Spaces:
Sleeping
Sleeping
File size: 5,304 Bytes
b7192a3 17b8f9b c1ae0da b7192a3 c1ae0da b7192a3 c1ae0da b7192a3 c1ae0da 0d41bf4 b7192a3 0d41bf4 b7192a3 17b8f9b c1ae0da 17b8f9b c1ae0da b7192a3 c1ae0da b7192a3 c1ae0da 0d41bf4 c1ae0da 17b8f9b c1ae0da 17b8f9b c1ae0da 17b8f9b c1ae0da 0d41bf4 c1ae0da 17b8f9b c1ae0da |
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
import streamlit as st
from PIL import Image
from phi.agent import Agent
from phi.model.google import Gemini
from phi.tools.firecrawl import FirecrawlTools
import google.generativeai as genai
import io
from dotenv import load_dotenv
import os
# Load environment variables
load_dotenv()
# Configure Gemini
API_KEY = os.getenv("GOOGLE_API_KEY")
if API_KEY:
genai.configure(api_key=API_KEY)
# Page Configuration with custom CSS
st.set_page_config(
page_title="AI Shopping Partner",
page_icon="ποΈ",
layout="wide"
)
# Custom CSS
st.markdown("""
<style>
.main {
padding: 2rem;
}
.stTitle {
color: #1E88E5;
font-family: 'Helvetica Neue', sans-serif;
}
.stHeader {
color: #333;
font-family: 'Helvetica Neue', sans-serif;
}
.upload-section {
background-color: #f8f9fa;
padding: 2rem;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.results-section {
background-color: white;
padding: 2rem;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
margin-top: 2rem;
}
.stTextInput input {
border-radius: 5px;
}
.stButton button {
border-radius: 5px;
background-color: #1E88E5;
color: white;
font-weight: bold;
}
.stTextArea textarea {
border-radius: 5px;
height: 100px;
}
</style>
""", unsafe_allow_html=True)
# App Header
col1, col2, col3 = st.columns([1,2,1])
with col2:
st.title("ποΈ AI Shopping Partner")
st.markdown("##### Powered by Agno and Google Gemini")
def get_gemini_response(api_key, prompt, image):
model = genai.GenerativeModel(model_name="gemini-2.0-flash-exp")
response = model.generate_content([prompt, image])
return response.text
def initialize_agent():
return Agent(
name="Shopping Partner",
model=Gemini(id="gemini-2.0-flash-exp"),
instructions=[
"You are a product recommender agent specializing in finding products that match user preferences.",
"Prioritize finding products that satisfy as many user requirements as possible, but ensure a minimum match of 50%.",
"Search for products only from authentic and trusted e-commerce websites.",
"Verify that each product recommendation is in stock and available for purchase.",
"Avoid suggesting counterfeit or unverified products.",
"Format recommendations in a clean, organized manner with clear product attributes.",
],
tools=[FirecrawlTools()],
markdown=True
)
# Initialize the Agent
multimodal_Agent = initialize_agent()
# Main content area
st.markdown('<div class="upload-section">', unsafe_allow_html=True)
# File Upload Section
uploaded_file = st.file_uploader(
"Upload a product image to analyze",
type=["jpg", "jpeg", "png"],
help="Maximum file size: 200MB"
)
if uploaded_file:
image = Image.open(uploaded_file)
# Display image and initial analysis
col1, col2 = st.columns([1, 2])
with col1:
st.image(image, caption="Uploaded Image", use_container_width=True)
with col2:
with st.spinner("Analyzing image..."):
initial_response = get_gemini_response(API_KEY, "What is in this photo?", image)
st.info(f"**Product Identified:** {initial_response}")
# Preference Collection
st.markdown("### Your Preferences")
col1, col2, col3 = st.columns(3)
with col1:
color_pref = st.text_input("π¨ Desired Color", placeholder="e.g., Navy Blue")
with col2:
purpose = st.text_input("π― Intended Purpose", placeholder="e.g., Casual wear")
with col3:
budget = st.text_input("π° Budget Range", placeholder="e.g., Under $100")
specific_requirements = st.text_area(
"β¨ Additional Requirements",
placeholder="Any specific features or requirements you're looking for?"
)
if st.button("π Find Similar Products", type="primary"):
if not specific_requirements:
st.warning("Please specify your requirements to get better recommendations.")
else:
st.markdown('<div class="results-section">', unsafe_allow_html=True)
with st.spinner("Searching for perfect matches..."):
analysis_prompt = f"""
I am looking for {initial_response}
with the following preferences:
Color: {color_pref}
Purpose: {purpose}
Budget: {budget}
Additional Requirements: {specific_requirements}
Please provide recommendations with direct product links.
"""
response = multimodal_Agent.run(analysis_prompt, image=image)
st.markdown("### π Recommended Products")
st.markdown(response.content)
st.markdown('</div>', unsafe_allow_html=True)
st.markdown('</div>', unsafe_allow_html=True)
# Footer
st.markdown("---")
st.markdown(
"""
<div style='text-align: center; color: #666;'>
<p>Made with β€οΈ by AI Shopping Partner</p>
</div>
""",
unsafe_allow_html=True
) |