Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import streamlit as st
|
|
2 |
import os
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
5 |
-
import pickle
|
6 |
from chatbot import Chatbot # Assuming you have a chatbot module
|
7 |
|
8 |
# Function to save uploaded file
|
@@ -19,64 +18,69 @@ def save_uploaded_file(uploaded_file):
|
|
19 |
|
20 |
# Function to show dashboard content
|
21 |
def show_dashboard():
|
22 |
-
st.
|
|
|
|
|
23 |
chatbot = Chatbot()
|
24 |
chatbot.load_data()
|
25 |
|
26 |
-
#
|
27 |
-
uploaded_file = st.file_uploader("
|
28 |
-
|
|
|
29 |
if save_uploaded_file(uploaded_file):
|
30 |
-
|
31 |
display_image = Image.open(uploaded_file)
|
32 |
-
st.image(display_image)
|
33 |
-
|
34 |
# Generate image caption
|
35 |
image_path = os.path.join("uploads", uploaded_file.name)
|
36 |
caption = chatbot.generate_image_caption(image_path)
|
37 |
-
st.write("Generated Caption
|
38 |
-
|
|
|
39 |
# Use caption to get product recommendations
|
40 |
_, recommended_products = chatbot.generate_response(caption)
|
41 |
|
42 |
-
|
43 |
col1, col2, col3, col4, col5 = st.columns(5)
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
with col3:
|
49 |
-
st.image(chatbot.images[recommended_products[2]['corpus_id']])
|
50 |
-
with col4:
|
51 |
-
st.image(chatbot.images[recommended_products[3]['corpus_id']])
|
52 |
-
with col5:
|
53 |
-
st.image(chatbot.images[recommended_products[4]['corpus_id']])
|
54 |
-
|
55 |
else:
|
56 |
-
st.
|
57 |
|
58 |
# Chatbot section
|
59 |
-
|
|
|
60 |
if user_question:
|
61 |
bot_response, recommended_products = chatbot.generate_response(user_question)
|
62 |
-
st.write("Chatbot
|
|
|
63 |
|
64 |
-
# Display recommended products
|
|
|
65 |
for result in recommended_products:
|
66 |
pid = result['corpus_id']
|
67 |
product_info = chatbot.product_data[pid]
|
68 |
-
st.write("Product Name
|
69 |
-
st.write("Category
|
70 |
-
st.write("Article Type
|
71 |
-
st.write("Usage
|
72 |
-
st.write("Season
|
73 |
-
st.write("Gender
|
74 |
-
st.image(chatbot.images[pid])
|
75 |
|
76 |
# Main Streamlit app
|
77 |
def main():
|
78 |
-
#
|
79 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
# Show dashboard content directly
|
82 |
show_dashboard()
|
|
|
2 |
import os
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
|
|
5 |
from chatbot import Chatbot # Assuming you have a chatbot module
|
6 |
|
7 |
# Function to save uploaded file
|
|
|
18 |
|
19 |
# Function to show dashboard content
|
20 |
def show_dashboard():
|
21 |
+
st.title("Fashion Recommender System")
|
22 |
+
st.write("Welcome to our Fashion Recommender System! Upload an image and get personalized product recommendations based on your image and queries.")
|
23 |
+
|
24 |
chatbot = Chatbot()
|
25 |
chatbot.load_data()
|
26 |
|
27 |
+
# Load and set up the ResNet model
|
28 |
+
uploaded_file = st.file_uploader("Upload an Image", type=['jpg', 'jpeg', 'png'])
|
29 |
+
|
30 |
+
if uploaded_file:
|
31 |
if save_uploaded_file(uploaded_file):
|
32 |
+
st.sidebar.header("Uploaded Image")
|
33 |
display_image = Image.open(uploaded_file)
|
34 |
+
st.sidebar.image(display_image, caption='Uploaded Image', use_column_width=True)
|
35 |
+
|
36 |
# Generate image caption
|
37 |
image_path = os.path.join("uploads", uploaded_file.name)
|
38 |
caption = chatbot.generate_image_caption(image_path)
|
39 |
+
st.write("### Generated Caption")
|
40 |
+
st.write(caption)
|
41 |
+
|
42 |
# Use caption to get product recommendations
|
43 |
_, recommended_products = chatbot.generate_response(caption)
|
44 |
|
45 |
+
st.write("### Recommended Products")
|
46 |
col1, col2, col3, col4, col5 = st.columns(5)
|
47 |
+
for i, idx in enumerate(recommended_products[:5]):
|
48 |
+
with col1 if i == 0 else col2 if i == 1 else col3 if i == 2 else col4 if i == 3 else col5:
|
49 |
+
product_image = chatbot.images[idx['corpus_id']]
|
50 |
+
st.image(product_image, caption=f"Product {i+1}", use_column_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
else:
|
52 |
+
st.error("Error in uploading the file.")
|
53 |
|
54 |
# Chatbot section
|
55 |
+
st.write("### Chat with our Fashion Assistant")
|
56 |
+
user_question = st.text_input("Ask a question about fashion:")
|
57 |
if user_question:
|
58 |
bot_response, recommended_products = chatbot.generate_response(user_question)
|
59 |
+
st.write("**Chatbot Response:**")
|
60 |
+
st.write(bot_response)
|
61 |
|
62 |
+
# Display recommended products based on the user question
|
63 |
+
st.write("**Recommended Products:**")
|
64 |
for result in recommended_products:
|
65 |
pid = result['corpus_id']
|
66 |
product_info = chatbot.product_data[pid]
|
67 |
+
st.write(f"**Product Name:** {product_info['productDisplayName']}")
|
68 |
+
st.write(f"**Category:** {product_info['masterCategory']}")
|
69 |
+
st.write(f"**Article Type:** {product_info['articleType']}")
|
70 |
+
st.write(f"**Usage:** {product_info['usage']}")
|
71 |
+
st.write(f"**Season:** {product_info['season']}")
|
72 |
+
st.write(f"**Gender:** {product_info['gender']}")
|
73 |
+
st.image(chatbot.images[pid], use_column_width=True)
|
74 |
|
75 |
# Main Streamlit app
|
76 |
def main():
|
77 |
+
# Set page configuration
|
78 |
+
st.set_page_config(
|
79 |
+
page_title="Fashion Recommender System",
|
80 |
+
page_icon=":dress:",
|
81 |
+
layout="wide",
|
82 |
+
initial_sidebar_state="expanded"
|
83 |
+
)
|
84 |
|
85 |
# Show dashboard content directly
|
86 |
show_dashboard()
|