antoinette-f commited on
Commit
0784a45
·
verified ·
1 Parent(s): 4822912

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -14,6 +14,7 @@ except FileNotFoundError:
14
  print("Error: 'clothing.csv' not found. Please ensure the file is in the same directory.")
15
  clothing_df = pd.DataFrame(columns=['weather', 'formality', 'category', 'image_path'])
16
  # Simple filtering function to get clothing suggestions based on a query
 
17
  def get_suggestions(query):
18
  """
19
  Filters the clothing dataframe based on weather and formality keywords
@@ -44,14 +45,20 @@ def get_suggestions(query):
44
 
45
  # Pick one item per category
46
  outfit = []
47
- for category in results.groupby('category'):
48
- # Take one random item per category to avoid displaying duplicates
49
- outfit.append(category[1].sample(1))
50
-
 
 
 
 
 
 
 
51
  # Combine into single DataFrame and return
52
  final_selection = pd.concat(outfit)
53
  return final_selection
54
-
55
  # Chatbot + image output function
56
  # Chatbot + image output function
57
  def respond(message, chat_history):
 
14
  print("Error: 'clothing.csv' not found. Please ensure the file is in the same directory.")
15
  clothing_df = pd.DataFrame(columns=['weather', 'formality', 'category', 'image_path'])
16
  # Simple filtering function to get clothing suggestions based on a query
17
+
18
  def get_suggestions(query):
19
  """
20
  Filters the clothing dataframe based on weather and formality keywords
 
45
 
46
  # Pick one item per category
47
  outfit = []
48
+ # Ensure there are results to group by before proceeding
49
+ if not results.empty:
50
+ for category in results.groupby('category'):
51
+ # Take one random item per category to avoid displaying duplicates
52
+ outfit.append(category[1].sample(1))
53
+
54
+ # Check if the outfit list is empty before concatenating
55
+ if not outfit:
56
+ # Return an empty DataFrame with the correct columns if no results
57
+ return pd.DataFrame(columns=clothing_df.columns)
58
+
59
  # Combine into single DataFrame and return
60
  final_selection = pd.concat(outfit)
61
  return final_selection
 
62
  # Chatbot + image output function
63
  # Chatbot + image output function
64
  def respond(message, chat_history):