Rammohan0504 commited on
Commit
03dc2c5
·
verified ·
1 Parent(s): 8dd7713

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -31
app.py CHANGED
@@ -147,10 +147,11 @@ popup_html = """
147
  """
148
 
149
  # Generate dish cards
150
- def display_dishes(category):
151
  html_content = "<div style='display: flex; flex-direction: column; gap: 20px; padding-bottom: 20px; box-sizing: border-box;'>"
152
  for dish in menu_data:
153
- if category == "ALL":
 
154
  html_content += f"""
155
  <div style='display: flex; align-items: center; justify-content: space-between; padding: 20px; border: 1px solid #ddd; border-radius: 10px; background-color: #f9f9f9;'>
156
  <div style='flex: 3; text-align: left;'>
@@ -165,48 +166,48 @@ def display_dishes(category):
165
  Add
166
  </button>
167
  </div>
168
-
169
- elif category == dish["category"] == category:
170
- html_content += f"""
171
- <div style='display: flex; align-items: center; justify-content: space-between; padding: 20px; height:100%; border: 1px solid #ddd; border-radius: 10px; background-color: #f9f9f9;'>
172
- <div style='flex: 3; text-align: left;'>
173
- <h3 style='margin: 0; font-size: 20px;'>{dish['name']}</h3>
174
- <p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p>
175
- <p style='margin: 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p>
176
- </div>
177
- <div style='flex: 1; text-align: center;'>
178
- <img src='{dish['image']}' alt='{dish['name']}' style='width: 120px; height: 80px; object-fit: cover; border-radius: 10px;'>
179
- <button onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}')"
180
- style='margin-top: 10px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;'>
181
- Add
182
- </button>
183
- </div>
184
  </div>
185
  """
186
  html_content += "</div>"
187
  return html_content
188
 
 
189
  # Main Gradio App
190
- with gr.Blocks (css="#dish-container {min-height: 100vh; overflow-y: auto;}") as demo:
191
  gr.HTML(popup_html) # Add the popup container and overlay
192
  gr.HTML(popup_js) # Add the JavaScript
193
 
194
  gr.HTML("<h1 style='text-align: center;'>🍛 Biryani Hub Menu 🍛</h1>")
195
 
196
- category_selector = gr.Radio(
197
- ["ALL", "VEGAN", "HALAL"],
198
- label="Select Category",
199
- value="ALL"
200
- )
 
 
 
201
 
202
- # Dish display
203
- dish_display = gr.HTML(value=display_dishes("ALL"))
 
 
 
 
 
 
 
204
 
205
- # Radio button change event
206
- category_selector.change(
207
- lambda category: gr.update(value=display_dishes(category)),
208
- inputs=category_selector,
209
- outputs=dish_display
 
 
 
 
 
210
  )
211
 
212
  demo.launch()
 
147
  """
148
 
149
  # Generate dish cards
150
+ def display_dishes(category, keyword=""):
151
  html_content = "<div style='display: flex; flex-direction: column; gap: 20px; padding-bottom: 20px; box-sizing: border-box;'>"
152
  for dish in menu_data:
153
+ # Filter by category and keyword
154
+ if (category == "ALL" or dish["category"] == category) and (keyword.lower() in dish["name"].lower()):
155
  html_content += f"""
156
  <div style='display: flex; align-items: center; justify-content: space-between; padding: 20px; border: 1px solid #ddd; border-radius: 10px; background-color: #f9f9f9;'>
157
  <div style='flex: 3; text-align: left;'>
 
166
  Add
167
  </button>
168
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  </div>
170
  """
171
  html_content += "</div>"
172
  return html_content
173
 
174
+
175
  # Main Gradio App
176
+ with gr.Blocks(css="#dish-container {min-height: 100vh; overflow-y: auto;}") as demo:
177
  gr.HTML(popup_html) # Add the popup container and overlay
178
  gr.HTML(popup_js) # Add the JavaScript
179
 
180
  gr.HTML("<h1 style='text-align: center;'>🍛 Biryani Hub Menu 🍛</h1>")
181
 
182
+ # Two containers
183
+ with gr.Row():
184
+ with gr.Column():
185
+ gr.HTML("<h2 style='text-align: center;'>All Dishes</h2>")
186
+ all_dishes_display = gr.HTML(value=display_dishes("ALL"))
187
+ with gr.Column():
188
+ gr.HTML("<h2 style='text-align: center;'>Vegan and Halal Dishes</h2>")
189
+ vegan_halal_display = gr.HTML(value=display_dishes("ALL", keyword=""))
190
 
191
+ # Inputs to filter containers
192
+ keyword_input_all = gr.Textbox(
193
+ label="Search in All Dishes",
194
+ placeholder="Enter keyword to filter (e.g., Chicken)"
195
+ )
196
+ keyword_input_vegan_halal = gr.Textbox(
197
+ label="Search in Vegan and Halal",
198
+ placeholder="Enter keyword to filter (e.g., Curry)"
199
+ )
200
 
201
+ # Update containers dynamically
202
+ keyword_input_all.change(
203
+ lambda keyword: gr.update(value=display_dishes("ALL", keyword)),
204
+ inputs=keyword_input_all,
205
+ outputs=all_dishes_display
206
+ )
207
+ keyword_input_vegan_halal.change(
208
+ lambda keyword: gr.update(value=display_dishes("VEGAN", keyword) + display_dishes("HALAL", keyword)),
209
+ inputs=keyword_input_vegan_halal,
210
+ outputs=vegan_halal_display
211
  )
212
 
213
  demo.launch()