geethareddy commited on
Commit
299bcff
·
verified ·
1 Parent(s): c6b41d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -3
app.py CHANGED
@@ -254,8 +254,10 @@ def modal_js():
254
  """
255
  return modal_script
256
 
257
- # Gradio App
258
  with gr.Blocks() as app:
 
 
259
  with gr.Row():
260
  gr.HTML("<h1 style='text-align: center;'>Welcome to Biryani Hub</h1>")
261
 
@@ -282,15 +284,45 @@ with gr.Blocks() as app:
282
  preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
283
  menu_output = gr.HTML()
284
  gr.HTML("<div id='cart-button' style='position: fixed; top: 20px; right: 20px; background: #28a745; color: white; padding: 10px 20px; border-radius: 30px; cursor: pointer; z-index: 1000;' onclick='openCartModal()'>View Cart</div>")
285
- gr.HTML("<div id='cart-modal' style='display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: white; z-index: 1000; overflow-y: auto;'><div style='padding: 20px;'><div style='text-align: right;'><button onclick='closeCartModal()' style='background: none; border: none; font-size: 24px; cursor: pointer;'>&times;</button></div><h1>Your Cart</h1><div id='cart-items'></div><p id='cart-total-cost' style='font-size: 1.2em; font-weight: bold;'>Total Cart Cost: $0.00</p><button style='background: #ff5722; color: white; padding: 10px 20px; border-radius: 5px; border: none; cursor: pointer;' onclick='proceedToCheckout()'>Proceed to Checkout</button></div></div>")
286
  gr.HTML(create_modal_window())
287
  gr.HTML(modal_js())
288
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
  login_button.click(
290
  lambda email, password: (gr.update(visible=False), gr.update(visible=True), gr.update(value=filter_menu("All")), "Login successful!")
291
  if login(email, password)[0] == "Login successful!" else (gr.update(), gr.update(), gr.update(), "Invalid email or password."),
292
  [login_email, login_password], [login_page, menu_page, menu_output, login_output]
293
  )
294
  preference.change(lambda pref: filter_menu(pref), [preference], menu_output)
 
 
 
 
 
 
 
 
 
 
 
295
 
296
- app.launch()
 
254
  """
255
  return modal_script
256
 
257
+ # Updated Gradio App
258
  with gr.Blocks() as app:
259
+ cart_data = gr.State([]) # State to hold cart data
260
+
261
  with gr.Row():
262
  gr.HTML("<h1 style='text-align: center;'>Welcome to Biryani Hub</h1>")
263
 
 
284
  preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
285
  menu_output = gr.HTML()
286
  gr.HTML("<div id='cart-button' style='position: fixed; top: 20px; right: 20px; background: #28a745; color: white; padding: 10px 20px; border-radius: 30px; cursor: pointer; z-index: 1000;' onclick='openCartModal()'>View Cart</div>")
287
+ gr.HTML("<div id='cart-modal' style='display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: white; z-index: 1000; overflow-y: auto;'><div style='padding: 20px;'><div style='text-align: right;'><button onclick='closeCartModal()' style='background: none; border: none; font-size: 24px; cursor: pointer;'>&times;</button></div><h1>Your Cart</h1><div id='cart-items'></div><p id='cart-total-cost' style='font-size: 1.2em; font-weight: bold;'>Total Cart Cost: $0.00</p><button style='background: #ff5722; color: white; padding: 10px 20px; border-radius: 5px; border: none; cursor: pointer;' onclick='proceedToCheckout()'>Proceed to Checkout</button><button id='final-submit' style='background: #28a745; color: white; padding: 10px 20px; border-radius: 5px; border: none; cursor: pointer;'>Final Submit</button></div></div>")
288
  gr.HTML(create_modal_window())
289
  gr.HTML(modal_js())
290
 
291
+ # New Page to Display Final Cart Details
292
+ with gr.Row(visible=False) as final_page:
293
+ cart_details = gr.HTML()
294
+ back_to_menu = gr.Button("Back to Menu")
295
+
296
+ # Show Final Page with Cart Details
297
+ def show_final_page(cart):
298
+ if not cart:
299
+ return gr.update(visible=False), "Your cart is empty!"
300
+ details = "<h2>Your Order Summary:</h2><ul>"
301
+ for item in cart:
302
+ details += f"<li>{item['quantity']} x {item['name']} (${item['price']} each)"
303
+ if item['extras']:
304
+ details += f"<br>Add-ons: {', '.join([extra['name'] for extra in item['extras']])}</li>"
305
+ details += "</li>"
306
+ details += f"</ul><p><strong>Total Cost: ${sum(item['totalCost'] for item in cart):.2f}</strong></p>"
307
+ return gr.update(visible=True), details
308
+
309
+ # Button Click Handlers
310
  login_button.click(
311
  lambda email, password: (gr.update(visible=False), gr.update(visible=True), gr.update(value=filter_menu("All")), "Login successful!")
312
  if login(email, password)[0] == "Login successful!" else (gr.update(), gr.update(), gr.update(), "Invalid email or password."),
313
  [login_email, login_password], [login_page, menu_page, menu_output, login_output]
314
  )
315
  preference.change(lambda pref: filter_menu(pref), [preference], menu_output)
316
+ gr.HTML(modal_js())
317
+
318
+ # Final Submit Button
319
+ menu_page.children[-1].click(
320
+ lambda cart: (gr.update(visible=False), gr.update(visible=True, value=show_final_page(cart)[1])),
321
+ [cart_data],
322
+ [menu_page, final_page, cart_details]
323
+ )
324
+
325
+ # Back to Menu Button
326
+ back_to_menu.click(lambda: (gr.update(visible=True), gr.update(visible=False)), None, [menu_page, final_page])
327
 
328
+ app.launch()