Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -64,7 +64,7 @@ def process_message(message, history):
|
|
64 |
if chat_state.step == "initial":
|
65 |
if "yes" in message.lower() or "yeah" in message.lower():
|
66 |
chat_state.step = "category"
|
67 |
-
return "Great! Please select your preferred category: Vegetarian
|
68 |
return "I'm here to help you customize your food. Would you like to proceed? (Yes/No)"
|
69 |
|
70 |
elif chat_state.step == "category":
|
@@ -72,10 +72,10 @@ def process_message(message, history):
|
|
72 |
chat_state.step = "ingredient"
|
73 |
|
74 |
if "vegetarian" in message.lower():
|
75 |
-
return f"Great! What main ingredient would you like? Available options: {', '.join(VEG_INGREDIENTS)}"
|
76 |
elif "non-vegetarian" in message.lower():
|
77 |
-
return f"Great! What type of meat would you prefer? Available options: {', '.join(NONVEG_TYPES)}"
|
78 |
-
return "Please select either Vegetarian
|
79 |
|
80 |
elif chat_state.step == "ingredient":
|
81 |
chat_state.ingredient = message.lower()
|
@@ -83,9 +83,9 @@ def process_message(message, history):
|
|
83 |
|
84 |
# Check if category is vegetarian or non-vegetarian
|
85 |
if "veg" in chat_state.category:
|
86 |
-
return f"Perfect! Now, select your nutrition preference: {', '.join(NUTRITION_OPTIONS)}"
|
87 |
elif "nonveg" in chat_state.category:
|
88 |
-
return f"Perfect! Now, select your nutrition preference: {', '.join(NUTRITION_OPTIONS)}"
|
89 |
return "I'm not sure how to help with that. Would you like to start over?"
|
90 |
|
91 |
elif chat_state.step == "nutrition":
|
@@ -99,10 +99,10 @@ def process_message(message, history):
|
|
99 |
for item in food_items:
|
100 |
response += f"\n• {item['name']} ({item['calories']} cal, {item['protein']}g protein)\n {item['description']}"
|
101 |
chat_state.step = "initial" # Reset for new conversation
|
102 |
-
return response
|
103 |
except KeyError:
|
104 |
chat_state.step = "initial" # Reset for new conversation
|
105 |
-
return f"Sorry, I don't have any dishes for this combination."
|
106 |
|
107 |
return "I'm not sure how to help with that. Would you like to start over?"
|
108 |
|
@@ -112,32 +112,22 @@ def create_gradio_interface():
|
|
112 |
msg = gr.Textbox(show_label=False, placeholder="Enter text and press enter")
|
113 |
clear = gr.Button("Clear")
|
114 |
|
115 |
-
# Buttons for category selection
|
116 |
-
veg_button = gr.Button("Vegetarian")
|
117 |
-
nonveg_button = gr.Button("Non-Vegetarian")
|
118 |
-
|
119 |
def user(user_message, history):
|
120 |
return "", history + [[user_message, None]]
|
121 |
|
122 |
def bot(history):
|
123 |
user_message = history[-1][0]
|
124 |
-
bot_message = process_message(user_message, history)
|
125 |
history[-1][1] = bot_message
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
return history
|
127 |
|
128 |
-
# Function for category selection buttons
|
129 |
-
def select_category(category):
|
130 |
-
chat_state.step = "category"
|
131 |
-
chat_state.category = category.lower()
|
132 |
-
if "veg" in category.lower():
|
133 |
-
return f"Great! What main ingredient would you like? Available options: {', '.join(VEG_INGREDIENTS)}"
|
134 |
-
elif "non-vegetarian" in category.lower():
|
135 |
-
return f"Great! What type of meat would you prefer? Available options: {', '.join(NONVEG_TYPES)}"
|
136 |
-
|
137 |
-
# Wire buttons to category selection
|
138 |
-
veg_button.click(select_category, inputs=[veg_button], outputs=[chatbot])
|
139 |
-
nonveg_button.click(select_category, inputs=[nonveg_button], outputs=[chatbot])
|
140 |
-
|
141 |
msg.submit(user, [msg, chatbot], [msg, chatbot]).then(bot, chatbot, chatbot)
|
142 |
clear.click(lambda: None, None, chatbot)
|
143 |
|
|
|
64 |
if chat_state.step == "initial":
|
65 |
if "yes" in message.lower() or "yeah" in message.lower():
|
66 |
chat_state.step = "category"
|
67 |
+
return "Great! Please select your preferred category: Vegetarian or Non-Vegetarian.", ["Vegetarian", "Non-Vegetarian"]
|
68 |
return "I'm here to help you customize your food. Would you like to proceed? (Yes/No)"
|
69 |
|
70 |
elif chat_state.step == "category":
|
|
|
72 |
chat_state.step = "ingredient"
|
73 |
|
74 |
if "vegetarian" in message.lower():
|
75 |
+
return f"Great! What main ingredient would you like? Available options: {', '.join(VEG_INGREDIENTS)}", []
|
76 |
elif "non-vegetarian" in message.lower():
|
77 |
+
return f"Great! What type of meat would you prefer? Available options: {', '.join(NONVEG_TYPES)}", []
|
78 |
+
return "Please select either Vegetarian or Non-Vegetarian."
|
79 |
|
80 |
elif chat_state.step == "ingredient":
|
81 |
chat_state.ingredient = message.lower()
|
|
|
83 |
|
84 |
# Check if category is vegetarian or non-vegetarian
|
85 |
if "veg" in chat_state.category:
|
86 |
+
return f"Perfect! Now, select your nutrition preference: {', '.join(NUTRITION_OPTIONS)}", []
|
87 |
elif "nonveg" in chat_state.category:
|
88 |
+
return f"Perfect! Now, select your nutrition preference: {', '.join(NUTRITION_OPTIONS)}", []
|
89 |
return "I'm not sure how to help with that. Would you like to start over?"
|
90 |
|
91 |
elif chat_state.step == "nutrition":
|
|
|
99 |
for item in food_items:
|
100 |
response += f"\n• {item['name']} ({item['calories']} cal, {item['protein']}g protein)\n {item['description']}"
|
101 |
chat_state.step = "initial" # Reset for new conversation
|
102 |
+
return response, []
|
103 |
except KeyError:
|
104 |
chat_state.step = "initial" # Reset for new conversation
|
105 |
+
return f"Sorry, I don't have any dishes for this combination.", []
|
106 |
|
107 |
return "I'm not sure how to help with that. Would you like to start over?"
|
108 |
|
|
|
112 |
msg = gr.Textbox(show_label=False, placeholder="Enter text and press enter")
|
113 |
clear = gr.Button("Clear")
|
114 |
|
115 |
+
# Buttons for category selection will appear in the chat stream
|
|
|
|
|
|
|
116 |
def user(user_message, history):
|
117 |
return "", history + [[user_message, None]]
|
118 |
|
119 |
def bot(history):
|
120 |
user_message = history[-1][0]
|
121 |
+
bot_message, buttons = process_message(user_message, history)
|
122 |
history[-1][1] = bot_message
|
123 |
+
|
124 |
+
# Display buttons for category selection after the initial message
|
125 |
+
if buttons:
|
126 |
+
button_elements = [gr.Button(button) for button in buttons]
|
127 |
+
return history + [[bot_message, button_elements]]
|
128 |
+
|
129 |
return history
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
msg.submit(user, [msg, chatbot], [msg, chatbot]).then(bot, chatbot, chatbot)
|
132 |
clear.click(lambda: None, None, chatbot)
|
133 |
|