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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -23
app.py CHANGED
@@ -87,7 +87,7 @@ def process_message(message, history):
87
  # Step 3: Ingredient selection
88
  elif chat_state.step == "ingredient":
89
  chat_state.ingredient = message.lower().strip() # Ensure no extra spaces or case issues
90
- # Get the list of available food items for this ingredient
91
  category = "nonveg" if "non" in chat_state.category else "veg"
92
 
93
  # Check if the ingredient exists in the food database
@@ -105,7 +105,6 @@ def process_message(message, history):
105
 
106
  # Step 4: Nutrition preference
107
  elif chat_state.step == "nutrition":
108
- # Sanitize and normalize input (remove spaces, handle case)
109
  nutrition = message.lower().replace(" ", "").strip() # Remove spaces and make lowercase
110
  chat_state.nutrition = nutrition
111
  category = "nonveg" if "non" in chat_state.category else "veg"
@@ -113,7 +112,6 @@ def process_message(message, history):
113
 
114
  # Try to fetch the food items from the correct category, ingredient, and nutrition preference
115
  try:
116
- # Access food items based on category, ingredient, and nutrition preference
117
  food_items = FOOD_DATABASE[category][ingredient][nutrition]
118
  if not food_items:
119
  return f"Sorry, no {nutrition.replace('_', ' ').title()} dishes are available for {ingredient}."
@@ -133,15 +131,6 @@ def process_message(message, history):
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,17 +146,6 @@ def create_gradio_interface():
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
-
171
  msg.submit(user, [msg, chatbot], [msg, chatbot]).then(bot, chatbot, chatbot)
172
  clear.click(lambda: None, None, chatbot)
173
 
 
87
  # Step 3: Ingredient selection
88
  elif chat_state.step == "ingredient":
89
  chat_state.ingredient = message.lower().strip() # Ensure no extra spaces or case issues
90
+ # Determine if the ingredient belongs to Veg or Non-Veg category
91
  category = "nonveg" if "non" in chat_state.category else "veg"
92
 
93
  # Check if the ingredient exists in the food database
 
105
 
106
  # Step 4: Nutrition preference
107
  elif chat_state.step == "nutrition":
 
108
  nutrition = message.lower().replace(" ", "").strip() # Remove spaces and make lowercase
109
  chat_state.nutrition = nutrition
110
  category = "nonveg" if "non" in chat_state.category else "veg"
 
112
 
113
  # Try to fetch the food items from the correct category, ingredient, and nutrition preference
114
  try:
 
115
  food_items = FOOD_DATABASE[category][ingredient][nutrition]
116
  if not food_items:
117
  return f"Sorry, no {nutrition.replace('_', ' ').title()} dishes are available for {ingredient}."
 
131
  # Gradio interface for the chatbot
132
  def create_gradio_interface():
133
  with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
134
  chatbot = gr.Chatbot([])
135
  msg = gr.Textbox(show_label=False, placeholder="Enter text and press enter")
136
  clear = gr.Button("Clear")
 
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