Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from transformers import pipeline | |
| # Set page configuration | |
| st.set_page_config(page_title="ReceiptBanao", layout="wide", page_icon="🍴") | |
| # Custom CSS for styling | |
| st.markdown( | |
| """ | |
| <style> | |
| .main { background-color: #DEEFF5; } | |
| .css-18e3th9 { padding: 1rem; } | |
| header { font-size: 2em; color: black; text-align: center; padding-top: 20px; } | |
| .sidebar .sidebar-content { background-color: #2e7d32; color: black; } | |
| .reportview-container .main footer { visibility: hidden; } | |
| </style> | |
| """, unsafe_allow_html=True | |
| ) | |
| # App title banner | |
| st.markdown('<header>🍴 ReceiptBanao 🍴</header>', unsafe_allow_html=True) | |
| # Sidebar setup | |
| st.sidebar.title("Ingredients Input") | |
| st.sidebar.markdown("### Select your available ingredients:") | |
| # Multi-selection box for ingredients | |
| ingredient_options = ["Tomato", "Onion", "Garlic", "Chicken", "Beef", "Tofu", "Carrot", "Pepper", "Rice", "Pasta", "Cheese", "Milk", "Eggs"] | |
| selected_ingredients = st.sidebar.multiselect("Select ingredients:", ingredient_options) | |
| # Dropdowns for dietary preferences and allergy filters | |
| diet = st.sidebar.selectbox("Dietary Preference:", ["None", "Vegan", "Vegetarian", "Keto", "Gluten-Free"]) | |
| allergies = st.sidebar.multiselect("Select Allergies:", ["None", "Nuts", "Dairy", "Shellfish", "Gluten", "Soy"]) | |
| # Dropdown for cuisine type | |
| cuisine = st.sidebar.selectbox("Choose Cuisine Type:", ["Any", "Italian", "Japanese", "Indian", "Mexican", "Ethiopian"]) | |
| # Meal planning feature | |
| meal_plan_days = st.sidebar.slider("Select number of days for meal planning:", 1, 7, 3) | |
| # Footer | |
| st.markdown('<footer style="text-align: center; color: black; padding-top: 20px;">Made with ❤️ by ReceiptBanao Team</footer>', unsafe_allow_html=True) | |
| # Hugging Face model pipeline setup for recipe generation | |
| def load_model(): | |
| return pipeline("text-generation", model="gpt2") | |
| recipe_generator = load_model() | |
| def generate_recipe(ingredients, diet, allergies, cuisine): | |
| prompt = f"Ingredients: {', '.join(ingredients)}, Dietary Preference: {diet}, Allergies: {allergies}, Cuisine: {cuisine}" | |
| generated = recipe_generator(prompt, max_length=200, num_return_sequences=1) | |
| recipe = generated[0]["generated_text"] | |
| return recipe | |
| if st.button("Generate Recipe"): | |
| if selected_ingredients: # Ensure ingredients are selected | |
| with st.spinner("Generating your recipe..."): | |
| recipe = generate_recipe(selected_ingredients, diet, allergies, cuisine) | |
| st.subheader("Your Generated Recipe:") | |
| st.write(recipe) | |
| else: | |
| st.warning("Please select at least one ingredient.") | |
| # Meal Planning Section | |
| st.subheader("Meal Planning") | |
| if meal_plan_days > 0: | |
| if selected_ingredients: # Ensure ingredients are selected before generating meal plan | |
| st.write(f"Here's your meal plan for the next {meal_plan_days} days:") | |
| for day in range(meal_plan_days): | |
| st.write(f"**Day {day + 1}**") | |
| day_recipe = generate_recipe(selected_ingredients, diet, allergies, cuisine) | |
| st.write(day_recipe) | |
| else: | |
| st.warning("Please select at least one ingredient for meal planning.") | |
| # Nutrition Analysis Section | |
| def get_nutrition_analysis(recipe): | |
| # Placeholder function to simulate nutrition analysis | |
| return {"Calories": 250, "Protein": "15g", "Carbs": "30g", "Fats": "10g"} | |
| if st.checkbox("Show Nutrition Analysis"): | |
| st.subheader("Nutrition Analysis") | |
| if 'recipe' in locals(): # Check if recipe has been generated | |
| nutrition = get_nutrition_analysis(recipe) | |
| st.write(f"Calories: {nutrition['Calories']}") | |
| st.write(f"Protein: {nutrition['Protein']}") | |
| st.write(f"Carbs: {nutrition['Carbs']}") | |
| st.write(f"Fats: {nutrition['Fats']}") | |
| else: | |
| st.warning("Generate a recipe first to see the nutrition analysis.") | |