Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -133,19 +133,29 @@ def process_message(message, history):
|
|
| 133 |
# Gradio interface for the chatbot
|
| 134 |
def create_gradio_interface():
|
| 135 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
| 136 |
chatbot = gr.Chatbot([])
|
| 137 |
msg = gr.Textbox(show_label=False, placeholder="Enter text and press enter")
|
| 138 |
clear = gr.Button("Clear")
|
| 139 |
|
|
|
|
| 140 |
def user(user_message, history):
|
| 141 |
return "", history + [[user_message, None]]
|
| 142 |
|
|
|
|
| 143 |
def bot(history):
|
| 144 |
user_message = history[-1][0]
|
| 145 |
bot_message = process_message(user_message, history)
|
| 146 |
history[-1][1] = bot_message
|
| 147 |
return history
|
| 148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
msg.submit(user, [msg, chatbot], [msg, chatbot]).then(bot, chatbot, chatbot)
|
| 150 |
clear.click(lambda: None, None, chatbot)
|
| 151 |
|
|
|
|
| 133 |
# Gradio interface for the chatbot
|
| 134 |
def create_gradio_interface():
|
| 135 |
with gr.Blocks() as demo:
|
| 136 |
+
category_btns = gr.Radio(choices=["Vegetarian", "Non-Vegetarian"], label="Select Category", type="value")
|
| 137 |
+
ingredient_btns = gr.Radio(choices=VEG_INGREDIENTS + NONVEG_TYPES, label="Select Ingredient", type="value")
|
| 138 |
+
nutrition_btns = gr.Radio(choices=NUTRITION_OPTIONS, label="Select Nutrition", type="value")
|
| 139 |
chatbot = gr.Chatbot([])
|
| 140 |
msg = gr.Textbox(show_label=False, placeholder="Enter text and press enter")
|
| 141 |
clear = gr.Button("Clear")
|
| 142 |
|
| 143 |
+
# Function for user message input and history handling
|
| 144 |
def user(user_message, history):
|
| 145 |
return "", history + [[user_message, None]]
|
| 146 |
|
| 147 |
+
# Function to handle bot's response
|
| 148 |
def bot(history):
|
| 149 |
user_message = history[-1][0]
|
| 150 |
bot_message = process_message(user_message, history)
|
| 151 |
history[-1][1] = bot_message
|
| 152 |
return history
|
| 153 |
|
| 154 |
+
# Handle category selection and pass to the next steps
|
| 155 |
+
category_btns.change(lambda category: process_message(category, []), category_btns, chatbot)
|
| 156 |
+
ingredient_btns.change(lambda ingredient: process_message(ingredient, []), ingredient_btns, chatbot)
|
| 157 |
+
nutrition_btns.change(lambda nutrition: process_message(nutrition, []), nutrition_btns, chatbot)
|
| 158 |
+
|
| 159 |
msg.submit(user, [msg, chatbot], [msg, chatbot]).then(bot, chatbot, chatbot)
|
| 160 |
clear.click(lambda: None, None, chatbot)
|
| 161 |
|