geethareddy commited on
Commit
882d9e9
·
verified ·
1 Parent(s): e9de30f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -103
app.py CHANGED
@@ -1,103 +1,38 @@
1
- import gradio as gr
2
-
3
- # Step 1: Greeting the user and asking if they'd like to customize food
4
- def start_conversation(user_input):
5
- # Checking if the input is a positive response
6
- if user_input.lower() in ["yes", "yeah"]:
7
- return "Great! Please select a food category:"
8
- else:
9
- return "Okay, let me know if you change your mind!"
10
-
11
- # Step 2: Show categories based on the user's interest
12
- def select_category(selected_category):
13
- categories = {
14
- "Veg": "Great! You selected Veg. Now, please select your nutrition preference.",
15
- "Non-Veg": "Great! You selected Non-Veg. Now, please select your nutrition preference.",
16
- "Vegan": "Great! You selected Vegan. Now, please select your nutrition preference.",
17
- "Pasta & Noodles": "Great! You selected Pasta & Noodles. Now, please select your nutrition preference.",
18
- "Breads & Baked Goods": "Great! You selected Breads & Baked Goods. Now, please select your nutrition preference."
19
- }
20
- return categories.get(selected_category, "Please select a valid category.")
21
-
22
-
23
- # Step 3: Show nutrition options based on the selected category
24
- def select_nutrition(selected_nutrition):
25
- nutrition_options = {
26
- "Protein Rich": "Now, please select ingredients from the list below.",
27
- "Low Carbs": "Now, please select ingredients from the list below.",
28
- "Gluten-Free": "Now, please select ingredients from the list below."
29
- }
30
- return nutrition_options.get(selected_nutrition, "Please select a valid nutrition option.")
31
-
32
-
33
- # Step 4: Show ingredients based on the category and nutrition selection
34
- def show_ingredients(selected_category, selected_nutrition):
35
- # Ingredients based on category and nutrition preference
36
- ingredients = {
37
- "Veg": ["Paneer", "Potato", "Cabbage", "Gobi"],
38
- "Non-Veg": ["Chicken", "Fish", "Mutton"],
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)