menu / app.py
SanaAdeel's picture
Create app.py
3549b82 verified
import random
import pandas as pd
import streamlit as st
# Function to filter dishes by season
def filter_dishes_by_season(df, season='All Seasons'):
"""Filters the dataset based on the season."""
filtered_df = df[df['Season'].isin([season, 'All Seasons'])]
return filtered_df
# Function to generate weekly menu based on constraints
def generate_weekly_menu(df, season='All Seasons', budget=6000):
"""Generates a weekly menu based on user preferences."""
available_dishes = filter_dishes_by_season(df, season)
# Constraints for the weekly menu
required_categories = {
'meat': 1,
'chicken': 2,
'fish': 1,
'daal': 4,
'sabzi': 4,
'outing': 1,
'dessert': 2,
'snack': 2
}
weekly_menu = []
total_cost = 0
# Generate the menu by selecting dishes that meet the constraints
for category, count in required_categories.items():
if category == 'outing':
category_dishes = available_dishes[available_dishes['Home Made / Outing'].str.contains('Outing', case=False)]
else:
category_dishes = available_dishes[available_dishes['Sub-Category'].str.contains(category, case=False)]
if len(category_dishes) > 0:
selected_dishes = random.sample(list(category_dishes.iterrows()), min(count, len(category_dishes)))
for dish in selected_dishes:
dish_info = dish[1]
weekly_menu.append(dish_info['Name'])
total_cost += dish_info['Cost per 4 persons']
if total_cost > budget:
weekly_menu = []
total_cost = 0
for category, count in required_categories.items():
category_dishes = available_dishes[available_dishes['Sub-Category'].str.contains(category, case=False)]
category_dishes_sorted = category_dishes.sort_values(by='Cost per 4 persons')
selected_dishes = random.sample(list(category_dishes_sorted.iterrows()), min(count, len(category_dishes_sorted)))
for dish in selected_dishes:
dish_info = dish[1]
weekly_menu.append(dish_info['Name'])
total_cost += dish_info['Cost per 4 persons']
if total_cost > budget:
break
return weekly_menu, total_cost
# Streamlit UI
def main():
# Title of the app
st.title("Weekly Menu Generator")
# File upload for the Excel data
uploaded_file = st.file_uploader("Upload your Excel file", type=["xlsx"])
if uploaded_file is not None:
# Load the Excel file
df = pd.read_excel(uploaded_file, engine='openpyxl')
# User inputs for season and budget
season = st.selectbox("Select Season", ["All Seasons", "Summer", "Winter"])
budget = st.slider("Select Budget (PKR)", min_value=1000, max_value=10000, value=6000)
# Button to generate the menu
if st.button("Generate Weekly Menu"):
menu, total_cost = generate_weekly_menu(df, season, budget)
# Display the results
if menu:
st.write("### Weekly Menu:")
for dish in menu:
st.write(f"- {dish}")
st.write(f"**Total Cost: {total_cost} PKR**")
else:
st.write("Not enough dishes found for the selected criteria.")
if __name__ == "__main__":
main()