Prathamesh1420 commited on
Commit
2122a17
·
verified ·
1 Parent(s): bd7ba8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -31,10 +31,17 @@ def recommend(features, feature_list):
31
  # Function to save uploaded file
32
  def save_uploaded_file(uploaded_file):
33
  try:
34
- with open(os.path.join('uploads', uploaded_file.name), 'wb') as f:
 
 
 
 
 
35
  f.write(uploaded_file.getbuffer())
 
36
  return True
37
- except:
 
38
  return False
39
 
40
  # Function to show dashboard content
@@ -49,8 +56,12 @@ def show_dashboard():
49
  GlobalMaxPooling2D()
50
  ])
51
 
52
- feature_list = np.array(pickle.load(open('embeddings.pkl', 'rb')))
53
- filenames = pickle.load(open('filenames.pkl', 'rb'))
 
 
 
 
54
 
55
  # File upload section
56
  uploaded_file = st.file_uploader("Choose an image")
@@ -78,9 +89,8 @@ def show_dashboard():
78
  st.image(filenames[indices[0][3]])
79
  with col5:
80
  st.image(filenames[indices[0][4]])
81
-
82
  else:
83
- st.header("Some error occurred in file upload")
84
 
85
  # Chatbot section
86
  user_question = st.text_input("Ask a question:")
 
31
  # Function to save uploaded file
32
  def save_uploaded_file(uploaded_file):
33
  try:
34
+ # Ensure the uploads directory exists
35
+ if not os.path.exists('uploads'):
36
+ os.makedirs('uploads')
37
+
38
+ file_path = os.path.join('uploads', uploaded_file.name)
39
+ with open(file_path, 'wb') as f:
40
  f.write(uploaded_file.getbuffer())
41
+ st.success(f"File saved to {file_path}")
42
  return True
43
+ except Exception as e:
44
+ st.error(f"Error saving file: {e}")
45
  return False
46
 
47
  # Function to show dashboard content
 
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
  # File upload section
67
  uploaded_file = st.file_uploader("Choose an image")
 
89
  st.image(filenames[indices[0][3]])
90
  with col5:
91
  st.image(filenames[indices[0][4]])
 
92
  else:
93
+ st.error("Some error occurred in file upload")
94
 
95
  # Chatbot section
96
  user_question = st.text_input("Ask a question:")