Update app.py
Browse files8 unmodified lines9101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828332 unmodified lines1161171181191201211221 unmodified line12412512612712812913013113213313413513613713813914014114214314414514 unmodified lines1601611621631641651661671681691701711721731741751761771781791801814 unmodified lines1861871881891901911921931941951968 unmodified linesgdown.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):season_data = data[(data['Season'] == season) | (data['Season'] == 'All Seasons')]# Define the number of dishes based on BMIif bmi < 18.5: # Underweightsub_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 weightsub_category_pref = {'Sabzi': 2,'Rice': 2,'Daal': 2,'Meat': 2,'Chicken': 2,'Fish': 1}elif 25 <= bmi < 29.9: # Overweightsub_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: # Obesesub_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}meals_needed = 14 - outings # Main Courses (14) minus outingsmenu = []shopping_list = set() # Track missing ingredientsfor sub_category, freq in sub_category_pref.items():sub_category_dishes = season_data[season_data['Sub-Category'] == sub_category]# Filter dishes based on dietary restrictionsif 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 preferenceselected_dishes = sub_category_dishes.sample(min(freq, len(sub_category_dishes)))# Check the ingredients for the pantry and add missing items to the shopping listfor 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 = menu[:meals_needed]32 unmodified lineslunch_menu = lunch_menu[["Name", "Weekday"]]dinner_menu = dinner_menu[["Name", "Weekday"]]return lunch_menu, dinner_menu, total_cost, shopping_list# Function to calculate BMI and recommend dietdef bmi_insights(weight, height_cm):1 unmodified linebmi = 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. 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)# Main workflowdef main():st.title("Roz Roz Ka Masla..... Aaj Kya Pakayen!!! ")st.title("Now generate weekly Menu with BMI Insights and more features")# Add food image at the top right of the appimage = Image.open("food_image.jpg") # Ensure you have an image in the same folder14 unmodified lines# Main menu generation sectionseason = 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)# Dietary restrictionsdietary_restrictions = st.selectbox("Select any dietary restrictions", ["None", "Diabetic", "Gluten-Free", "Low-Sodium"])# Pantry Syncpantry_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()if st.button("Generate Menu"):bmi = weight / (height_cm / 100) ** 2 # BMI calculationlunch_menu, dinner_menu, total_cost, shopping_list = generate_menu(data, season, outings, dietary_restrictions, bmi, pantry_ingredients)st.header("Weekly Menu")st.subheader("Lunch Menu")4 unmodified linesst.subheader(f"Total Expenditure for the Week: PKR {total_cost}")# Shopping list for missing ingredientsif shopping_list:st.subheader("Shopping List for Missing Ingredients")st.write(sorted(shopping_list))# Save menu to Excelwith pd.ExcelWriter("weekly_menu_split.xlsx") as writer:lunch_menu.to_excel(writer, sheet_name="Lunch", index=False)8 unmodified lines910111213141516171819202122232425262728293031323332 unmodified lines666768697071721 unmodified line74757677787980818283848586878889909114 unmodified lines1061071081091101111121131141151161171184 unmodified lines1231241251261271288 unmodified linesgdown.download(file_url, file_path, quiet=False)return pd.read_excel(file_path, engine='openpyxl')# Function to generate the weekly menudef generate_menu(data, season, dietary_restriction, outings):# Filter data by season and dietary restrictionsseason_data = data[(data['Season'] == season) | (data['Season'] == 'All Seasons')]# 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 outingsmenu = []sub_categories = ['Sabzi', 'Rice', 'Daal', 'Meat', 'Chicken', 'Fish']for sub_category in sub_categories:sub_category_dishes = season_data[season_data['Sub-Category'] == sub_category]menu.extend(sub_category_dishes.sample(min(1, len(sub_category_dishes))).to_dict('records'))menu = menu[:meals_needed]32 unmodified lineslunch_menu = lunch_menu[["Name", "Weekday"]]dinner_menu = dinner_menu[["Name", "Weekday"]]return lunch_menu, dinner_menu, total_cost# Function to calculate BMI and recommend dietdef bmi_insights(weight, height_cm):1 unmodified linebmi = 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. 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, including fruits, vegetables, whole grains, and lean proteins."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. Consider reducing sugar intake."else: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")# Add food image at the top right of the appimage = Image.open("food_image.jpg") # Ensure you have an image in the same folder14 unmodified lines# Main menu generation sectionseason = 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)# Generate Menu when button is clickedif st.button("Generate Menu"):lunch_menu, dinner_menu, total_cost = generate_menu(data, season, dietary_restriction, outings)st.header("Weekly Menu")st.subheader("Lunch Menu")4 unmodified linesst.subheader(f"Total Expenditure for the Week: PKR {total_cost}")# Save menu to Excelwith pd.ExcelWriter("weekly_menu_split.xlsx") as writer:lunch_menu.to_excel(writer, sheet_name="Lunch", index=False)
app.py+20-88