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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -29
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
- try:
70
- feature_list = np.array(pickle.load(open('embeddings.pkl', 'rb')))
71
- filenames = pickle.load(open('filenames.pkl', 'rb'))
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
- full_path = os.path.join(extract_to, os.path.basename(file_path))
113
- st.write(f"Trying to open file: {full_path}") # Add debug info
114
  try:
115
- if os.path.exists(full_path):
116
  with col:
117
- st.image(full_path)
118
  else:
119
- st.error(f"File does not exist: {full_path}")
120
  except Exception as e:
121
- st.error(f"Error opening file {full_path}: {e}")
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