khirodsahoo93 commited on
Commit
c1f0135
Β·
verified Β·
1 Parent(s): 555cc9a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -39
app.py CHANGED
@@ -477,49 +477,37 @@ body, .gradio-container {
477
  }
478
  """
479
 
480
- # Create the interface with password protection
481
  def create_interface():
482
  with gr.Blocks(css=modern_css, title="Python to C++ Code Optimizer", theme=gr.themes.Soft()) as app:
483
- authorized = gr.State(False)
484
- BANNER_URL = os.getenv("BANNER_URL", "")
485
- BACKGROUND_URL = os.getenv("BACKGROUND_URL", "")
486
- # Intentionally not rendering a banner image to avoid empty placeholders
487
-
488
  def check_password(pw):
489
- ok = pw == APP_PASSWORD
490
- return (
491
- gr.update(visible=not ok), # login hidden when ok
492
- gr.update(visible=ok), # main shown when ok
493
- gr.update(value="" if ok else "Invalid password", visible=not ok)
494
- )
495
-
496
- # Login gate
497
- with gr.Group(visible=True) as login_group:
498
  gr.HTML("""
499
- <div class="login-wrapper">
500
- <div class="login-card">
501
- <div class="login-icon">πŸ”</div>
502
- <div class="login-title">Private Access</div>
503
- <div class="login-subtitle">Enter password to continue</div>
504
  """)
505
  pw = gr.Textbox(
506
- label="Password",
507
- type="password",
508
- placeholder="Enter password",
509
- elem_classes=["login-input"],
510
  container=True
511
  )
512
- login_btn = gr.Button("Continue", elem_classes=["modern-button"], size="lg")
513
- login_error = gr.Markdown(visible=False, elem_classes=["login-error"])
514
- gr.HTML("""
515
- <div class="freepik-credit">Background design inspired by <a href="https://www.freepik.com" target="_blank">Freepik</a></div>
516
- </div>
517
- </div>
518
- """)
519
-
520
- # Main UI wrapped for toggling visibility
521
- with gr.Group(visible=False) as main_group:
522
- main_group.elem_id = "main_group"
523
  # Header Section
524
  gr.HTML("""
525
  <div class="modern-header">
@@ -613,8 +601,8 @@ def create_interface():
613
  inputs=cpp_output,
614
  outputs=cpp_execution_output
615
  )
616
-
617
- # Bind login after main_group is defined
618
  login_btn.click(
619
  fn=check_password,
620
  inputs=[pw],
@@ -638,7 +626,7 @@ if __name__ == "__main__":
638
  if is_huggingface:
639
  # Hugging Face Spaces configuration
640
  print("πŸš€ Launching Python to C++ Code Optimizer on Hugging Face Spaces")
641
- print("πŸ” Password protection enabled")
642
  app.launch(
643
  show_error=True
644
  )
@@ -658,7 +646,7 @@ if __name__ == "__main__":
658
 
659
  port = get_available_port()
660
  print(f"πŸš€ Launching Python to C++ Code Optimizer on port: {port}")
661
- print(f"πŸ” Password protection enabled. Password: {APP_PASSWORD}")
662
 
663
  app.launch(
664
  server_name="127.0.0.1",
 
477
  }
478
  """
479
 
480
+ # Create the interface with custom login that SHOWS the boxes
481
  def create_interface():
482
  with gr.Blocks(css=modern_css, title="Python to C++ Code Optimizer", theme=gr.themes.Soft()) as app:
483
+
 
 
 
 
484
  def check_password(pw):
485
+ if pw == APP_PASSWORD:
486
+ return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
487
+ else:
488
+ return gr.update(visible=True), gr.update(visible=False), gr.update(value="❌ Wrong password", visible=True)
489
+
490
+ # Login Section - NO HTML wrapper around Gradio components!
491
+ with gr.Column(visible=True, elem_classes=["login-wrapper"]) as login_group:
 
 
492
  gr.HTML("""
493
+ <div style="text-align: center; margin: 60px auto 40px; max-width: 400px;">
494
+ <div style="font-size: 56px; margin-bottom: 16px;">πŸ”</div>
495
+ <div style="font-size: 28px; font-weight: 700; color: #1f2937; margin-bottom: 8px;">Private Access</div>
496
+ <div style="font-size: 15px; color: #6b7280; margin-bottom: 32px;">Enter password to continue</div>
497
+ </div>
498
  """)
499
  pw = gr.Textbox(
500
+ label="Password",
501
+ type="password",
502
+ placeholder="Enter password",
503
+ scale=1,
504
  container=True
505
  )
506
+ login_btn = gr.Button("Continue", variant="primary", size="lg")
507
+ login_error = gr.Markdown("", visible=False)
508
+
509
+ # Main App Section
510
+ with gr.Column(visible=False) as main_group:
 
 
 
 
 
 
511
  # Header Section
512
  gr.HTML("""
513
  <div class="modern-header">
 
601
  inputs=cpp_output,
602
  outputs=cpp_execution_output
603
  )
604
+
605
+ # Connect login button
606
  login_btn.click(
607
  fn=check_password,
608
  inputs=[pw],
 
626
  if is_huggingface:
627
  # Hugging Face Spaces configuration
628
  print("πŸš€ Launching Python to C++ Code Optimizer on Hugging Face Spaces")
629
+ print("πŸ” Custom in-app password protection enabled")
630
  app.launch(
631
  show_error=True
632
  )
 
646
 
647
  port = get_available_port()
648
  print(f"πŸš€ Launching Python to C++ Code Optimizer on port: {port}")
649
+ print(f"πŸ” Custom in-app password protection enabled. Password: {APP_PASSWORD}")
650
 
651
  app.launch(
652
  server_name="127.0.0.1",