SanaAdeel commited on
Commit
5143f2f
·
verified ·
1 Parent(s): c695ced

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -43
app.py CHANGED
@@ -10,27 +10,40 @@ def load_data(file_url):
10
  gdown.download(file_url, file_path, quiet=False)
11
  return pd.read_excel(file_path, engine='openpyxl')
12
 
13
- # Function to generate the weekly menu
14
- def generate_menu(data, season, sub_category_pref, outings, dietary_restrictions):
15
  season_data = data[(data['Season'] == season) | (data['Season'] == 'All Seasons')]
16
 
17
  meals_needed = 14 - outings # Main Courses (14) minus outings
18
 
19
  menu = []
 
 
20
  for sub_category, freq in sub_category_pref.items():
21
  sub_category_dishes = season_data[season_data['Sub-Category'] == sub_category]
22
- menu.extend(sub_category_dishes.sample(min(freq, len(sub_category_dishes))).to_dict('records'))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  menu = menu[:meals_needed]
25
 
26
- # Filter out dishes based on dietary restrictions
27
- if dietary_restrictions == 'Diabetic':
28
- menu = [dish for dish in menu if 'sugar' not in dish['Ingredients'].lower()]
29
- elif dietary_restrictions == 'Gluten-Free':
30
- menu = [dish for dish in menu if 'gluten' not in dish['Ingredients'].lower()]
31
- elif dietary_restrictions == 'Low-Sodium':
32
- menu = [dish for dish in menu if 'sodium' not in dish['Ingredients'].lower()]
33
-
34
  outing_dishes = data[data['Home Made / Outing'] == 'Outing'].sample(outings).to_dict('records')
35
  menu.extend(outing_dishes)
36
 
@@ -47,7 +60,7 @@ def generate_menu(data, season, sub_category_pref, outings, dietary_restrictions
47
  lunch_menu = lunch_menu[["Name"]]
48
  dinner_menu = dinner_menu[["Name"]]
49
 
50
- return lunch_menu, dinner_menu, total_cost
51
 
52
  # Function to calculate BMI and recommend diet
53
  def bmi_insights(weight, height_cm):
@@ -64,21 +77,8 @@ def bmi_insights(weight, height_cm):
64
  return f"Your BMI is {bmi:.2f}. You are obese. A calorie-restricted diet with lean proteins is recommended."
65
 
66
  # Function for Smart Inventory Management (Pantry Sync)
67
- def pantry_sync(available_ingredients, data):
68
- # Suggest meals based on ingredients available in the pantry
69
- suggested_dishes = []
70
- for dish in data.to_dict('records'):
71
- ingredients = dish.get('Ingredients', '').split(',')
72
- if all(ingredient in available_ingredients for ingredient in ingredients):
73
- suggested_dishes.append(dish)
74
- return pd.DataFrame(suggested_dishes)
75
-
76
- # Function for Shopping List Generator
77
- def generate_shopping_list(menu):
78
- ingredients = []
79
- for dish in menu:
80
- ingredients.extend(dish['Ingredients'].split(','))
81
- return sorted(set(ingredients))
82
 
83
  # Main workflow
84
  def main():
@@ -125,8 +125,15 @@ def main():
125
  st.warning("The total number of main courses exceeds 14! Please adjust your preferences.")
126
  return
127
 
 
 
 
 
 
 
 
128
  if st.button("Generate Menu"):
129
- lunch_menu, dinner_menu, total_cost = generate_menu(data, season, sub_category_pref, outings, dietary_restrictions)
130
 
131
  st.header("Weekly Menu")
132
  st.subheader("Lunch Menu")
@@ -137,6 +144,11 @@ def main():
137
 
138
  st.subheader(f"Total Expenditure for the Week: PKR {total_cost}")
139
 
 
 
 
 
 
140
  # Save menu to Excel
141
  with pd.ExcelWriter("weekly_menu_split.xlsx") as writer:
142
  lunch_menu.to_excel(writer, sheet_name="Lunch", index=False)
@@ -144,20 +156,5 @@ def main():
144
 
145
  st.success("Weekly menu saved as 'weekly_menu_split.xlsx'")
146
 
147
- # Pantry sync section
148
- st.header("Smart Pantry Sync")
149
- available_ingredients = st.text_area("Enter available ingredients in your pantry (comma separated)")
150
- if available_ingredients:
151
- available_ingredients = [item.strip() for item in available_ingredients.split(',')]
152
- pantry_suggested_dishes = pantry_sync(available_ingredients, data)
153
- st.subheader("Suggested Dishes Based on Pantry Ingredients")
154
- st.write(pantry_suggested_dishes)
155
-
156
- # Shopping list section
157
- st.header("Generate Shopping List")
158
- if st.button("Generate Shopping List"):
159
- shopping_list = generate_shopping_list(lunch_menu.to_dict('records') + dinner_menu.to_dict('records'))
160
- st.write("Shopping List:", shopping_list)
161
-
162
  if __name__ == "__main__":
163
  main()
 
10
  gdown.download(file_url, file_path, quiet=False)
11
  return pd.read_excel(file_path, engine='openpyxl')
12
 
13
+ # Function to generate the weekly menu based on BMI, dietary restriction, and pantry sync
14
+ def generate_menu(data, season, sub_category_pref, outings, dietary_restrictions, pantry_ingredients):
15
  season_data = data[(data['Season'] == season) | (data['Season'] == 'All Seasons')]
16
 
17
  meals_needed = 14 - outings # Main Courses (14) minus outings
18
 
19
  menu = []
20
+ shopping_list = set() # Track missing ingredients
21
+
22
  for sub_category, freq in sub_category_pref.items():
23
  sub_category_dishes = season_data[season_data['Sub-Category'] == sub_category]
24
+
25
+ # Filter dishes based on dietary restrictions
26
+ if dietary_restrictions == 'Diabetic':
27
+ sub_category_dishes = sub_category_dishes[~sub_category_dishes['Ingredients'].str.contains('sugar', case=False, na=False)]
28
+ elif dietary_restrictions == 'Gluten-Free':
29
+ sub_category_dishes = sub_category_dishes[~sub_category_dishes['Ingredients'].str.contains('gluten', case=False, na=False)]
30
+ elif dietary_restrictions == 'Low-Sodium':
31
+ sub_category_dishes = sub_category_dishes[~sub_category_dishes['Ingredients'].str.contains('sodium', case=False, na=False)]
32
+
33
+ # Sample the dishes based on the user preference
34
+ selected_dishes = sub_category_dishes.sample(min(freq, len(sub_category_dishes)))
35
+
36
+ # Check the ingredients for the pantry and add missing items to the shopping list
37
+ for dish in selected_dishes.to_dict('records'):
38
+ ingredients = dish.get('Ingredients', '').split(',')
39
+ for ingredient in ingredients:
40
+ if ingredient.strip().lower() not in pantry_ingredients:
41
+ shopping_list.add(ingredient.strip().lower())
42
+
43
+ menu.append(dish)
44
 
45
  menu = menu[:meals_needed]
46
 
 
 
 
 
 
 
 
 
47
  outing_dishes = data[data['Home Made / Outing'] == 'Outing'].sample(outings).to_dict('records')
48
  menu.extend(outing_dishes)
49
 
 
60
  lunch_menu = lunch_menu[["Name"]]
61
  dinner_menu = dinner_menu[["Name"]]
62
 
63
+ return lunch_menu, dinner_menu, total_cost, shopping_list
64
 
65
  # Function to calculate BMI and recommend diet
66
  def bmi_insights(weight, height_cm):
 
77
  return f"Your BMI is {bmi:.2f}. You are obese. A calorie-restricted diet with lean proteins is recommended."
78
 
79
  # Function for Smart Inventory Management (Pantry Sync)
80
+ def pantry_sync(available_ingredients):
81
+ return set(available_ingredients)
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  # Main workflow
84
  def main():
 
125
  st.warning("The total number of main courses exceeds 14! Please adjust your preferences.")
126
  return
127
 
128
+ # Pantry Sync
129
+ pantry_ingredients_input = st.text_area("Enter available ingredients in your pantry (comma separated)")
130
+ if pantry_ingredients_input:
131
+ pantry_ingredients = pantry_sync(pantry_ingredients_input.split(','))
132
+ else:
133
+ pantry_ingredients = set()
134
+
135
  if st.button("Generate Menu"):
136
+ lunch_menu, dinner_menu, total_cost, shopping_list = generate_menu(data, season, sub_category_pref, outings, dietary_restrictions, pantry_ingredients)
137
 
138
  st.header("Weekly Menu")
139
  st.subheader("Lunch Menu")
 
144
 
145
  st.subheader(f"Total Expenditure for the Week: PKR {total_cost}")
146
 
147
+ # Shopping list for missing ingredients
148
+ if shopping_list:
149
+ st.subheader("Shopping List for Missing Ingredients")
150
+ st.write(sorted(shopping_list))
151
+
152
  # Save menu to Excel
153
  with pd.ExcelWriter("weekly_menu_split.xlsx") as writer:
154
  lunch_menu.to_excel(writer, sheet_name="Lunch", index=False)
 
156
 
157
  st.success("Weekly menu saved as 'weekly_menu_split.xlsx'")
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  if __name__ == "__main__":
160
  main()