Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,103 +1,38 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
"
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
def
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
"Vegan": ["Tofu", "Tempeh", "Seitan"],
|
| 40 |
-
"Pasta & Noodles": ["Whole Wheat Pasta", "Rice Noodles"],
|
| 41 |
-
"Breads & Baked Goods": ["Whole Grain Bread", "Gluten-Free Bread"]
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
return f"Here are the ingredients available for {selected_category} with {selected_nutrition} option: " + ", ".join(ingredients.get(selected_category, []))
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
# Step 5: Show dishes based on the selected ingredient
|
| 48 |
-
def show_dishes(selected_ingredient):
|
| 49 |
-
dishes = {
|
| 50 |
-
"Paneer": ["Paneer Tikka", "Paneer Curry", "Paneer Manchurian", "Paneer Butter Masala"],
|
| 51 |
-
"Potato": ["Aloo Dal", "Potato and Chickpea Salad", "Paneer-Stuffed Potatoes", "Potato and Black Bean Tacos"],
|
| 52 |
-
"Cabbage": ["Cabbage and Chickpea Curry", "Cabbage Stir-Fry with Tofu", "Cabbage and Lentil Soup"],
|
| 53 |
-
"Chicken": ["Grilled Chicken Breast", "Chicken Tikka Masala", "Chicken Stir-Fry", "Chicken Biryani"],
|
| 54 |
-
"Fish": ["Grilled Salmon", "Fish Curry", "Baked Fish with Herbs", "Fish Tacos"],
|
| 55 |
-
"Mutton": ["Mutton Curry", "Mutton Biryani", "Grilled Lamb Chops", "Mutton Rogan Josh"],
|
| 56 |
-
"Tofu": ["Tofu Stir-Fry", "Crispy Tofu Nuggets", "Tofu Scramble", "Tofu Curry"],
|
| 57 |
-
"Tempeh": ["Tempeh Bacon", "BBQ Tempeh", "Tempeh Stir-Fry", "Marinated Tempeh"],
|
| 58 |
-
"Seitan": ["Seitan Steak", "Seitan Wings", "Seitan Stir-Fry", "Seitan Curry"]
|
| 59 |
-
}
|
| 60 |
-
return f"Based on your selection, here are the food items you can make: " + ", ".join(dishes.get(selected_ingredient, []))
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
# Gradio interface setup
|
| 64 |
-
def create_gradio_interface():
|
| 65 |
-
# Step-by-step interaction using Gradio components
|
| 66 |
-
with gr.Blocks() as demo:
|
| 67 |
-
gr.Markdown("# Food Customization Assistant")
|
| 68 |
-
gr.Markdown("Talk to the bot and customize your food preferences based on category.")
|
| 69 |
-
|
| 70 |
-
# Greeting Step
|
| 71 |
-
user_input = gr.Textbox(label="Your Message", placeholder="Type 'yes' or 'yeah' to begin.", lines=1)
|
| 72 |
-
bot_response = gr.Textbox(label="Bot Response", lines=2)
|
| 73 |
-
|
| 74 |
-
# First interaction: Ask user if they want to customize food
|
| 75 |
-
user_input.submit(start_conversation, user_input, bot_response)
|
| 76 |
-
|
| 77 |
-
# Category Selection
|
| 78 |
-
category_dropdown = gr.Dropdown(
|
| 79 |
-
choices=["Veg", "Non-Veg", "Vegan", "Pasta & Noodles", "Breads & Baked Goods"],
|
| 80 |
-
label="Select Food Category"
|
| 81 |
-
)
|
| 82 |
-
category_dropdown.change(select_category, category_dropdown, bot_response)
|
| 83 |
-
|
| 84 |
-
# Nutrition Preferences
|
| 85 |
-
nutrition_dropdown = gr.Dropdown(
|
| 86 |
-
choices=["Protein Rich", "Low Carbs", "Gluten-Free"],
|
| 87 |
-
label="Select Nutrition Preference"
|
| 88 |
-
)
|
| 89 |
-
nutrition_dropdown.change(select_nutrition, nutrition_dropdown, bot_response)
|
| 90 |
-
|
| 91 |
-
# Show Ingredients based on category & nutrition
|
| 92 |
-
ingredients_output = gr.Textbox(label="Ingredients List", lines=2)
|
| 93 |
-
ingredients_output.change(show_ingredients, [category_dropdown, nutrition_dropdown], ingredients_output)
|
| 94 |
-
|
| 95 |
-
# Ingredient Selection
|
| 96 |
-
ingredient_dropdown = gr.Dropdown(label="Select Ingredient")
|
| 97 |
-
ingredient_dropdown.change(show_dishes, ingredient_dropdown, bot_response)
|
| 98 |
-
|
| 99 |
-
# Start Gradio Interface
|
| 100 |
-
demo.launch()
|
| 101 |
-
|
| 102 |
-
if __name__ == "__main__":
|
| 103 |
-
create_gradio_interface()
|
|
|
|
| 1 |
+
from flask import Flask, request, render_template
|
| 2 |
+
app = Flask(__name__)
|
| 3 |
+
|
| 4 |
+
# Recipe suggestions based on ingredients
|
| 5 |
+
recipes = {
|
| 6 |
+
"paneer": [
|
| 7 |
+
"Paneer Butter Masala", "Palak Paneer", "Paneer Tikka", "Paneer Bhurji", "Shahi Paneer"
|
| 8 |
+
],
|
| 9 |
+
"lettuce": [
|
| 10 |
+
"Lettuce Salad", "Lettuce Wraps", "Lettuce and Avocado Salad", "Caesar Salad"
|
| 11 |
+
],
|
| 12 |
+
"carrot": [
|
| 13 |
+
"Carrot Halwa", "Carrot Soup", "Carrot Salad", "Carrot Cake", "Pickled Carrots"
|
| 14 |
+
],
|
| 15 |
+
"broccoli": [
|
| 16 |
+
"Broccoli Stir Fry", "Broccoli Soup", "Broccoli Salad", "Steamed Broccoli"
|
| 17 |
+
],
|
| 18 |
+
"mushrooms": [
|
| 19 |
+
"Mushroom Masala", "Mushroom Soup", "Mushroom Risotto", "Stuffed Mushrooms"
|
| 20 |
+
]
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
@app.route('/')
|
| 24 |
+
def index():
|
| 25 |
+
return render_template('index.html')
|
| 26 |
+
|
| 27 |
+
@app.route('/get_recipes', methods=['POST'])
|
| 28 |
+
def get_recipes():
|
| 29 |
+
selected_ingredients = request.form.getlist('ingredients')
|
| 30 |
+
suggested_recipes = []
|
| 31 |
+
|
| 32 |
+
for ingredient in selected_ingredients:
|
| 33 |
+
suggested_recipes.extend(recipes.get(ingredient, []))
|
| 34 |
+
|
| 35 |
+
return render_template('index.html', recipes=suggested_recipes)
|
| 36 |
+
|
| 37 |
+
if __name__ == '__main__':
|
| 38 |
+
app.run(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|