Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import gdown | |
| from PIL import Image | |
| # Function to load data from Google Drive | |
| def load_data(file_url): | |
| file_path = "menu_data.xlsx" | |
| gdown.download(file_url, file_path, quiet=False) | |
| return pd.read_excel(file_path, engine='openpyxl') | |
| # Function to generate the weekly menu | |
| def generate_menu(data, season, sub_category_pref, outings): | |
| season_data = data[(data['Season'] == season) | (data['Season'] == 'All Seasons')] | |
| meals_needed = 14 - outings # Main Courses (14) minus outings | |
| menu = [] | |
| for sub_category, freq in sub_category_pref.items(): | |
| sub_category_dishes = season_data[season_data['Sub-Category'] == sub_category] | |
| menu.extend(sub_category_dishes.sample(min(freq, len(sub_category_dishes))).to_dict('records')) | |
| menu = menu[:meals_needed] | |
| outing_dishes = data[data['Home Made / Outing'] == 'Outing'].sample(outings).to_dict('records') | |
| menu.extend(outing_dishes) | |
| side_dishes = data[data['Course'] == 'Side Dish'].sample(2).to_dict('records') | |
| menu.extend(side_dishes) | |
| menu_df = pd.DataFrame(menu) | |
| lunch_menu = menu_df.iloc[:len(menu_df)//2] | |
| dinner_menu = menu_df.iloc[len(menu_df)//2:] | |
| total_cost = menu_df["Cost per 4 persons"].sum() | |
| lunch_menu = lunch_menu[["Name"]] | |
| dinner_menu = dinner_menu[["Name"]] | |
| return lunch_menu, dinner_menu, total_cost | |
| # Function to calculate BMI and recommend diet for adults | |
| def bmi_insights(weight, height_cm): | |
| height_m = height_cm / 100 | |
| 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." | |
| elif 18.5 <= bmi < 24.9: | |
| return f"Your BMI is {bmi:.2f}. You are in the normal weight range. Maintain a balanced diet." | |
| elif 25 <= bmi < 29.9: | |
| return f"Your BMI is {bmi:.2f}. You are overweight. A diet with fewer carbs and more lean proteins can help manage your weight." | |
| else: | |
| return f"Your BMI is {bmi:.2f}. You are obese. A calorie-restricted diet with a focus on whole foods and lean proteins is recommended." | |
| # Function to provide general diet recommendation for infants | |
| def infant_diet_recommendation(): | |
| return ( | |
| "For infants (up to 12 months), breast milk or formula should be the primary source of nutrition. " | |
| "Around 6 months, you can start introducing solid foods, including pureed fruits, vegetables, and cereals. " | |
| "Consult with your pediatrician for more personalized advice." | |
| ) | |
| # Function to provide dietary recommendations based on medical conditions | |
| def medical_condition_recommendation(condition): | |
| recommendations = { | |
| "Diabetes": "A low-carb diet is essential. Focus on fiber-rich vegetables, lean proteins, and healthy fats. Avoid sugary foods.", | |
| "Celiac Disease": "Avoid gluten-containing foods like wheat, barley, and rye. Focus on gluten-free grains, fruits, vegetables, and lean proteins.", | |
| "Hypertension": "Limit salt intake. Incorporate potassium-rich foods such as bananas, spinach, and potatoes. A heart-healthy diet with lean proteins is ideal.", | |
| "Heart Disease": "Consume a heart-healthy diet rich in omega-3 fatty acids, vegetables, and whole grains. Limit saturated fats and processed foods.", | |
| "Obesity": "Focus on a calorie-restricted diet, prioritizing vegetables, lean meats, and whole grains. Avoid sugary snacks and drinks.", | |
| "Cholesterol Disorders": "Eat foods rich in fiber, such as oats, fruits, and vegetables. Limit saturated fats and trans fats.", | |
| "IBS": "Incorporate fiber-rich foods like oats and vegetables. Avoid foods that cause bloating, such as beans, cabbage, and onions.", | |
| "GERD": "Avoid acidic and spicy foods, caffeine, and alcohol. Focus on bland, easy-to-digest meals like rice, oatmeal, and non-citrus fruits.", | |
| "Peptic Ulcers": "Avoid spicy, fatty, and acidic foods. Focus on bland foods like rice, oatmeal, and non-citrus fruits.", | |
| "Gout": "Limit foods high in purines, such as red meat, shellfish, and alcohol. Focus on low-fat dairy, fruits, and vegetables.", | |
| "Lactose Intolerance": "Avoid dairy products or choose lactose-free alternatives. Incorporate plant-based sources of calcium.", | |
| "Kidney Disease": "Reduce sodium, potassium, and phosphorus intake. Focus on lean proteins and avoid processed foods.", | |
| "Hypothyroidism": "Increase iodine-rich foods like seaweed, eggs, and dairy. Focus on vegetables and lean proteins.", | |
| "Anemia": "Focus on iron-rich foods such as red meat, spinach, and beans. Pair with vitamin C-rich foods for better absorption.", | |
| "Food Allergies": "Avoid allergenic foods like peanuts, tree nuts, dairy, eggs, shellfish, and others. Focus on a balanced, allergy-free diet.", | |
| "Acid Reflux": "Avoid acidic and spicy foods. Incorporate alkaline foods like bananas, melons, and oatmeal.", | |
| "Crohn's Disease": "Focus on low-fiber foods and avoid spicy, fatty, and acidic foods. Prioritize lean meats and easy-to-digest grains.", | |
| "Osteoporosis": "Ensure adequate calcium and vitamin D intake through dairy or fortified alternatives. Incorporate weight-bearing exercises.", | |
| "Autoimmune Diseases": "A diet rich in anti-inflammatory foods like leafy greens, berries, nuts, and fatty fish is ideal.", | |
| "Migraines": "Avoid foods that trigger migraines, such as chocolate, caffeine, and aged cheeses. Focus on magnesium-rich foods.", | |
| "PCOS": "Focus on a low-glycemic index diet with plenty of fruits, vegetables, and lean proteins. Limit processed sugars.", | |
| "CFS": "A balanced diet with adequate calories and nutrients is essential. Focus on anti-inflammatory foods and avoid refined sugars.", | |
| "Mental Health": "Focus on omega-3 fatty acids, whole grains, fruits, and vegetables. Avoid processed foods and sugar." | |
| } | |
| return recommendations.get(condition, "No specific recommendations available.") | |
| # Main workflow | |
| def main(): | |
| st.title("Roz Roz Ka Masla..... Aaj Kya Pakayen!!! ") | |
| 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 folder | |
| st.sidebar.image(image, use_container_width=True) | |
| # User input for BMI insights or Infant's weekly diet | |
| st.sidebar.header("Select your category:") | |
| category = st.sidebar.radio("Are you an Adult or Infant?", ["Adult", "Infant"]) | |
| if category == "Infant": | |
| st.sidebar.header("Infant Weekly Diet Recommendations") | |
| diet_recommendation = infant_diet_recommendation() | |
| st.sidebar.write(diet_recommendation) | |
| return | |
| if category == "Adult": | |
| # User input for BMI insights (only for Adults) | |
| st.sidebar.header("Enter your details for BMI insights:") | |
| weight = st.sidebar.number_input("Enter your weight (kg)", min_value=30, max_value=200, value=70) | |
| height_cm = st.sidebar.number_input("Enter your height (cm)", min_value=90, max_value=250, value=175) | |
| if st.sidebar.button("Get BMI Insights"): | |
| bmi_message = bmi_insights(weight, height_cm) | |
| st.sidebar.success(bmi_message) | |
| # Dropdown for selecting medical condition(s) | |
| medical_condition = st.sidebar.selectbox( | |
| "Select any medical condition", [ | |
| "None", "Diabetes", "Celiac Disease", "Hypertension", "Heart Disease", "Obesity", | |
| "Cholesterol Disorders", "IBS", "GERD", "Peptic Ulcers", "Gout", "Lactose Intolerance", | |
| "Kidney Disease", "Hypothyroidism", "Anemia", "Food Allergies", "Acid Reflux", | |
| "Crohn's Disease", "Osteoporosis", "Autoimmune Diseases", "Migraines", "PCOS", | |
| "CFS", "Mental Health" | |
| ] | |
| ) | |
| if medical_condition != "None": | |
| condition_recommendation = medical_condition_recommendation(medical_condition) | |
| st.sidebar.write(condition_recommendation) | |
| # Google Drive file URL | |
| file_url = 'https://drive.google.com/uc?id=1BJFao3C6p8k3_KjLfmDo5KbNMrTs7MRo' # Replace with actual file link | |
| data = load_data(file_url) | |
| # Main menu generation section (for Adults) | |
| if category == "Adult": | |
| season = st.selectbox("Select the current season", ["Summer", "Winter"]) | |
| outings = st.number_input("Enter the number of outings this week", min_value=0, max_value=14, value=0) | |
| st.header("How many dishes from each sub-category would you like?") | |
| sub_category_pref = { | |
| 'Sabzi': st.number_input("Number of Sabzi dishes", min_value=0, value=0), | |
| 'Rice': st.number_input("Number of Rice dishes", min_value=0, value=0), | |
| 'Daal': st.number_input("Number of Daal dishes", min_value=0, value=0), | |
| 'Meat': st.number_input("Number of Meat dishes", min_value=0, value=0), | |
| 'Chicken': st.number_input("Number of Chicken dishes", min_value=0, value=0), | |
| 'Fish': st.number_input("Number of Fish dishes", min_value=0, value=0) | |
| } | |
| total_main_courses = sum(sub_category_pref.values()) + outings | |
| if total_main_courses > 14: | |
| st.warning("The total number of main courses exceeds 14! Please adjust your preferences.") | |
| return | |
| if st.button("Generate Menu"): | |
| lunch_menu, dinner_menu, total_cost = generate_menu(data, season, sub_category_pref, outings) | |
| st.header("Weekly Menu") | |
| st.subheader("Lunch Menu") | |
| st.write(lunch_menu) | |
| st.subheader("Dinner Menu") | |
| st.write(dinner_menu) | |
| st.subheader(f"Total Expenditure for the Week: PKR {total_cost}") | |
| # Save menu to Excel | |
| with pd.ExcelWriter("weekly_menu_split.xlsx") as writer: | |
| lunch_menu.to_excel(writer, sheet_name="Lunch", index=False) | |
| dinner_menu.to_excel(writer, sheet_name="Dinner", index=False) | |
| st.success("Weekly menu saved as 'weekly_menu_split.xlsx'") | |
| if __name__ == "__main__": | |
| main() | |