Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,15 @@
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
-
from PIL import Image
|
4 |
-
import numpy as np
|
5 |
import pickle
|
|
|
6 |
import tensorflow
|
7 |
from tensorflow.keras.preprocessing import image
|
8 |
from tensorflow.keras.layers import GlobalMaxPooling2D
|
9 |
from tensorflow.keras.applications.resnet50 import ResNet50, preprocess_input
|
10 |
from sklearn.neighbors import NearestNeighbors
|
11 |
from numpy.linalg import norm
|
|
|
12 |
from chatbot import Chatbot # Assuming you have a chatbot module
|
13 |
-
import zipfile
|
14 |
-
|
15 |
-
# Define the path to the zip file and the directory to extract to
|
16 |
-
zip_file_path = 'images.zip'
|
17 |
-
extract_to = 'images'
|
18 |
-
|
19 |
-
# Check if the images directory already exists to avoid re-extracting
|
20 |
-
if not os.path.exists(extract_to):
|
21 |
-
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
|
22 |
-
zip_ref.extractall(extract_to)
|
23 |
|
24 |
# Define function for feature extraction
|
25 |
def feature_extraction(img_path, model):
|
@@ -57,7 +47,8 @@ def save_uploaded_file(uploaded_file):
|
|
57 |
# Function to show dashboard content
|
58 |
def show_dashboard():
|
59 |
st.header("Fashion Recommender System")
|
60 |
-
chatbot = Chatbot()
|
|
|
61 |
# Load ResNet model for image feature extraction
|
62 |
model = ResNet50(weights='imagenet', include_top=False, input_shape=(224, 224, 3))
|
63 |
model.trainable = False
|
@@ -66,16 +57,9 @@ def show_dashboard():
|
|
66 |
GlobalMaxPooling2D()
|
67 |
])
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
except Exception as e:
|
73 |
-
st.error(f"Error loading pickle files: {e}")
|
74 |
-
return
|
75 |
-
|
76 |
-
# Print the filenames to verify
|
77 |
-
st.write("List of filenames loaded:")
|
78 |
-
st.write(filenames)
|
79 |
|
80 |
# File upload section
|
81 |
uploaded_file = st.file_uploader("Choose an image")
|
@@ -109,16 +93,15 @@ def show_dashboard():
|
|
109 |
|
110 |
for col, idx in zip(columns, indices[0]):
|
111 |
file_path = filenames[idx]
|
112 |
-
|
113 |
-
st.write(f"Trying to open file: {full_path}") # Add debug info
|
114 |
try:
|
115 |
-
if os.path.exists(
|
116 |
with col:
|
117 |
-
st.image(
|
118 |
else:
|
119 |
-
st.error(f"File does not exist: {
|
120 |
except Exception as e:
|
121 |
-
st.error(f"Error opening file {
|
122 |
else:
|
123 |
st.error("Some error occurred in file upload")
|
124 |
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
|
|
|
|
3 |
import pickle
|
4 |
+
import numpy as np
|
5 |
import tensorflow
|
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
|
15 |
def feature_extraction(img_path, model):
|
|
|
47 |
# Function to show dashboard content
|
48 |
def show_dashboard():
|
49 |
st.header("Fashion Recommender System")
|
50 |
+
chatbot = Chatbot() # Load the chatbot, which will also load the dataset
|
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 |
GlobalMaxPooling2D()
|
58 |
])
|
59 |
|
60 |
+
# Feature list and filenames should be loaded from the same source as the chatbot
|
61 |
+
feature_list = np.array(chatbot.image_embeddings) # Assuming you have embeddings loaded in the chatbot
|
62 |
+
filenames = chatbot.product_frame['productImageURL'].tolist() # Adjust according to your dataset
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
# File upload section
|
65 |
uploaded_file = st.file_uploader("Choose an image")
|
|
|
93 |
|
94 |
for col, idx in zip(columns, indices[0]):
|
95 |
file_path = filenames[idx]
|
96 |
+
st.write(f"Trying to open file: {file_path}") # Add debug info
|
|
|
97 |
try:
|
98 |
+
if os.path.exists(file_path):
|
99 |
with col:
|
100 |
+
st.image(file_path)
|
101 |
else:
|
102 |
+
st.error(f"File does not exist: {file_path}")
|
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 |
|