Prathamesh1420 commited on
Commit
ddfcb23
·
verified ·
1 Parent(s): 3b3b8a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -17
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 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
@@ -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() # 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,9 +56,16 @@ def show_dashboard():
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")
@@ -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
- 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
 
 
 
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