Rammohan0504 commited on
Commit
276cc84
·
verified ·
1 Parent(s): 67c46de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -21
app.py CHANGED
@@ -93,6 +93,30 @@ extras = [
93
  {"name": "Extra Onion & Lemon", "price": "$2.00"}
94
  ]
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  # JavaScript for popup modal
97
  popup_js = """
98
  <script>
@@ -147,9 +171,9 @@ popup_html = """
147
  </div>
148
  """
149
 
150
- # Generate dish cards
151
  def display_dishes(category):
152
- html_content = "<div style='display: flex; flex-wrap: wrap; gap: 20px; width: 80%; margin: 0 auto;'>"
 
153
  for dish in menu_data:
154
  if category == "ALL" or dish["category"] == category:
155
  html_content += f"""
@@ -160,10 +184,9 @@ def display_dishes(category):
160
  <h3 style='margin: 10px 0; font-size: 18px;'>{dish['name']}</h3>
161
  <p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p>
162
  <p style='margin: 10px 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p>
163
- <button onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}')"
164
- style='padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;'>
165
- Add
166
- </button>
167
  </div>
168
  """
169
  html_content += "</div>"
@@ -173,12 +196,10 @@ def display_dishes(category):
173
 
174
  # Main Gradio App
175
  with gr.Blocks() as demo:
176
- gr.HTML(popup_html) # Add the popup container and overlay
177
- gr.HTML(popup_js) # Add the JavaScript
178
-
179
- gr.HTML("<h1 style='text-align: center;'>🍛 Biryani Hub Menu 🍛</h1>")
180
 
181
  with gr.Tabs():
 
182
  with gr.Tab("Menu"):
183
  with gr.Row():
184
  btn_all = gr.Button("ALL")
@@ -188,22 +209,24 @@ with gr.Blocks() as demo:
188
  dish_display = gr.HTML(value=display_dishes("ALL"))
189
 
190
  btn_all.click(
191
- lambda: display_dishes("ALL"),
192
- outputs=dish_display
193
- )
194
  btn_vegan.click(
195
- lambda: display_dishes("VEGAN"),
196
- outputs=dish_display
197
- )
198
  btn_halal.click(
199
- lambda: display_dishes("HALAL"),
200
- outputs=dish_display
201
- )
202
 
 
203
  with gr.Tab("Cart"):
204
  cart_display = gr.HTML(value=display_cart())
205
- gr.Button("Refresh Cart").click(
206
- lambda: gr.update(value=display_cart()),
 
207
  outputs=cart_display
208
  )
209
 
 
93
  {"name": "Extra Onion & Lemon", "price": "$2.00"}
94
  ]
95
 
96
+
97
+
98
+ # Global cart variable
99
+ cart = []
100
+
101
+
102
+ def add_to_cart(item_name, spice_level=None, extras=None):
103
+ """Add selected item to cart."""
104
+ cart.append({"item_name": item_name, "spice_level": spice_level, "extras": extras or []})
105
+ return f"{item_name} added to cart!"
106
+
107
+
108
+ def display_cart():
109
+ """Return the current cart contents."""
110
+ if not cart:
111
+ return "Your cart is empty."
112
+ cart_content = "<h3>Your Cart:</h3><ul>"
113
+ for item in cart:
114
+ extras = ', '.join(item['extras']) if item['extras'] else "No extras"
115
+ cart_content += f"<li>{item['item_name']} - Spice: {item['spice_level'] or 'Default'} - Extras: {extras}</li>"
116
+ cart_content += "</ul>"
117
+ return cart_content
118
+
119
+
120
  # JavaScript for popup modal
121
  popup_js = """
122
  <script>
 
171
  </div>
172
  """
173
 
 
174
  def display_dishes(category):
175
+ """Render dishes dynamically based on the selected category."""
176
+ html_content = "<div style='display: flex; flex-wrap: wrap; gap: 20px; justify-content: center;'>"
177
  for dish in menu_data:
178
  if category == "ALL" or dish["category"] == category:
179
  html_content += f"""
 
184
  <h3 style='margin: 10px 0; font-size: 18px;'>{dish['name']}</h3>
185
  <p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p>
186
  <p style='margin: 10px 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p>
187
+ <button style='padding: 10px 20px; background-color: #28a745; color: white; border: none;
188
+ border-radius: 5px; cursor: pointer;'
189
+ onclick="addToCart('{dish['name']}')">Add to Cart</button>
 
190
  </div>
191
  """
192
  html_content += "</div>"
 
196
 
197
  # Main Gradio App
198
  with gr.Blocks() as demo:
199
+ gr.HTML("<h1 style='text-align: center;'>🍛 Welcome to the Biryani Hub 🍛</h1>")
 
 
 
200
 
201
  with gr.Tabs():
202
+ # Menu Tab
203
  with gr.Tab("Menu"):
204
  with gr.Row():
205
  btn_all = gr.Button("ALL")
 
209
  dish_display = gr.HTML(value=display_dishes("ALL"))
210
 
211
  btn_all.click(
212
+ lambda: display_dishes("ALL"),
213
+ outputs=dish_display
214
+ )
215
  btn_vegan.click(
216
+ lambda: display_dishes("VEGAN"),
217
+ outputs=dish_display
218
+ )
219
  btn_halal.click(
220
+ lambda: display_dishes("HALAL"),
221
+ outputs=dish_display
222
+ )
223
 
224
+ # Cart Tab
225
  with gr.Tab("Cart"):
226
  cart_display = gr.HTML(value=display_cart())
227
+ refresh_cart_btn = gr.Button("Refresh Cart")
228
+ refresh_cart_btn.click(
229
+ lambda: display_cart(),
230
  outputs=cart_display
231
  )
232