Subbu1304 commited on
Commit
33933ea
·
verified ·
1 Parent(s): ce3593c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -25
app.py CHANGED
@@ -1,33 +1,103 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # Load Hugging Face's conversational model (DialoGPT in this case)
5
- generator = pipeline("conversational", model="microsoft/DialoGPT-medium")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- # Define a function that will interact with the model
8
- def chatbot_response(user_input, chat_history):
9
- # Create response by sending the user input and previous history to the model
10
- response = generator(user_input, pad_token_id=50256)
11
- chat_history.append((user_input, response[0]['generated_text']))
12
-
13
- # Return the updated chat history for displaying the conversation
14
- return chat_history, chat_history
15
 
16
  # Gradio interface setup
17
  def create_gradio_interface():
18
- # Create a chat-based interface using Gradio
19
- interface = gr.Interface(
20
- fn=chatbot_response,
21
- inputs=[gr.Textbox(label="Ask about food customization...", placeholder="Type your message...", lines=1),
22
- gr.State()],
23
- outputs=[gr.Chatbot(), gr.State()],
24
- title="Food Customization Assistant",
25
- description="Talk to the bot and customize your food preferences. Ask about recipes, categories, or ingredients.",
26
- theme="compact" # Custom theme
27
- )
28
-
29
- return interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  if __name__ == "__main__":
32
- interface = create_gradio_interface()
33
- interface.launch()
 
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()