import streamlit as st import random # Sample dataset for dish suggestions and recipes recipe_data = { "Spaghetti Carbonara": { "ingredients": ["spaghetti", "eggs", "cheese", "pancetta", "garlic", "black pepper"], "recipe": "1. Cook spaghetti. 2. Mix eggs and cheese. 3. Fry pancetta and garlic. 4. Combine all and season with pepper." }, "Chicken Salad": { "ingredients": ["chicken", "lettuce", "tomato", "cucumber", "olive oil", "lemon"], "recipe": "1. Grill the chicken. 2. Prepare the salad with lettuce, tomato, and cucumber. 3. Dress with olive oil and lemon." }, "Beef Stew": { "ingredients": ["beef", "carrots", "potatoes", "onion", "garlic", "beef broth"], "recipe": "1. Brown the beef. 2. Add carrots, potatoes, and onion. 3. Pour in beef broth and simmer until tender." }, "Vegetable Stir Fry": { "ingredients": ["carrot", "broccoli", "bell pepper", "soy sauce", "ginger", "garlic"], "recipe": "1. Stir-fry the vegetables in oil. 2. Add soy sauce and ginger. 3. Cook until tender." }, "Pasta Salad": { "ingredients": ["pasta", "tomato", "cucumber", "olive oil", "balsamic vinegar"], "recipe": "1. Cook pasta. 2. Chop vegetables. 3. Mix all ingredients and season with olive oil and balsamic vinegar." }, # Add more recipes as needed } # Function to suggest dishes based on ingredients def suggest_dishes(ingredients): suggested_dishes = [] for dish, details in recipe_data.items(): # Check if the dish contains at least one of the entered ingredients if any(ingredient in ingredients for ingredient in details['ingredients']): suggested_dishes.append(dish) # Randomly suggest 3 dishes from the possible matches (if there are enough) return random.sample(suggested_dishes, 3) if len(suggested_dishes) >= 3 else suggested_dishes # BMI calculation function def calculate_bmi(weight, height): bmi = weight / (height ** 2) return bmi # Function to categorize BMI and generate diet plan def get_bmi_category(bmi): if bmi < 18.5: return "Underweight" elif 18.5 <= bmi < 24.9: return "Normal weight" elif 25 <= bmi < 29.9: return "Overweight" else: return "Obese" # Weekly diet plans for different BMI categories diet_plans = { "Underweight": { "Breakfast": [ {"dish": "Avocado Toast", "calories": 400}, {"dish": "Peanut Butter Smoothie", "calories": 350}, {"dish": "Oatmeal with Almonds", "calories": 300} ], "Lunch": [ {"dish": "Grilled Chicken Salad", "calories": 500}, {"dish": "Pasta with Pesto", "calories": 600}, {"dish": "Quinoa and Black Beans", "calories": 450} ], "Dinner": [ {"dish": "Salmon with Sweet Potatoes", "calories": 600}, {"dish": "Chicken Stir Fry with Veggies", "calories": 550}, {"dish": "Beef Tacos", "calories": 650} ] }, "Normal weight": { "Breakfast": [ {"dish": "Scrambled Eggs with Spinach", "calories": 350}, {"dish": "Greek Yogurt with Berries", "calories": 250}, {"dish": "Whole Wheat Toast with Avocado", "calories": 300} ], "Lunch": [ {"dish": "Chicken Caesar Salad", "calories": 500}, {"dish": "Veggie Wrap", "calories": 400}, {"dish": "Grilled Fish Tacos", "calories": 550} ], "Dinner": [ {"dish": "Grilled Chicken with Rice", "calories": 600}, {"dish": "Vegetable Stir Fry", "calories": 450}, {"dish": "Spaghetti with Marinara", "calories": 550} ] }, "Overweight": { "Breakfast": [ {"dish": "Greek Yogurt with Granola", "calories": 250}, {"dish": "Scrambled Egg Whites with Veggies", "calories": 200}, {"dish": "Smoothie with Kale and Berries", "calories": 220} ], "Lunch": [ {"dish": "Chicken Salad with Low-Cal Dressing", "calories": 400}, {"dish": "Grilled Chicken and Vegetables", "calories": 350}, {"dish": "Tofu Stir Fry", "calories": 300} ], "Dinner": [ {"dish": "Baked Salmon with Veggies", "calories": 450}, {"dish": "Turkey Meatballs with Zucchini Noodles", "calories": 500}, {"dish": "Grilled Shrimp with Quinoa", "calories": 400} ] }, "Obese": { "Breakfast": [ {"dish": "Omelette with Veggies", "calories": 250}, {"dish": "Cottage Cheese with Berries", "calories": 200}, {"dish": "Chia Seed Pudding", "calories": 150} ], "Lunch": [ {"dish": "Chicken and Veggie Soup", "calories": 350}, {"dish": "Salmon Salad with Olive Oil", "calories": 400}, {"dish": "Grilled Tofu with Broccoli", "calories": 350} ], "Dinner": [ {"dish": "Baked Chicken Breast with Asparagus", "calories": 450}, {"dish": "Steamed Fish with Veggies", "calories": 400}, {"dish": "Roasted Cauliflower with Lentils", "calories": 350} ] } } # Function to generate weekly diet plan def generate_weekly_diet(bmi_category): diet = diet_plans.get(bmi_category) if not diet: return None weekly_diet = {"Breakfast": [], "Lunch": [], "Dinner": []} for meal_time, meals in diet.items(): # If there are fewer than 7 meals, repeat them to fill the week num_meals = len(meals) if num_meals < 7: # Repeat meals to ensure there are 7 meals (one for each day of the week) weekly_diet[meal_time] = (meals * (7 // num_meals)) + meals[:(7 % num_meals)] else: # Randomly sample 7 meals if there are enough weekly_diet[meal_time] = random.sample(meals, 7) return weekly_diet # Streamlit App Interface st.title("Select an App to Use") st.write("Choose one of the following options:") # Buttons to trigger respective apps app_choice = st.radio( "Choose App", ("Cooking Suggestion App", "BMI Calculator and Diet Plan") ) if app_choice == "Cooking Suggestion App": st.write("Enter 1 or 2 ingredients to get recipe suggestions:") ingredients_input = st.text_input("Enter ingredients (comma separated):") if st.button("Suggest Dishes"): if ingredients_input: ingredients = [ingredient.strip().lower() for ingredient in ingredients_input.split(',')] st.write("Entered Ingredients:", ingredients) if ingredients: suggested_dishes = suggest_dishes(ingredients) if suggested_dishes: st.write("Suggested Dishes:") selected_dish = st.selectbox("Choose a dish", suggested_dishes) if selected_dish: st.write(f"Recipe for {selected_dish}:") st.write(recipe_data[selected_dish]["recipe"]) else: st.write("No dishes found for the entered ingredients.") else: st.write("No valid ingredients entered.") else: st.write("Please enter some ingredients.") elif app_choice == "BMI Calculator and Diet Plan": st.write("Enter your weight and height to calculate your BMI and get a personalized weekly diet plan.") weight = st.number_input("Enter your weight (in kg):", min_value=1.0, max_value=200.0, step=0.1) height = st.number_input("Enter your height (in meters):", min_value=1.0, max_value=3.0, step=0.01) if st.button("Calculate BMI and Get Weekly Diet Plan"): if weight > 0 and height > 0: bmi = calculate_bmi(weight, height) st.write(f"Your BMI is: {bmi:.2f}") bmi_category = get_bmi_category(bmi) st.write(f"Your BMI category is: {bmi_category}") weekly_diet = generate_weekly_diet(bmi_category) if weekly_diet: st.write(f"### Your Weekly Diet Plan:") for meal_time, meals in weekly_diet.items(): st.write(f"**{meal_time}:**") for meal in meals: meal_text = f"- {meal['dish']} - {meal['calories']} Calories" st.write(meal_text) else: st.write("Sorry, we couldn't generate a diet plan for you.") else: st.write("Please enter valid weight and height.")