nagasurendra commited on
Commit
8fd9cea
·
verified ·
1 Parent(s): ccd6d31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -19
app.py CHANGED
@@ -306,22 +306,13 @@ def navigate_to_login():
306
 
307
  def app():
308
  with gr.Blocks() as demo:
309
- # JavaScript for scrolling to the top
310
- scroll_to_top_js = """
311
- <script>
312
- function scrollToTop() {
313
- document.body.scrollTop = 0; // For Safari
314
- document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE, and Opera
315
- }
316
- </script>
317
- """
318
-
319
  # Cart & Final Order Page (Always at the Top)
320
- with gr.Column(visible=False) as cart_section:
321
  gr.Markdown("### Cart & Final Order Page (Always at the Top)")
322
  cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
323
  final_order_output = gr.HTML(value="", elem_id="final-order")
324
  back_to_menu_button = gr.Button("Back to Menu")
 
325
  # Login Page
326
  with gr.Column(visible=True) as login_section:
327
  gr.Markdown("# Login Page")
@@ -342,8 +333,8 @@ def app():
342
  signup_button = gr.Button("Sign Up")
343
  go_to_login = gr.Button("Back to Login")
344
 
345
- # Menu Page
346
- with gr.Column(visible=False) as menu_section:
347
  gr.Markdown("### Menu Page (Below Cart Section)")
348
 
349
  # View Cart Button (Top Position)
@@ -401,19 +392,21 @@ def app():
401
  gr.Row(view_cart_button_top) # View Cart button at the top
402
  gr.Row([selected_preference])
403
  gr.Row(menu_output)
404
- gr.Row(view_cart_button_bottom)
405
- gr.HTML(scroll_to_top_js)# View Cart button at the bottom
406
  gr.Row(modal_window)
407
  gr.HTML(modal_and_cart_js)
408
 
409
  # Button Bindings
410
  # Login Button
411
  # Login Button
 
 
412
  login_button.click(
413
  lambda email, password: (gr.update(visible=False), gr.update(visible=True), "") if check_credentials(email, password) else (gr.update(), gr.update(), "Invalid email or password."),
414
  inputs=[login_email, login_password],
415
  outputs=[login_section, menu_section, login_error],
416
  )
 
417
  signup_button.click(
418
  lambda name, phone, email, password: ("Signup successful! Please login.", gr.update(visible=True), gr.update(visible=False)) if save_user(name, phone, email, password) else ("Email already exists.", gr.update(visible=False), gr.update(visible=True)),
419
  inputs=[signup_name, signup_phone, signup_email, signup_password],
@@ -427,25 +420,23 @@ def app():
427
  lambda: (gr.update(visible=True), gr.update(visible=False)),
428
  outputs=[login_section, signup_section],
429
  )
 
430
  view_cart_button_top.click(
431
  lambda: (gr.update(visible=True), gr.update(visible=False)),
432
  outputs=[cart_section, menu_section],
433
- _js="scrollToTop()", # Scroll to top on visibility change
434
  )
435
  view_cart_button_bottom.click(
436
  lambda: (gr.update(visible=True), gr.update(visible=False)),
437
  outputs=[cart_section, menu_section],
438
- _js="scrollToTop()", # Scroll to top on visibility change
439
  )
440
  back_to_menu_button.click(
441
  lambda: (gr.update(visible=False), gr.update(visible=True)),
442
  outputs=[cart_section, menu_section],
443
  )
444
 
445
-
446
-
447
  return demo
448
 
449
 
 
450
  if __name__ == "__main__":
451
  app().launch()
 
306
 
307
  def app():
308
  with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
309
  # Cart & Final Order Page (Always at the Top)
310
+ with gr.Column(visible=False, elem_id="cart-section") as cart_section:
311
  gr.Markdown("### Cart & Final Order Page (Always at the Top)")
312
  cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
313
  final_order_output = gr.HTML(value="", elem_id="final-order")
314
  back_to_menu_button = gr.Button("Back to Menu")
315
+
316
  # Login Page
317
  with gr.Column(visible=True) as login_section:
318
  gr.Markdown("# Login Page")
 
333
  signup_button = gr.Button("Sign Up")
334
  go_to_login = gr.Button("Back to Login")
335
 
336
+ # Menu Page (Below the Cart Section)
337
+ with gr.Column(visible=False, elem_id="menu-section") as menu_section:
338
  gr.Markdown("### Menu Page (Below Cart Section)")
339
 
340
  # View Cart Button (Top Position)
 
392
  gr.Row(view_cart_button_top) # View Cart button at the top
393
  gr.Row([selected_preference])
394
  gr.Row(menu_output)
395
+ gr.Row(view_cart_button_bottom) # View Cart button at the bottom
 
396
  gr.Row(modal_window)
397
  gr.HTML(modal_and_cart_js)
398
 
399
  # Button Bindings
400
  # Login Button
401
  # Login Button
402
+ # Button Bindings
403
+ # Login Button
404
  login_button.click(
405
  lambda email, password: (gr.update(visible=False), gr.update(visible=True), "") if check_credentials(email, password) else (gr.update(), gr.update(), "Invalid email or password."),
406
  inputs=[login_email, login_password],
407
  outputs=[login_section, menu_section, login_error],
408
  )
409
+ # Signup Button
410
  signup_button.click(
411
  lambda name, phone, email, password: ("Signup successful! Please login.", gr.update(visible=True), gr.update(visible=False)) if save_user(name, phone, email, password) else ("Email already exists.", gr.update(visible=False), gr.update(visible=True)),
412
  inputs=[signup_name, signup_phone, signup_email, signup_password],
 
420
  lambda: (gr.update(visible=True), gr.update(visible=False)),
421
  outputs=[login_section, signup_section],
422
  )
423
+ # Navigate to Cart Page (Both Buttons Use the Same Logic)
424
  view_cart_button_top.click(
425
  lambda: (gr.update(visible=True), gr.update(visible=False)),
426
  outputs=[cart_section, menu_section],
 
427
  )
428
  view_cart_button_bottom.click(
429
  lambda: (gr.update(visible=True), gr.update(visible=False)),
430
  outputs=[cart_section, menu_section],
 
431
  )
432
  back_to_menu_button.click(
433
  lambda: (gr.update(visible=False), gr.update(visible=True)),
434
  outputs=[cart_section, menu_section],
435
  )
436
 
 
 
437
  return demo
438
 
439
 
440
+
441
  if __name__ == "__main__":
442
  app().launch()