import streamlit as st import os from PIL import Image import numpy as np from chatbot import Chatbot # Assuming you have a chatbot module # Function to save uploaded file def save_uploaded_file(uploaded_file): try: if not os.path.exists('uploads'): os.makedirs('uploads') with open(os.path.join('uploads', uploaded_file.name), 'wb') as f: f.write(uploaded_file.getbuffer()) return True except Exception as e: st.error(f"Error: {e}") return False # Function to show dashboard content def show_dashboard(): st.title("Fashion Recommender System") st.write("Welcome to our Fashion Recommender System! Upload an image and get personalized product recommendations based on your image and queries.") chatbot = Chatbot() chatbot.load_data() # Load and set up the ResNet model uploaded_file = st.file_uploader("Upload an Image", type=['jpg', 'jpeg', 'png']) if uploaded_file: if save_uploaded_file(uploaded_file): st.sidebar.header("Uploaded Image") display_image = Image.open(uploaded_file) st.sidebar.image(display_image, caption='Uploaded Image', use_column_width=True) # Generate image caption image_path = os.path.join("uploads", uploaded_file.name) caption = chatbot.generate_image_caption(image_path) st.write("### Generated Caption") st.write(caption) # Use caption to get product recommendations _, recommended_products = chatbot.generate_response(caption) st.write("### Recommended Products") col1, col2, col3, col4, col5 = st.columns(5) for i, idx in enumerate(recommended_products[:5]): with col1 if i == 0 else col2 if i == 1 else col3 if i == 2 else col4 if i == 3 else col5: product_image = chatbot.images[idx['corpus_id']] st.image(product_image, caption=f"Product {i+1}", width=150) else: st.error("Error in uploading the file.") # Chatbot section st.write("### Chat with our Fashion Assistant") user_question = st.text_input("Ask a question about fashion:") if user_question: bot_response, recommended_products = chatbot.generate_response(user_question) st.write("**Chatbot Response:**") st.write(bot_response) # Display recommended products based on the user question st.write("**Recommended Products:**") for result in recommended_products: pid = result['corpus_id'] product_info = chatbot.product_data[pid] st.markdown("""
Product Name: {product_name}
Category: {category}
Article Type: {article_type}
Usage: {usage}
Season: {season}
Gender: {gender}