Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,13 @@
|
|
1 |
-
import streamlit as st
|
2 |
import os
|
3 |
import pickle
|
4 |
import numpy as np
|
5 |
-
import
|
|
|
6 |
from tensorflow.keras.preprocessing import image
|
7 |
from tensorflow.keras.layers import GlobalMaxPooling2D
|
8 |
from tensorflow.keras.applications.resnet50 import ResNet50, preprocess_input
|
9 |
from sklearn.neighbors import NearestNeighbors
|
10 |
from numpy.linalg import norm
|
11 |
-
from PIL import Image
|
12 |
from chatbot import Chatbot # Assuming you have a chatbot module
|
13 |
|
14 |
# Define function for feature extraction
|
@@ -47,8 +46,8 @@ def save_uploaded_file(uploaded_file):
|
|
47 |
# Function to show dashboard content
|
48 |
def show_dashboard():
|
49 |
st.header("Fashion Recommender System")
|
50 |
-
chatbot = Chatbot()
|
51 |
-
|
52 |
# Load ResNet model for image feature extraction
|
53 |
model = ResNet50(weights='imagenet', include_top=False, input_shape=(224, 224, 3))
|
54 |
model.trainable = False
|
@@ -57,9 +56,16 @@ def show_dashboard():
|
|
57 |
GlobalMaxPooling2D()
|
58 |
])
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
# File upload section
|
65 |
uploaded_file = st.file_uploader("Choose an image")
|
@@ -92,16 +98,14 @@ def show_dashboard():
|
|
92 |
columns = [col1, col2, col3, col4, col5]
|
93 |
|
94 |
for col, idx in zip(columns, indices[0]):
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
with col:
|
100 |
-
st.image(
|
101 |
-
|
102 |
-
st.error(f"
|
103 |
-
except Exception as e:
|
104 |
-
st.error(f"Error opening file {file_path}: {e}")
|
105 |
else:
|
106 |
st.error("Some error occurred in file upload")
|
107 |
|
|
|
|
|
1 |
import os
|
2 |
import pickle
|
3 |
import numpy as np
|
4 |
+
import streamlit as st
|
5 |
+
from PIL import Image
|
6 |
from tensorflow.keras.preprocessing import image
|
7 |
from tensorflow.keras.layers import GlobalMaxPooling2D
|
8 |
from tensorflow.keras.applications.resnet50 import ResNet50, preprocess_input
|
9 |
from sklearn.neighbors import NearestNeighbors
|
10 |
from numpy.linalg import norm
|
|
|
11 |
from chatbot import Chatbot # Assuming you have a chatbot module
|
12 |
|
13 |
# Define function for feature extraction
|
|
|
46 |
# Function to show dashboard content
|
47 |
def show_dashboard():
|
48 |
st.header("Fashion Recommender System")
|
49 |
+
chatbot = Chatbot()
|
50 |
+
|
51 |
# Load ResNet model for image feature extraction
|
52 |
model = ResNet50(weights='imagenet', include_top=False, input_shape=(224, 224, 3))
|
53 |
model.trainable = False
|
|
|
56 |
GlobalMaxPooling2D()
|
57 |
])
|
58 |
|
59 |
+
try:
|
60 |
+
feature_list = np.array(pickle.load(open('embeddings.pkl', 'rb')))
|
61 |
+
filenames = pickle.load(open('filenames.pkl', 'rb'))
|
62 |
+
except Exception as e:
|
63 |
+
st.error(f"Error loading pickle files: {e}")
|
64 |
+
return
|
65 |
+
|
66 |
+
# Print the filenames to verify
|
67 |
+
st.write("List of filenames loaded:")
|
68 |
+
st.write(filenames)
|
69 |
|
70 |
# File upload section
|
71 |
uploaded_file = st.file_uploader("Choose an image")
|
|
|
98 |
columns = [col1, col2, col3, col4, col5]
|
99 |
|
100 |
for col, idx in zip(columns, indices[0]):
|
101 |
+
# Directly access images from the dataset instead of file paths
|
102 |
+
image_data = chatbot.images[idx]
|
103 |
+
if image_data is not None:
|
104 |
+
try:
|
105 |
with col:
|
106 |
+
st.image(image_data)
|
107 |
+
except Exception as e:
|
108 |
+
st.error(f"Error opening image index {idx}: {e}")
|
|
|
|
|
109 |
else:
|
110 |
st.error("Some error occurred in file upload")
|
111 |
|