Spaces:
Sleeping
Sleeping
| from dotenv import load_dotenv | |
| import streamlit as st | |
| import os | |
| import google.generativeai as genai | |
| import time | |
| load_dotenv() | |
| genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) | |
| st.set_page_config( | |
| page_title="Theaimart", | |
| page_icon="ico.jpeg", | |
| layout="wide", | |
| initial_sidebar_state="expanded" | |
| ) | |
| st.markdown(""" | |
| <style> | |
| /* Main background and text colors */ | |
| .stApp { | |
| background-color: #1a1a1a; | |
| color: #ffffff; | |
| } | |
| /* Buttons */ | |
| .stButton>button { | |
| background-color: #FF4B4B; | |
| color: white; | |
| border-radius: 8px; | |
| padding: 0.5rem 1rem; | |
| border: none; | |
| transition: all 0.3s ease; | |
| } | |
| .stButton>button:hover { | |
| background-color: #FF6B6B; | |
| transform: translateY(-2px); | |
| box-shadow: 0 4px 12px rgba(255, 75, 75, 0.2); | |
| } | |
| /* Headers */ | |
| h1, h2, h3 { | |
| color: #FF4B4B !important; | |
| font-weight: 600; | |
| } | |
| /* File uploader */ | |
| .uploadedFile { | |
| background-color: #2d2d2d !important; | |
| border-radius: 8px; | |
| padding: 1rem; | |
| border: 2px dashed #FF4B4B; | |
| } | |
| /* Select boxes */ | |
| .stSelectbox { | |
| background-color: #2d2d2d; | |
| border-radius: 8px; | |
| color: white; | |
| } | |
| /* Text inputs */ | |
| .stTextInput>div>div>input { | |
| background-color: #2d2d2d; | |
| color: white; | |
| border-radius: 8px; | |
| border: 1px solid #FF4B4B; | |
| } | |
| /* Cards */ | |
| .css-1r6slb0 { | |
| background-color: #2d2d2d; | |
| border-radius: 10px; | |
| padding: 1.5rem; | |
| box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | |
| } | |
| /* Multiselect */ | |
| .stMultiSelect { | |
| background-color: #2d2d2d; | |
| border-radius: 8px; | |
| } | |
| /* Success messages */ | |
| .success { | |
| padding: 1rem; | |
| border-radius: 8px; | |
| background-color: #1e4620; | |
| border-left: 4px solid #4CAF50; | |
| } | |
| /* Warning messages */ | |
| .warning { | |
| padding: 1rem; | |
| border-radius: 8px; | |
| background-color: #332b1b; | |
| border-left: 4px solid #FFC107; | |
| } | |
| /* Redirect message */ | |
| .redirect-message { | |
| position: fixed; | |
| bottom: 20px; | |
| right: 20px; | |
| background-color: #2d2d2d; | |
| padding: 1rem; | |
| border-radius: 8px; | |
| box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); | |
| z-index: 1000; | |
| } | |
| .social-links a { | |
| display: block; | |
| margin: 0.5rem 0; | |
| padding: 0.8rem 1.2rem; | |
| color: white; | |
| text-decoration: none; | |
| border-radius: 8px; | |
| text-align: center; | |
| font-weight: bold; | |
| background-color: #FF4B4B; /* Button background */ | |
| transition: all 0.3s ease; | |
| } | |
| .social-links a:hover { | |
| background-color: #FF6B6B; /* Hover effect */ | |
| transform: translateY(-3px); | |
| box-shadow: 0 4px 12px rgba(255, 75, 75, 0.3); | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| def input_image_setup(uploaded_file): | |
| if uploaded_file is not None: | |
| bytes_data = uploaded_file.getvalue() | |
| image_parts = [ | |
| { | |
| "mime_type": uploaded_file.type, | |
| "data": bytes_data | |
| } | |
| ] | |
| return image_parts | |
| else: | |
| raise FileNotFoundError("No file uploaded") | |
| def get_fashion_analysis(image, prompt): | |
| try: | |
| model = genai.GenerativeModel('gemini-1.5-flash') | |
| if image: | |
| response = model.generate_content([image[0], prompt]) | |
| else: | |
| response = model.generate_content([prompt]) | |
| return response.text | |
| except Exception as e: | |
| st.error(f"Analysis failed: {str(e)}") | |
| return None | |
| with st.sidebar: | |
| st.image("ico.jpeg", width=100) | |
| st.title("FashChat Settings") | |
| accent_color = st.color_picker("Accent Color", "#FF4B4B") | |
| st.markdown("---") | |
| st.markdown("### About FashChat") | |
| st.markdown( | |
| "Your AI-powered fashion analysis companion. Get instant insights on outfits, makeup, and celebrity styles.") | |
| st.markdown("---") | |
| st.markdown("v1.0.0 | Made with β€οΈ by theaimart") | |
| st.title("FashChat: Your Fashion AI Companion") | |
| analysis_type = st.tabs(["Outfit Analyzer"]) | |
| with analysis_type[0]: | |
| st.header("π Outfit Analysis") | |
| col1, col2 = st.columns([2, 1]) | |
| with col1: | |
| uploaded_file = st.file_uploader( | |
| "Drop your outfit image here", | |
| type=["jpg", "jpeg", "png"], | |
| help="Upload a clear, full-body image for best results" | |
| ) | |
| if uploaded_file: | |
| st.image(uploaded_file, use_column_width=True) | |
| with col2: | |
| prompt = st.text_area("Analysis Focus (optional)", | |
| placeholder="E.g., 'Analyze the color coordination' or 'Suggest improvements'") | |
| analysis_options = st.multiselect( | |
| "Analysis Aspects", | |
| [ | |
| "π¨ Color Harmony", | |
| "π Fit Analysis", | |
| "π― Style Recommendations", | |
| "ποΈ Shopping Suggestions", | |
| "π Mix & Match Ideas" | |
| ], | |
| default=["π¨ Color Harmony"] | |
| ) | |
| analyze_button = st.button("β¨ Analyze Outfit", type="primary") | |
| if analyze_button and uploaded_file: | |
| with st.spinner("Analyzing your outfit..."): | |
| try: | |
| image_data = input_image_setup(uploaded_file) | |
| input_prompt = f""" | |
| As a fashion expert, provide a detailed analysis of this outfit: | |
| Focus areas: | |
| {', '.join(analysis_options)} | |
| Additional context: | |
| {prompt if prompt else 'Provide general style analysis'} | |
| Please structure the analysis with clear headings and bullet points. | |
| """ | |
| response = get_fashion_analysis(image=image_data, prompt=input_prompt) | |
| st.markdown("### π Analysis Results") | |
| st.markdown(response) | |
| st.markdown(""" | |
| <div class='success'> | |
| Analysis completed successfully! Save or share your results. | |
| </div> | |
| """, unsafe_allow_html=True) | |
| st.markdown(""" | |
| <div class='redirect-message'> | |
| FashChat by theaimart | |
| </div> | |
| """, unsafe_allow_html=True) | |
| time.sleep(3) | |
| except Exception as e: | |
| st.error(f"Analysis failed: {str(e)}") | |
| # Footer | |
| st.markdown("---") | |
| col1, col2, col3 = st.columns(3) | |
| with col1: | |
| st.markdown("### π± Connect") | |
| st.markdown("[Instagram](https://instagram.com)") | |
| st.markdown("[Youtube](https://www.youtube.com/@theaimartofficial)") | |