SanaAdeel commited on
Commit
55d91f4
·
verified ·
1 Parent(s): 70e6c0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -59
app.py CHANGED
@@ -10,24 +10,15 @@ 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, dietary_restriction, outings):
14
- # Filter data by season and dietary restrictions
15
  season_data = data[(data['Season'] == season) | (data['Season'] == 'All Seasons')]
16
 
17
- # Apply dietary restrictions (e.g., remove gluten or low-sodium)
18
- if dietary_restriction == "Gluten-Free":
19
- season_data = season_data[season_data['Gluten-Free'] == True]
20
- elif dietary_restriction == "Low-Sodium":
21
- season_data = season_data[season_data['Sodium'] < 100]
22
-
23
  meals_needed = 14 - outings # Main Courses (14) minus outings
24
 
25
  menu = []
26
- sub_categories = ['Sabzi', 'Rice', 'Daal', 'Meat', 'Chicken', 'Fish']
27
-
28
- for sub_category in sub_categories:
29
  sub_category_dishes = season_data[season_data['Sub-Category'] == sub_category]
30
- menu.extend(sub_category_dishes.sample(min(1, len(sub_category_dishes))).to_dict('records'))
31
 
32
  menu = menu[:meals_needed]
33
 
@@ -39,37 +30,19 @@ def generate_menu(data, season, dietary_restriction, outings):
39
 
40
  menu_df = pd.DataFrame(menu)
41
 
42
- # Function to assign weekdays to dishes
43
- def assign_weekdays(menu):
44
- weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
45
-
46
- menu_with_weekdays = []
47
- for i, dish in enumerate(menu):
48
- if isinstance(dish, dict):
49
- dish_with_day = dish.copy() # Copy the dish dictionary
50
- else:
51
- dish_with_day = {"Name": dish} # If it's just a string, create a dict with "Name" key
52
-
53
- dish_with_day["Weekday"] = weekdays[i % 7] # Assign the weekday
54
- menu_with_weekdays.append(dish_with_day)
55
-
56
- return pd.DataFrame(menu_with_weekdays)
57
-
58
  lunch_menu = menu_df.iloc[:len(menu_df)//2]
59
  dinner_menu = menu_df.iloc[len(menu_df)//2:]
60
 
61
  total_cost = menu_df["Cost per 4 persons"].sum()
62
 
63
- lunch_menu = assign_weekdays(lunch_menu)
64
- dinner_menu = assign_weekdays(dinner_menu)
65
-
66
- lunch_menu = lunch_menu[["Name", "Weekday"]]
67
- dinner_menu = dinner_menu[["Name", "Weekday"]]
68
 
69
  return lunch_menu, dinner_menu, total_cost
70
 
71
- # Function to calculate BMI and recommend diet
72
  def bmi_insights(weight, height_cm):
 
73
  height_m = height_cm / 100
74
  bmi = weight / (height_m ** 2)
75
 
@@ -82,6 +55,15 @@ def bmi_insights(weight, height_cm):
82
  else:
83
  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."
84
 
 
 
 
 
 
 
 
 
 
85
  # Main workflow
86
  def main():
87
  st.title("Roz Roz Ka Masla..... Aaj Kya Pakayen!!! ")
@@ -91,44 +73,69 @@ def main():
91
  image = Image.open("food_image.jpg") # Ensure you have an image in the same folder
92
  st.sidebar.image(image, use_container_width=True)
93
 
94
- # User input for BMI insights
95
- st.sidebar.header("Enter your details for BMI insights:")
96
- weight = st.sidebar.number_input("Enter your weight (kg)", min_value=30, max_value=200, value=70)
97
- height_cm = st.sidebar.number_input("Enter your height (cm)", min_value=90, max_value=250, value=175)
 
 
 
 
 
98
 
99
- if st.sidebar.button("Get BMI Insights"):
100
- bmi_message = bmi_insights(weight, height_cm)
101
- st.sidebar.success(bmi_message)
 
 
 
 
 
 
102
 
103
  # Google Drive file URL
104
  file_url = 'https://drive.google.com/uc?id=1BJFao3C6p8k3_KjLfmDo5KbNMrTs7MRo' # Replace with actual file link
105
  data = load_data(file_url)
106
 
107
- # Main menu generation section
108
- season = st.selectbox("Select the current season", ["Summer", "Winter"])
109
- dietary_restriction = st.selectbox("Select your dietary restriction", ["None", "Gluten-Free", "Low-Sodium"])
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
- outings = st.number_input("Enter the number of outings this week", min_value=0, max_value=14, value=0)
 
 
 
112
 
113
- # Generate Menu when button is clicked
114
- if st.button("Generate Menu"):
115
- lunch_menu, dinner_menu, total_cost = generate_menu(data, season, dietary_restriction, outings)
116
 
117
- st.header("Weekly Menu")
118
- st.subheader("Lunch Menu")
119
- st.write(lunch_menu)
120
 
121
- st.subheader("Dinner Menu")
122
- st.write(dinner_menu)
123
 
124
- st.subheader(f"Total Expenditure for the Week: PKR {total_cost}")
125
 
126
- # Save menu to Excel
127
- with pd.ExcelWriter("weekly_menu_split.xlsx") as writer:
128
- lunch_menu.to_excel(writer, sheet_name="Lunch", index=False)
129
- dinner_menu.to_excel(writer, sheet_name="Dinner", index=False)
130
 
131
- st.success("Weekly menu saved as 'weekly_menu_split.xlsx'")
132
 
133
  if __name__ == "__main__":
134
  main()
 
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
17
 
18
  menu = []
19
+ for sub_category, freq in sub_category_pref.items():
 
 
20
  sub_category_dishes = season_data[season_data['Sub-Category'] == sub_category]
21
+ menu.extend(sub_category_dishes.sample(min(freq, len(sub_category_dishes))).to_dict('records'))
22
 
23
  menu = menu[:meals_needed]
24
 
 
30
 
31
  menu_df = pd.DataFrame(menu)
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  lunch_menu = menu_df.iloc[:len(menu_df)//2]
34
  dinner_menu = menu_df.iloc[len(menu_df)//2:]
35
 
36
  total_cost = menu_df["Cost per 4 persons"].sum()
37
 
38
+ lunch_menu = lunch_menu[["Name"]]
39
+ dinner_menu = dinner_menu[["Name"]]
 
 
 
40
 
41
  return lunch_menu, dinner_menu, total_cost
42
 
43
+ # Function to calculate BMI and recommend diet for adults
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
 
 
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
+ # Function to provide general diet recommendation for infants
59
+ def infant_diet_recommendation():
60
+ return (
61
+ "For infants (up to 12 months), breast milk or formula should be the primary source of nutrition. "
62
+ "Around 6 months, you can start introducing solid foods, including pureed fruits, vegetables, and cereals. "
63
+ "Ensure a variety of textures as they grow and introduce protein-rich foods, like pureed meat or lentils. "
64
+ "Consult with your pediatrician for more personalized advice."
65
+ )
66
+
67
  # Main workflow
68
  def main():
69
  st.title("Roz Roz Ka Masla..... Aaj Kya Pakayen!!! ")
 
73
  image = Image.open("food_image.jpg") # Ensure you have an image in the same folder
74
  st.sidebar.image(image, use_container_width=True)
75
 
76
+ # User input for BMI insights or Infant's weekly diet
77
+ st.sidebar.header("Select your category:")
78
+ category = st.sidebar.radio("Are you an Adult or Infant?", ["Adult", "Infant"])
79
+
80
+ if category == "Infant":
81
+ st.sidebar.header("Infant Weekly Diet Recommendations")
82
+ diet_recommendation = infant_diet_recommendation()
83
+ st.sidebar.write(diet_recommendation)
84
+ return
85
 
86
+ if category == "Adult":
87
+ # User input for BMI insights (only for Adults)
88
+ st.sidebar.header("Enter your details for BMI insights:")
89
+ weight = st.sidebar.number_input("Enter your weight (kg)", min_value=30, max_value=200, value=70)
90
+ height_cm = st.sidebar.number_input("Enter your height (cm)", min_value=90, max_value=250, value=175)
91
+
92
+ if st.sidebar.button("Get BMI Insights"):
93
+ bmi_message = bmi_insights(weight, height_cm)
94
+ st.sidebar.success(bmi_message)
95
 
96
  # Google Drive file URL
97
  file_url = 'https://drive.google.com/uc?id=1BJFao3C6p8k3_KjLfmDo5KbNMrTs7MRo' # Replace with actual file link
98
  data = load_data(file_url)
99
 
100
+ # Main menu generation section (for Adults)
101
+ if category == "Adult":
102
+ season = st.selectbox("Select the current season", ["Summer", "Winter"])
103
+
104
+ outings = st.number_input("Enter the number of outings this week", min_value=0, max_value=14, value=0)
105
+
106
+ st.header("How many dishes from each sub-category would you like?")
107
+ sub_category_pref = {
108
+ 'Sabzi': st.number_input("Number of Sabzi dishes", min_value=0, value=0),
109
+ 'Rice': st.number_input("Number of Rice dishes", min_value=0, value=0),
110
+ 'Daal': st.number_input("Number of Daal dishes", min_value=0, value=0),
111
+ 'Meat': st.number_input("Number of Meat dishes", min_value=0, value=0),
112
+ 'Chicken': st.number_input("Number of Chicken dishes", min_value=0, value=0),
113
+ 'Fish': st.number_input("Number of Fish dishes", min_value=0, value=0)
114
+ }
115
 
116
+ total_main_courses = sum(sub_category_pref.values()) + outings
117
+ if total_main_courses > 14:
118
+ st.warning("The total number of main courses exceeds 14! Please adjust your preferences.")
119
+ return
120
 
121
+ if st.button("Generate Menu"):
122
+ lunch_menu, dinner_menu, total_cost = generate_menu(data, season, sub_category_pref, outings)
 
123
 
124
+ st.header("Weekly Menu")
125
+ st.subheader("Lunch Menu")
126
+ st.write(lunch_menu)
127
 
128
+ st.subheader("Dinner Menu")
129
+ st.write(dinner_menu)
130
 
131
+ st.subheader(f"Total Expenditure for the Week: PKR {total_cost}")
132
 
133
+ # Save menu to Excel
134
+ with pd.ExcelWriter("weekly_menu_split.xlsx") as writer:
135
+ lunch_menu.to_excel(writer, sheet_name="Lunch", index=False)
136
+ dinner_menu.to_excel(writer, sheet_name="Dinner", index=False)
137
 
138
+ st.success("Weekly menu saved as 'weekly_menu_split.xlsx'")
139
 
140
  if __name__ == "__main__":
141
  main()