Update app.py
Browse files8 unmodified lines91011121312131415161617181920212223242526272829303132333435363738394041424344454647484950515217181920212223242557262759282961626364656667686970717273747576777879803031323332 unmodified lines666768119697071721 unmodified line74757612777781297980131818213313413513613783848586871428889909114 unmodified lines1061071081091101111121661671681691701711721731741751131141771781151161171184 unmodified lines1231241251891901911921931261271288 unmodified lines gdown.download(file_url, file_path, quiet=False) return pd.read_excel(file_path, engine='openpyxl')
# Function to generate the weekly menu based on BMI, dietary restriction, and pantry syncdef generate_menu(data, season, outings, dietary_restrictions, bmi, pantry_ingredients):# Function to generate the weekly menudef generate_menu(data, season, dietary_restriction, outings): # Filter data by season and dietary restrictions season_data = data[(data['Season'] == season) | (data['Season'] == 'All Seasons')]
# Define the number of dishes based on BMI if bmi < 18.5: # Underweight sub_category_pref = { 'Sabzi': 3, # More vegetables to increase calorie intake 'Rice': 2, # More rice to increase carbohydrates 'Daal': 2, # Protein-rich dals 'Meat': 3, # More meat for proteins 'Chicken': 2, 'Fish': 1 } elif 18.5 <= bmi < 24.9: # Normal weight sub_category_pref = { 'Sabzi': 2, 'Rice': 2, 'Daal': 2, 'Meat': 2, 'Chicken': 2, 'Fish': 1 } elif 25 <= bmi < 29.9: # Overweight sub_category_pref = { 'Sabzi': 4, # More vegetables 'Rice': 1, # Limit rice 'Daal': 2, # Protein-rich dals 'Meat': 1, # Limit meat intake 'Chicken': 3, 'Fish': 1 } else: # Obese sub_category_pref = { 'Sabzi': 5, # More vegetables 'Rice': 1, # Very limited rice 'Daal': 2, # Protein-rich dals 'Meat': 1, # Very limited meat 'Chicken': 2, 'Fish': 1 } # Apply dietary restrictions (e.g., remove gluten or low-sodium) if dietary_restriction == "Gluten-Free": season_data = season_data[season_data['Gluten-Free'] == True] elif dietary_restriction == "Low-Sodium": season_data = season_data[season_data['Sodium'] < 100]
meals_needed = 14 - outings # Main Courses (14) minus outings
menu = [] shopping_list = set() # Track missing ingredients sub_categories = ['Sabzi', 'Rice', 'Daal', 'Meat', 'Chicken', 'Fish']
for sub_category, freq in sub_category_pref.items(): for sub_category in sub_categories: sub_category_dishes = season_data[season_data['Sub-Category'] == sub_category] # Filter dishes based on dietary restrictions if dietary_restrictions == 'Diabetic': sub_category_dishes = sub_category_dishes[~sub_category_dishes['Ingredients'].str.contains('sugar', case=False, na=False)] elif dietary_restrictions == 'Gluten-Free': sub_category_dishes = sub_category_dishes[~sub_category_dishes['Ingredients'].str.contains('gluten', case=False, na=False)] elif dietary_restrictions == 'Low-Sodium': sub_category_dishes = sub_category_dishes[~sub_category_dishes['Ingredients'].str.contains('sodium', case=False, na=False)]
# Sample the dishes based on the user preference selected_dishes = sub_category_dishes.sample(min(freq, len(sub_category_dishes)))
# Check the ingredients for the pantry and add missing items to the shopping list for dish in selected_dishes.to_dict('records'): ingredients = dish.get('Ingredients', '').split(',') for ingredient in ingredients: if ingredient.strip().lower() not in pantry_ingredients: shopping_list.add(ingredient.strip().lower())
menu.append(dish) menu.extend(sub_category_dishes.sample(min(1, len(sub_category_dishes))).to_dict('records'))
menu = menu[:meals_needed]
32 unmodified lines lunch_menu = lunch_menu[["Name", "Weekday"]] dinner_menu = dinner_menu[["Name", "Weekday"]]
return lunch_menu, dinner_menu, total_cost, shopping_list return lunch_menu, dinner_menu, total_cost
# Function to calculate BMI and recommend dietdef bmi_insights(weight, height_cm):1 unmodified line bmi = weight / (height_m ** 2)
if bmi < 18.5: return f"Your BMI is {bmi:.2f}. You are underweight. A diet rich in proteins and healthy fats would be beneficial." return f"Your BMI is {bmi:.2f}. You are underweight. A diet rich in proteins and healthy fats would be beneficial. Consider incorporating more calories and nutritious snacks." elif 18.5 <= bmi < 24.9: return f"Your BMI is {bmi:.2f}. You are in the normal weight range. Maintain a balanced diet." return f"Your BMI is {bmi:.2f}. You are in the normal weight range. Maintain a balanced diet, including fruits, vegetables, whole grains, and lean proteins." elif 25 <= bmi < 29.9: return f"Your BMI is {bmi:.2f}. You are overweight. Consider reducing sugar intake." return f"Your BMI is {bmi:.2f}. You are overweight. A diet with fewer carbs and more lean proteins can help manage your weight. Consider reducing sugar intake." else: return f"Your BMI is {bmi:.2f}. You are obese. A calorie-restricted diet with lean proteins is recommended."
# Function for Smart Inventory Management (Pantry Sync)def pantry_sync(available_ingredients): return set(available_ingredients) 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."
# Main workflowdef main(): st.title("Roz Roz Ka Masla..... Aaj Kya Pakayen!!! ") st.title("Now generate weekly Menu with BMI Insights and more features") st.title("Now generate weekly Menu with BMI Insights") # Add food image at the top right of the app image = Image.open("food_image.jpg") # Ensure you have an image in the same folder14 unmodified lines
# Main menu generation section season = st.selectbox("Select the current season", ["Summer", "Winter"]) dietary_restriction = st.selectbox("Select your dietary restriction", ["None", "Gluten-Free", "Low-Sodium"])
outings = st.number_input("Enter the number of outings this week", min_value=0, max_value=14, value=0)
# Dietary restrictions dietary_restrictions = st.selectbox("Select any dietary restrictions", ["None", "Diabetic", "Gluten-Free", "Low-Sodium"])
# Pantry Sync pantry_ingredients_input = st.text_area("Enter available ingredients in your pantry (comma separated)") if pantry_ingredients_input: pantry_ingredients = pantry_sync(pantry_ingredients_input.split(',')) else: pantry_ingredients = set()
# Generate Menu when button is clicked if st.button("Generate Menu"): bmi = weight / (height_cm / 100) ** 2 # BMI calculation lunch_menu, dinner_menu, total_cost, shopping_list = generate_menu(data, season, outings, dietary_restrictions, bmi, pantry_ingredients) lunch_menu, dinner_menu, total_cost = generate_menu(data, season, dietary_restriction, outings)
st.header("Weekly Menu") st.subheader("Lunch Menu")4 unmodified lines
st.subheader(f"Total Expenditure for the Week: PKR {total_cost}")
# Shopping list for missing ingredients if shopping_list: st.subheader("Shopping List for Missing Ingredients") st.write(sorted(shopping_list))
# Save menu to Excel with pd.ExcelWriter("weekly_menu_split.xlsx") as writer: lunch_menu.to_excel(writer, sheet_name="Lunch", index=False)app.py+20-88