engralimalik commited on
Commit
017b4e8
·
verified ·
1 Parent(s): 60b210e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +108 -0
app.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+
4
+ # Function to generate the grocery list
5
+ def generate_grocery_list(family_details, budget, region, preferences):
6
+ grocery_list = []
7
+ price_estimates = {
8
+ "Rice (1kg)": 2.5,
9
+ "Flour (1kg)": 1.2,
10
+ "Milk (1L)": 1.5,
11
+ "Eggs (12)": 2.0,
12
+ "Chicken (1kg)": 5.0,
13
+ "Beef (1kg)": 8.0,
14
+ "Vegetables (1kg)": 3.0,
15
+ "Fruits (1kg)": 4.0,
16
+ "Bread (loaf)": 1.0,
17
+ "Cooking Oil (1L)": 3.5,
18
+ "Sugar (1kg)": 1.8,
19
+ "Salt (1kg)": 0.5
20
+ }
21
+
22
+ # Estimate quantity based on family members and age groups
23
+ rice_needed = family_details['adults'] * 5 + family_details['children_under_5'] * 2 + family_details['children_5_to_12'] * 4
24
+ flour_needed = family_details['adults'] * 4 + family_details['children_under_5'] * 2 + family_details['children_5_to_12'] * 3
25
+ milk_needed = family_details['adults'] * 10 + family_details['children_under_5'] * 8 + family_details['children_5_to_12'] * 7
26
+ eggs_needed = family_details['adults'] * 12 + family_details['children_5_to_12'] * 8
27
+ chicken_needed = family_details['adults'] * 4 + family_details['children_5_to_12'] * 2
28
+
29
+ # Add the items to the grocery list
30
+ grocery_list.append(f"Rice (kg): {rice_needed} kg")
31
+ grocery_list.append(f"Flour (kg): {flour_needed} kg")
32
+ grocery_list.append(f"Milk (L): {milk_needed} L")
33
+ grocery_list.append(f"Eggs: {eggs_needed} dozen")
34
+ grocery_list.append(f"Chicken (kg): {chicken_needed} kg")
35
+
36
+ # Calculate the total estimated price
37
+ total_cost = (rice_needed * price_estimates["Rice (1kg)"] +
38
+ flour_needed * price_estimates["Flour (1kg)"] +
39
+ milk_needed * price_estimates["Milk (1L)"] +
40
+ eggs_needed * price_estimates["Eggs (12)"] +
41
+ chicken_needed * price_estimates["Chicken (1kg)"])
42
+
43
+ # Ensure the list fits within the budget
44
+ if total_cost > budget:
45
+ grocery_list.append(f"Warning: Your budget of ${budget} is insufficient. Total cost is ${total_cost:.2f}.")
46
+ else:
47
+ grocery_list.append(f"Total estimated cost: ${total_cost:.2f}")
48
+
49
+ return grocery_list
50
+
51
+ # Streamlit App UI
52
+ st.title("Family Grocery List Generator")
53
+ st.markdown("""
54
+ **Create a monthly grocery list based on your family size, preferences, and budget.**
55
+ """)
56
+
57
+ # Collecting user inputs
58
+ st.sidebar.header("Enter Your Family Details")
59
+
60
+ # Number of family members in different age groups
61
+ num_adults = st.sidebar.number_input("Number of Adults (Age 18+)", min_value=0, value=2)
62
+ num_children_under_5 = st.sidebar.number_input("Number of Children under 5", min_value=0, value=1)
63
+ num_children_5_to_12 = st.sidebar.number_input("Number of Children (5-12 years)", min_value=0, value=1)
64
+ num_teenagers = st.sidebar.number_input("Number of Teenagers (13-18 years)", min_value=0, value=1)
65
+
66
+ # Family preferences
67
+ food_preferences = st.sidebar.selectbox("Food Preferences", ["Halal", "Vegetarian", "Non-Vegetarian"])
68
+ region = st.sidebar.selectbox("Region", ["South Asia", "Middle East", "North America", "Europe"])
69
+
70
+ # Budget
71
+ budget = st.sidebar.number_input("Monthly Grocery Budget ($)", min_value=50, value=150)
72
+
73
+ # Family Details Dictionary
74
+ family_details = {
75
+ 'adults': num_adults,
76
+ 'children_under_5': num_children_under_5,
77
+ 'children_5_to_12': num_children_5_to_12,
78
+ 'teenagers': num_teenagers
79
+ }
80
+
81
+ # Button to generate grocery list
82
+ if st.sidebar.button("Generate Grocery List"):
83
+ # Generate the list based on user inputs
84
+ grocery_list = generate_grocery_list(family_details, budget, region, food_preferences)
85
+
86
+ # Display the grocery list
87
+ st.subheader("Your Monthly Grocery List:")
88
+ for item in grocery_list:
89
+ st.write(f"- {item}")
90
+
91
+ # Prepare the quotation text
92
+ grocery_list_text = "\n".join(grocery_list)
93
+
94
+ # Provide a download button for the list
95
+ st.download_button(
96
+ label="Download Grocery List",
97
+ data=grocery_list_text.encode('utf-8'),
98
+ file_name="monthly_grocery_list.txt",
99
+ mime="text/plain"
100
+ )
101
+
102
+ # About Section
103
+ st.sidebar.markdown("""
104
+ ## About the App
105
+ This app helps you create a monthly grocery list based on the size and preferences of your family.
106
+ You can input the number of adults, children, teenagers, and specify food preferences like Halal, Vegetarian, or Non-Vegetarian.
107
+ The app then generates a grocery list along with estimated prices and compares it to your budget.
108
+ """)