SanaAdeel commited on
Commit
3549b82
·
verified ·
1 Parent(s): f910910

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -0
app.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ import pandas as pd
3
+ import streamlit as st
4
+
5
+ # Function to filter dishes by season
6
+ def filter_dishes_by_season(df, season='All Seasons'):
7
+ """Filters the dataset based on the season."""
8
+ filtered_df = df[df['Season'].isin([season, 'All Seasons'])]
9
+ return filtered_df
10
+
11
+ # Function to generate weekly menu based on constraints
12
+ def generate_weekly_menu(df, season='All Seasons', budget=6000):
13
+ """Generates a weekly menu based on user preferences."""
14
+ available_dishes = filter_dishes_by_season(df, season)
15
+
16
+ # Constraints for the weekly menu
17
+ required_categories = {
18
+ 'meat': 1,
19
+ 'chicken': 2,
20
+ 'fish': 1,
21
+ 'daal': 4,
22
+ 'sabzi': 4,
23
+ 'outing': 1,
24
+ 'dessert': 2,
25
+ 'snack': 2
26
+ }
27
+
28
+ weekly_menu = []
29
+ total_cost = 0
30
+
31
+ # Generate the menu by selecting dishes that meet the constraints
32
+ for category, count in required_categories.items():
33
+ if category == 'outing':
34
+ category_dishes = available_dishes[available_dishes['Home Made / Outing'].str.contains('Outing', case=False)]
35
+ else:
36
+ category_dishes = available_dishes[available_dishes['Sub-Category'].str.contains(category, case=False)]
37
+
38
+ if len(category_dishes) > 0:
39
+ selected_dishes = random.sample(list(category_dishes.iterrows()), min(count, len(category_dishes)))
40
+ for dish in selected_dishes:
41
+ dish_info = dish[1]
42
+ weekly_menu.append(dish_info['Name'])
43
+ total_cost += dish_info['Cost per 4 persons']
44
+
45
+ if total_cost > budget:
46
+ weekly_menu = []
47
+ total_cost = 0
48
+ for category, count in required_categories.items():
49
+ category_dishes = available_dishes[available_dishes['Sub-Category'].str.contains(category, case=False)]
50
+ category_dishes_sorted = category_dishes.sort_values(by='Cost per 4 persons')
51
+ selected_dishes = random.sample(list(category_dishes_sorted.iterrows()), min(count, len(category_dishes_sorted)))
52
+ for dish in selected_dishes:
53
+ dish_info = dish[1]
54
+ weekly_menu.append(dish_info['Name'])
55
+ total_cost += dish_info['Cost per 4 persons']
56
+ if total_cost > budget:
57
+ break
58
+
59
+ return weekly_menu, total_cost
60
+
61
+ # Streamlit UI
62
+ def main():
63
+ # Title of the app
64
+ st.title("Weekly Menu Generator")
65
+
66
+ # File upload for the Excel data
67
+ uploaded_file = st.file_uploader("Upload your Excel file", type=["xlsx"])
68
+ if uploaded_file is not None:
69
+ # Load the Excel file
70
+ df = pd.read_excel(uploaded_file, engine='openpyxl')
71
+
72
+ # User inputs for season and budget
73
+ season = st.selectbox("Select Season", ["All Seasons", "Summer", "Winter"])
74
+ budget = st.slider("Select Budget (PKR)", min_value=1000, max_value=10000, value=6000)
75
+
76
+ # Button to generate the menu
77
+ if st.button("Generate Weekly Menu"):
78
+ menu, total_cost = generate_weekly_menu(df, season, budget)
79
+
80
+ # Display the results
81
+ if menu:
82
+ st.write("### Weekly Menu:")
83
+ for dish in menu:
84
+ st.write(f"- {dish}")
85
+ st.write(f"**Total Cost: {total_cost} PKR**")
86
+ else:
87
+ st.write("Not enough dishes found for the selected criteria.")
88
+
89
+ if __name__ == "__main__":
90
+ main()