Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,10 +22,11 @@ st.markdown('<header>🍴 ReceiptBanao 🍴</header>', unsafe_allow_html=True)
|
|
| 22 |
|
| 23 |
# Sidebar setup
|
| 24 |
st.sidebar.title("Ingredients Input")
|
| 25 |
-
st.sidebar.markdown("###
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
# Dropdowns for dietary preferences and allergy filters
|
| 31 |
diet = st.sidebar.selectbox("Dietary Preference:", ["None", "Vegan", "Vegetarian", "Keto", "Gluten-Free"])
|
|
@@ -48,29 +49,32 @@ def load_model():
|
|
| 48 |
recipe_generator = load_model()
|
| 49 |
|
| 50 |
def generate_recipe(ingredients, diet, allergies, cuisine):
|
| 51 |
-
prompt = f"Ingredients: {ingredients}, Dietary Preference: {diet}, Allergies: {allergies}, Cuisine: {cuisine}"
|
| 52 |
generated = recipe_generator(prompt, max_length=200, num_return_sequences=1)
|
| 53 |
recipe = generated[0]["generated_text"]
|
| 54 |
return recipe
|
| 55 |
|
| 56 |
if st.button("Generate Recipe"):
|
| 57 |
-
if
|
| 58 |
with st.spinner("Generating your recipe..."):
|
| 59 |
-
recipe = generate_recipe(
|
| 60 |
st.subheader("Your Generated Recipe:")
|
| 61 |
st.write(recipe)
|
| 62 |
else:
|
| 63 |
-
st.warning("Please
|
| 64 |
|
| 65 |
# Meal Planning Section
|
| 66 |
st.subheader("Meal Planning")
|
| 67 |
|
| 68 |
-
if meal_plan_days:
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
# Nutrition Analysis Section
|
| 76 |
def get_nutrition_analysis(recipe):
|
|
@@ -79,8 +83,11 @@ def get_nutrition_analysis(recipe):
|
|
| 79 |
|
| 80 |
if st.checkbox("Show Nutrition Analysis"):
|
| 81 |
st.subheader("Nutrition Analysis")
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Sidebar setup
|
| 24 |
st.sidebar.title("Ingredients Input")
|
| 25 |
+
st.sidebar.markdown("### Select your available ingredients:")
|
| 26 |
|
| 27 |
+
# Multi-selection box for ingredients
|
| 28 |
+
ingredient_options = ["Tomato", "Onion", "Garlic", "Chicken", "Beef", "Tofu", "Carrot", "Pepper", "Rice", "Pasta", "Cheese", "Milk", "Eggs"]
|
| 29 |
+
selected_ingredients = st.sidebar.multiselect("Select ingredients:", ingredient_options)
|
| 30 |
|
| 31 |
# Dropdowns for dietary preferences and allergy filters
|
| 32 |
diet = st.sidebar.selectbox("Dietary Preference:", ["None", "Vegan", "Vegetarian", "Keto", "Gluten-Free"])
|
|
|
|
| 49 |
recipe_generator = load_model()
|
| 50 |
|
| 51 |
def generate_recipe(ingredients, diet, allergies, cuisine):
|
| 52 |
+
prompt = f"Ingredients: {', '.join(ingredients)}, Dietary Preference: {diet}, Allergies: {allergies}, Cuisine: {cuisine}"
|
| 53 |
generated = recipe_generator(prompt, max_length=200, num_return_sequences=1)
|
| 54 |
recipe = generated[0]["generated_text"]
|
| 55 |
return recipe
|
| 56 |
|
| 57 |
if st.button("Generate Recipe"):
|
| 58 |
+
if selected_ingredients: # Ensure ingredients are selected
|
| 59 |
with st.spinner("Generating your recipe..."):
|
| 60 |
+
recipe = generate_recipe(selected_ingredients, diet, allergies, cuisine)
|
| 61 |
st.subheader("Your Generated Recipe:")
|
| 62 |
st.write(recipe)
|
| 63 |
else:
|
| 64 |
+
st.warning("Please select at least one ingredient.")
|
| 65 |
|
| 66 |
# Meal Planning Section
|
| 67 |
st.subheader("Meal Planning")
|
| 68 |
|
| 69 |
+
if meal_plan_days > 0:
|
| 70 |
+
if selected_ingredients: # Ensure ingredients are selected before generating meal plan
|
| 71 |
+
st.write(f"Here's your meal plan for the next {meal_plan_days} days:")
|
| 72 |
+
for day in range(meal_plan_days):
|
| 73 |
+
st.write(f"**Day {day + 1}**")
|
| 74 |
+
day_recipe = generate_recipe(selected_ingredients, diet, allergies, cuisine)
|
| 75 |
+
st.write(day_recipe)
|
| 76 |
+
else:
|
| 77 |
+
st.warning("Please select at least one ingredient for meal planning.")
|
| 78 |
|
| 79 |
# Nutrition Analysis Section
|
| 80 |
def get_nutrition_analysis(recipe):
|
|
|
|
| 83 |
|
| 84 |
if st.checkbox("Show Nutrition Analysis"):
|
| 85 |
st.subheader("Nutrition Analysis")
|
| 86 |
+
if 'recipe' in locals(): # Check if recipe has been generated
|
| 87 |
+
nutrition = get_nutrition_analysis(recipe)
|
| 88 |
+
st.write(f"Calories: {nutrition['Calories']}")
|
| 89 |
+
st.write(f"Protein: {nutrition['Protein']}")
|
| 90 |
+
st.write(f"Carbs: {nutrition['Carbs']}")
|
| 91 |
+
st.write(f"Fats: {nutrition['Fats']}")
|
| 92 |
+
else:
|
| 93 |
+
st.warning("Generate a recipe first to see the nutrition analysis.")
|