import requests import streamlit as st @st.cache def generate_meal_plan(time_frame, target_calories, diet, exclude): API_KEY = '14ad5613468b4bae8ff6175ecc697660' url = f"https://api.spoonacular.com/mealplanner/generate?timeFrame={time_frame}&targetCalories={target_calories}&diet={diet}&exclude={exclude}&apiKey={API_KEY}" response = requests.get(url) return response.json() def display_recipe(recipe): st.write("Title: ", recipe["title"]) st.write("Ready in minutes: ", recipe["readyInMinutes"]) st.write("Servings: ", recipe["servings"]) image_url = f"https://spoonacular.com/recipeImages/{recipe['id']}-312x231.{recipe['imageType']}" st.image(image_url, width=312) st.write("Source: ", recipe["sourceUrl"]) def main(): st.title("Meal Plan Generator") time_frame = st.selectbox("Select time frame", ["day", "week"]) target_calories = st.number_input("Enter target calories per day", value=2000) diet = st.selectbox("Select diet", ["", "Gluten Free", "Ketogenic", "Vegetarian", "Lacto-Vegetarian", "Ovo-Vegetarian", "Vegan", "Pescetarian", "Paleo", "Primal", "Low FODMAP", "Whole30"]) exclude = st.text_input("Enter ingredients to exclude (comma separated)") meal_plan = generate_meal_plan(time_frame, target_calories, diet, exclude) st.write("Meal Plan:") for meal in meal_plan["meals"]: display_recipe(meal) st.write("") st.write("Total Nutrients:") st.write("Calories: ", meal_plan["nutrients"]["calories"]) st.write("Protein: ", meal_plan["nutrients"]["protein"]) st.write("Fat: ", meal_plan["nutrients"]["fat"]) st.write("Carbohydrates: ", meal_plan["nutrients"]["carbohydrates"]) if __name__ == "__main__": main()