Subbu1304 commited on
Commit
3145dee
·
verified ·
1 Parent(s): 45313bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -133,9 +133,15 @@ def process_message(message, history):
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")
137
- ingredient_btns = gr.Radio(choices=VEG_INGREDIENTS + NONVEG_TYPES, label="Select Ingredient")
 
 
 
 
138
  nutrition_btns = gr.Radio(choices=NUTRITION_OPTIONS, label="Select Nutrition")
 
139
  chatbot = gr.Chatbot([])
140
  msg = gr.Textbox(show_label=False, placeholder="Enter text and press enter")
141
  clear = gr.Button("Clear")
@@ -151,8 +157,14 @@ def create_gradio_interface():
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
 
 
133
  # Gradio interface for the chatbot
134
  def create_gradio_interface():
135
  with gr.Blocks() as demo:
136
+ # Category button
137
  category_btns = gr.Radio(choices=["Vegetarian", "Non-Vegetarian"], label="Select Category")
138
+
139
+ # Ingredient button
140
+ ingredient_btns = gr.Radio(choices=[], label="Select Ingredient") # Initially empty
141
+
142
+ # Nutrition button
143
  nutrition_btns = gr.Radio(choices=NUTRITION_OPTIONS, label="Select Nutrition")
144
+
145
  chatbot = gr.Chatbot([])
146
  msg = gr.Textbox(show_label=False, placeholder="Enter text and press enter")
147
  clear = gr.Button("Clear")
 
157
  history[-1][1] = bot_message
158
  return history
159
 
160
+ # Handle category selection and dynamically update ingredient choices
161
+ category_btns.change(
162
+ lambda category: ingredient_btns.update(choices=VEG_INGREDIENTS if "vegetarian" in category.lower() else NONVEG_TYPES),
163
+ category_btns,
164
+ ingredient_btns
165
+ )
166
+
167
+ # Handle ingredient selection and pass to the next steps
168
  ingredient_btns.change(lambda ingredient: process_message(ingredient, []), ingredient_btns, chatbot)
169
  nutrition_btns.change(lambda nutrition: process_message(nutrition, []), nutrition_btns, chatbot)
170