Subbu1304 commited on
Commit
ee04be4
·
verified ·
1 Parent(s): 73ddf5e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -88
app.py CHANGED
@@ -1,103 +1,42 @@
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
  import gradio as gr
2
+ import time
3
 
4
+ # Function to simulate typing and provide chatbot response
5
+ def chatbot_response(user_input, history):
6
+ bot_message = ""
7
+ response = "Here is the response from the bot based on your input: " + user_input # Replace with your AI response logic
 
 
 
8
 
9
+ # Simulate typing by adding characters one by one with a slight delay
10
+ for char in response:
11
+ bot_message += char
12
+ history.append((user_input, bot_message))
13
+ time.sleep(0.05) # Delay to simulate typing speed
14
+ yield gr.update(value=bot_message) # Yield updated message
 
 
 
 
15
 
16
+ # Gradio Interface Setup
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  def create_gradio_interface():
 
18
  with gr.Blocks() as demo:
19
  gr.Markdown("# Food Customization Assistant")
20
+ gr.Markdown("Talk to the bot and customize your food preferences.")
 
 
 
 
 
 
 
21
 
22
+ # Conversation Box
23
+ with gr.Chatbot() as chatbox:
24
+ pass
 
 
 
25
 
26
+ # User input field
27
+ user_input = gr.Textbox(placeholder="Type your message here...", lines=1)
 
 
 
 
28
 
29
+ # Submit button
30
+ submit_btn = gr.Button("Submit")
 
31
 
32
+ # Function for handling message submission
33
+ submit_btn.click(
34
+ chatbot_response,
35
+ inputs=[user_input, chatbox],
36
+ outputs=chatbox
37
+ )
38
 
39
+ demo.launch()
 
40
 
41
  if __name__ == "__main__":
42
  create_gradio_interface()