-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
84 lines (70 loc) · 2.92 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import streamlit as st
from google.generativeai import upload_file
import os
from dotenv import load_dotenv
from pathlib import Path
import tempfile
import google.generativeai as genai
import time
from agent import MultimodalAgent
load_dotenv()
API_KEY = os.getenv("GOOGLE_API_KEY")
if API_KEY:
genai.configure(api_key=API_KEY)
st.set_page_config(
page_title="Music recommendation for Social Media Post",
layout="wide"
)
st.title("Music recommendation for Social Media Post")
st.header("Powered by Google Gemini Flash")
# @st.cache_resource
# def initiate_agent():
# return MultimodalAgent()
multimodal_agent = MultimodalAgent()
image_file = st.file_uploader(label="Upload photo", type=["jpg", "png", "jpeg"],
help="Upload a photo for AI analysis")
if image_file:
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_image:
temp_image.write(image_file.read())
image_path = temp_image.name
st.image(image_path)
user_query = st.text_area(
"Provide specific info of the image!",
placeholder="Provide inforation about the image like where(location) it is clicked, how are u feeling etc.",
help="Provide specific info for insights."
)
language = st.multiselect("Select languages for music",
["English", "Hindi", "Tamil", "Telugu"])
if st.button("Analyze image", key="analyze_image_button"):
if not user_query:
st.warning("Please enter information to analyze the image")
elif not language:
st.warning("Please select languages for music")
else:
try:
with st.spinner("Processing image and gathering insights"):
# Process the image
processed_image = upload_file(image_path)
time.sleep(1)
# Prompt for analysis
analysis_prompt = (
f""" Analyze the uploaded image for content and context.
Analyze it along with image information.
{user_query}
music language: {language}
Provide top 5 music recommendation with lyrics using the image insights and web search.
"""
)
# AI agent processing
response = multimodal_agent.run(analysis_prompt, images=[processed_image])
print(response)
# Display the result
st.subheader("Analysis Report")
st.markdown(response.content)
except Exception as e:
st.error(f"An error occurred during analysis {e}")
finally:
# Clean the temporary image file
Path(image_path).unlink(missing_ok=True)
else:
st.info("Upload a image file to begin the analysis")