nagasurendra commited on
Commit
53adc8f
·
verified ·
1 Parent(s): e048e07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -6
app.py CHANGED
@@ -323,6 +323,7 @@ def navigate_to_login():
323
 
324
  # Gradio App
325
  def app():
 
326
  with gr.Blocks() as demo:
327
  # Login Page
328
  with gr.Column(visible=True) as login_section:
@@ -356,10 +357,10 @@ def app():
356
  )
357
 
358
  # Output area for menu items
359
- menu_output = gr.HTML(value=filter_menu("All"))
360
 
361
  # Button to navigate to Cart Page
362
- view_cart_button = gr.Button("View Cart")
363
 
364
  # Modal window
365
  modal_window = gr.HTML("""
@@ -400,8 +401,7 @@ def app():
400
  gr.Row(menu_output)
401
  gr.Row(modal_window)
402
  gr.HTML(modal_and_cart_js)
403
-
404
- # Cart & Final Order Page
405
  with gr.Column(visible=False) as cart_section:
406
  gr.Markdown("### Cart & Final Order Page")
407
 
@@ -420,37 +420,59 @@ def app():
420
  # Button Bindings
421
  # Login Button
422
  login_button.click(
423
- 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."),
 
 
424
  inputs=[login_email, login_password],
425
  outputs=[login_section, menu_section, login_error],
426
  )
 
427
  # Signup Button
428
  signup_button.click(
429
- 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)),
430
  inputs=[signup_name, signup_phone, signup_email, signup_password],
431
  outputs=[signup_message, login_section, signup_section],
432
  )
 
433
  # Navigate to Signup Page
434
  go_to_signup.click(
435
  lambda: (gr.update(visible=False), gr.update(visible=True)),
436
  outputs=[login_section, signup_section],
437
  )
 
438
  # Navigate Back to Login Page
439
  go_to_login.click(
440
  lambda: (gr.update(visible=True), gr.update(visible=False)),
441
  outputs=[login_section, signup_section],
442
  )
 
443
  # Navigate to Cart Page
444
  view_cart_button.click(
445
  lambda: (gr.update(visible=False), gr.update(visible=True)),
446
  outputs=[menu_section, cart_section],
447
  )
 
448
  # Navigate Back to Menu Page
449
  back_to_menu_button.click(
450
  lambda: (gr.update(visible=True), gr.update(visible=False)),
451
  outputs=[menu_section, cart_section],
452
  )
453
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
454
  return demo
455
 
456
  if __name__ == "__main__":
 
323
 
324
  # Gradio App
325
  def app():
326
+
327
  with gr.Blocks() as demo:
328
  # Login Page
329
  with gr.Column(visible=True) as login_section:
 
357
  )
358
 
359
  # Output area for menu items
360
+ menu_output = gr.HTML(value="<p>Displaying all menu items...</p>")
361
 
362
  # Button to navigate to Cart Page
363
+ view_cart_button = gr.Button("View Cart", elem_id="view-cart-button")
364
 
365
  # Modal window
366
  modal_window = gr.HTML("""
 
401
  gr.Row(menu_output)
402
  gr.Row(modal_window)
403
  gr.HTML(modal_and_cart_js)
404
+ # Cart & Final Order Page
 
405
  with gr.Column(visible=False) as cart_section:
406
  gr.Markdown("### Cart & Final Order Page")
407
 
 
420
  # Button Bindings
421
  # Login Button
422
  login_button.click(
423
+ lambda email, password: (gr.update(visible=False), gr.update(visible=True), "")
424
+ if email == "test@example.com" and password == "password"
425
+ else (gr.update(), gr.update(), "Invalid email or password."),
426
  inputs=[login_email, login_password],
427
  outputs=[login_section, menu_section, login_error],
428
  )
429
+
430
  # Signup Button
431
  signup_button.click(
432
+ lambda name, phone, email, password: ("Signup successful! Please login.", gr.update(visible=True), gr.update(visible=False)),
433
  inputs=[signup_name, signup_phone, signup_email, signup_password],
434
  outputs=[signup_message, login_section, signup_section],
435
  )
436
+
437
  # Navigate to Signup Page
438
  go_to_signup.click(
439
  lambda: (gr.update(visible=False), gr.update(visible=True)),
440
  outputs=[login_section, signup_section],
441
  )
442
+
443
  # Navigate Back to Login Page
444
  go_to_login.click(
445
  lambda: (gr.update(visible=True), gr.update(visible=False)),
446
  outputs=[login_section, signup_section],
447
  )
448
+
449
  # Navigate to Cart Page
450
  view_cart_button.click(
451
  lambda: (gr.update(visible=False), gr.update(visible=True)),
452
  outputs=[menu_section, cart_section],
453
  )
454
+
455
  # Navigate Back to Menu Page
456
  back_to_menu_button.click(
457
  lambda: (gr.update(visible=True), gr.update(visible=False)),
458
  outputs=[menu_section, cart_section],
459
  )
460
 
461
+ # Inject JavaScript for Scrolling to Top
462
+ demo.add_component(gr.HTML("""
463
+ <script>
464
+ document.addEventListener("DOMContentLoaded", function () {
465
+ const viewCartButton = document.querySelector("#view-cart-button");
466
+ if (viewCartButton) {
467
+ viewCartButton.addEventListener("click", function () {
468
+ setTimeout(() => {
469
+ window.scrollTo({ top: 0, behavior: "smooth" });
470
+ }, 200);
471
+ });
472
+ }
473
+ });
474
+ </script>
475
+ """))
476
  return demo
477
 
478
  if __name__ == "__main__":