Update app.py
Browse files
app.py
CHANGED
|
@@ -87,17 +87,42 @@ def generate_menu(data, season, outings, dietary_restrictions, bmi, pantry_ingre
|
|
| 87 |
side_dishes = data[data['Course'] == 'Side Dish'].sample(2).to_dict('records')
|
| 88 |
menu.extend(side_dishes)
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
menu_df = pd.DataFrame(menu)
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
| 99 |
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
# Function to calculate BMI and recommend diet
|
| 103 |
def bmi_insights(weight, height_cm):
|
|
@@ -156,14 +181,24 @@ def main():
|
|
| 156 |
|
| 157 |
if st.button("Generate Menu"):
|
| 158 |
bmi = weight / (height_cm / 100) ** 2 # BMI calculation
|
| 159 |
-
lunch_menu, dinner_menu, total_cost, shopping_list = generate_menu(data, season, outings, dietary_restrictions, bmi, pantry_ingredients)
|
| 160 |
|
| 161 |
st.header("Weekly Menu")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
st.subheader("Lunch Menu")
|
| 163 |
-
|
|
|
|
| 164 |
|
|
|
|
| 165 |
st.subheader("Dinner Menu")
|
| 166 |
-
|
|
|
|
| 167 |
|
| 168 |
st.subheader(f"Total Expenditure for the Week: PKR {total_cost}")
|
| 169 |
|
|
@@ -174,6 +209,7 @@ def main():
|
|
| 174 |
|
| 175 |
# Save menu to Excel
|
| 176 |
with pd.ExcelWriter("weekly_menu_split.xlsx") as writer:
|
|
|
|
| 177 |
lunch_menu.to_excel(writer, sheet_name="Lunch", index=False)
|
| 178 |
dinner_menu.to_excel(writer, sheet_name="Dinner", index=False)
|
| 179 |
|
|
|
|
| 87 |
side_dishes = data[data['Course'] == 'Side Dish'].sample(2).to_dict('records')
|
| 88 |
menu.extend(side_dishes)
|
| 89 |
|
| 90 |
+
# Function to assign weekdays to dishes (for Breakfast, Lunch, and Dinner)
|
| 91 |
+
def assign_weekdays(menu):
|
| 92 |
+
weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
|
| 93 |
+
menu_with_weekdays = []
|
| 94 |
+
|
| 95 |
+
# Assigning the dishes to the weekdays for Breakfast, Lunch, and Dinner
|
| 96 |
+
for i, dish in enumerate(menu):
|
| 97 |
+
if isinstance(dish, dict):
|
| 98 |
+
dish_name = dish["Name"]
|
| 99 |
+
else:
|
| 100 |
+
dish_name = dish # If it's just a string, take the name directly
|
| 101 |
+
|
| 102 |
+
dish_with_day = {"Name": dish_name, "Weekday": weekdays[i % 7]}
|
| 103 |
+
menu_with_weekdays.append(dish_with_day)
|
| 104 |
+
|
| 105 |
+
return menu_with_weekdays
|
| 106 |
+
|
| 107 |
menu_df = pd.DataFrame(menu)
|
| 108 |
|
| 109 |
+
# Apply weekdays to the menu
|
| 110 |
+
full_menu_with_weekdays = assign_weekdays(menu_df)
|
| 111 |
|
| 112 |
+
# Split menu for breakfast, lunch, and dinner (assuming 7 for each)
|
| 113 |
+
breakfast_menu = full_menu_with_weekdays[:7]
|
| 114 |
+
lunch_menu = full_menu_with_weekdays[7:14]
|
| 115 |
+
dinner_menu = full_menu_with_weekdays[14:21]
|
| 116 |
|
| 117 |
+
# Convert to DataFrame for display
|
| 118 |
+
breakfast_menu_df = pd.DataFrame(breakfast_menu)
|
| 119 |
+
lunch_menu_df = pd.DataFrame(lunch_menu)
|
| 120 |
+
dinner_menu_df = pd.DataFrame(dinner_menu)
|
| 121 |
|
| 122 |
+
# Calculate total cost (assuming it's available in the data)
|
| 123 |
+
total_cost = menu_df["Cost per 4 persons"].sum()
|
| 124 |
+
|
| 125 |
+
return breakfast_menu_df, lunch_menu_df, dinner_menu_df, total_cost, shopping_list
|
| 126 |
|
| 127 |
# Function to calculate BMI and recommend diet
|
| 128 |
def bmi_insights(weight, height_cm):
|
|
|
|
| 181 |
|
| 182 |
if st.button("Generate Menu"):
|
| 183 |
bmi = weight / (height_cm / 100) ** 2 # BMI calculation
|
| 184 |
+
breakfast_menu, lunch_menu, dinner_menu, total_cost, shopping_list = generate_menu(data, season, outings, dietary_restrictions, bmi, pantry_ingredients)
|
| 185 |
|
| 186 |
st.header("Weekly Menu")
|
| 187 |
+
|
| 188 |
+
# Display Breakfast Menu
|
| 189 |
+
st.subheader("Breakfast Menu")
|
| 190 |
+
for index, row in breakfast_menu.iterrows():
|
| 191 |
+
st.write(f"{row['Weekday']}: {row['Name']}")
|
| 192 |
+
|
| 193 |
+
# Display Lunch Menu
|
| 194 |
st.subheader("Lunch Menu")
|
| 195 |
+
for index, row in lunch_menu.iterrows():
|
| 196 |
+
st.write(f"{row['Weekday']}: {row['Name']}")
|
| 197 |
|
| 198 |
+
# Display Dinner Menu
|
| 199 |
st.subheader("Dinner Menu")
|
| 200 |
+
for index, row in dinner_menu.iterrows():
|
| 201 |
+
st.write(f"{row['Weekday']}: {row['Name']}")
|
| 202 |
|
| 203 |
st.subheader(f"Total Expenditure for the Week: PKR {total_cost}")
|
| 204 |
|
|
|
|
| 209 |
|
| 210 |
# Save menu to Excel
|
| 211 |
with pd.ExcelWriter("weekly_menu_split.xlsx") as writer:
|
| 212 |
+
breakfast_menu.to_excel(writer, sheet_name="Breakfast", index=False)
|
| 213 |
lunch_menu.to_excel(writer, sheet_name="Lunch", index=False)
|
| 214 |
dinner_menu.to_excel(writer, sheet_name="Dinner", index=False)
|
| 215 |
|