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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -11
app.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  import pandas as pd
3
  import gdown
4
  from PIL import Image
 
5
 
6
  # Function to load data from Google Drive
7
  def load_data(file_url):
@@ -10,7 +11,7 @@ def load_data(file_url):
10
  return pd.read_excel(file_path, engine='openpyxl')
11
 
12
  # Function to generate the weekly menu
13
- def generate_menu(data, season, sub_category_pref, outings):
14
  season_data = data[(data['Season'] == season) | (data['Season'] == 'All Seasons')]
15
 
16
  meals_needed = 14 - outings # Main Courses (14) minus outings
@@ -22,6 +23,14 @@ def generate_menu(data, season, sub_category_pref, outings):
22
 
23
  menu = menu[:meals_needed]
24
 
 
 
 
 
 
 
 
 
25
  outing_dishes = data[data['Home Made / Outing'] == 'Outing'].sample(outings).to_dict('records')
26
  menu.extend(outing_dishes)
27
 
@@ -42,23 +51,39 @@ def generate_menu(data, season, sub_category_pref, outings):
42
 
43
  # Function to calculate BMI and recommend diet
44
  def bmi_insights(weight, height_cm):
45
- # Convert height from cm to meters
46
  height_m = height_cm / 100
47
  bmi = weight / (height_m ** 2)
48
 
49
  if bmi < 18.5:
50
- return f"Your BMI is {bmi:.2f}. You are underweight. A diet rich in proteins and healthy fats would be beneficial. Consider incorporating more calories and nutritious snacks."
51
  elif 18.5 <= bmi < 24.9:
52
- return f"Your BMI is {bmi:.2f}. You are in the normal weight range. Maintain a balanced diet, including fruits, vegetables, whole grains, and lean proteins."
53
  elif 25 <= bmi < 29.9:
54
- return f"Your BMI is {bmi:.2f}. You are overweight. A diet with fewer carbs and more lean proteins can help manage your weight. Consider reducing sugar intake."
55
  else:
56
- return f"Your BMI is {bmi:.2f}. You are obese. A calorie-restricted diet with a focus on whole foods, vegetables, and lean proteins is recommended. Consult a health professional for personalized guidance."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
  # Main workflow
59
  def main():
60
  st.title("Roz Roz Ka Masla..... Aaj Kya Pakayen!!! ")
61
- st.title("Now generate weekly Menu with BMI Insights")
62
 
63
  # Add food image at the top right of the app
64
  image = Image.open("food_image.jpg") # Ensure you have an image in the same folder
@@ -82,6 +107,9 @@ def main():
82
 
83
  outings = st.number_input("Enter the number of outings this week", min_value=0, max_value=14, value=0)
84
 
 
 
 
85
  st.header("How many dishes from each sub-category would you like?")
86
  sub_category_pref = {
87
  'Sabzi': st.number_input("Number of Sabzi dishes", min_value=0, value=0),
@@ -98,7 +126,7 @@ def main():
98
  return
99
 
100
  if st.button("Generate Menu"):
101
- lunch_menu, dinner_menu, total_cost = generate_menu(data, season, sub_category_pref, outings)
102
 
103
  st.header("Weekly Menu")
104
  st.subheader("Lunch Menu")
@@ -109,14 +137,27 @@ def main():
109
 
110
  st.subheader(f"Total Expenditure for the Week: PKR {total_cost}")
111
 
112
- # Save menu to Excel
113
  with pd.ExcelWriter("weekly_menu_split.xlsx") as writer:
114
  lunch_menu.to_excel(writer, sheet_name="Lunch", index=False)
115
  dinner_menu.to_excel(writer, sheet_name="Dinner", index=False)
116
 
117
  st.success("Weekly menu saved as 'weekly_menu_split.xlsx'")
118
 
119
-
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
  if __name__ == "__main__":
122
- main()
 
2
  import pandas as pd
3
  import gdown
4
  from PIL import Image
5
+ import random
6
 
7
  # Function to load data from Google Drive
8
  def load_data(file_url):
 
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
 
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
 
 
51
 
52
  # Function to calculate BMI and recommend diet
53
  def bmi_insights(weight, height_cm):
 
54
  height_m = height_cm / 100
55
  bmi = weight / (height_m ** 2)
56
 
57
  if bmi < 18.5:
58
+ return f"Your BMI is {bmi:.2f}. You are underweight. A diet rich in proteins and healthy fats would be beneficial."
59
  elif 18.5 <= bmi < 24.9:
60
+ return f"Your BMI is {bmi:.2f}. You are in the normal weight range. Maintain a balanced diet."
61
  elif 25 <= bmi < 29.9:
62
+ return f"Your BMI is {bmi:.2f}. You are overweight. Consider reducing sugar intake."
63
  else:
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():
85
  st.title("Roz Roz Ka Masla..... Aaj Kya Pakayen!!! ")
86
+ st.title("Now generate weekly Menu with BMI Insights and more features")
87
 
88
  # Add food image at the top right of the app
89
  image = Image.open("food_image.jpg") # Ensure you have an image in the same folder
 
107
 
108
  outings = st.number_input("Enter the number of outings this week", min_value=0, max_value=14, value=0)
109
 
110
+ # Dietary restrictions
111
+ dietary_restrictions = st.selectbox("Select any dietary restrictions", ["None", "Diabetic", "Gluten-Free", "Low-Sodium"])
112
+
113
  st.header("How many dishes from each sub-category would you like?")
114
  sub_category_pref = {
115
  'Sabzi': st.number_input("Number of Sabzi dishes", min_value=0, value=0),
 
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
 
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)
143
  dinner_menu.to_excel(writer, sheet_name="Dinner", index=False)
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()