khirodsahoo93 commited on
Commit
7843995
·
verified ·
1 Parent(s): ce52901

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -154
app.py CHANGED
@@ -378,169 +378,37 @@ modern_css = """
378
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
379
  }
380
 
381
- /* Login styling */
382
- body, .gradio-container {
 
 
 
 
 
 
383
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
384
- }
385
-
386
- .login-column {
387
  display: flex !important;
388
- flex-direction: column !important;
389
  align-items: center !important;
390
  justify-content: center !important;
391
- min-height: 100vh !important;
392
- padding: 24px !important;
393
  }
394
 
395
- .login-wrapper {
396
- width: 100%;
397
- display: flex;
398
- justify-content: center;
399
- margin-bottom: 24px;
400
- }
401
-
402
- .login-card {
403
  max-width: 400px;
404
- width: 100%;
405
  background: rgba(255, 255, 255, 0.95);
406
  backdrop-filter: blur(10px);
407
- border: 1px solid rgba(255, 255, 255, 0.3);
408
  border-radius: 20px;
409
- padding: 48px 40px 24px 40px;
410
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
411
- text-align: center;
412
- }
413
-
414
- .login-form {
415
- max-width: 400px !important;
416
- width: 100% !important;
417
- background: rgba(255, 255, 255, 0.95) !important;
418
- backdrop-filter: blur(10px) !important;
419
- border: 1px solid rgba(255, 255, 255, 0.3) !important;
420
- border-radius: 20px !important;
421
- padding: 32px 40px !important;
422
- box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3) !important;
423
- margin: 0 auto !important;
424
- }
425
-
426
- .login-icon {
427
- font-size: 56px;
428
- text-align: center;
429
- margin-bottom: 16px;
430
- filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
431
- }
432
-
433
- .login-title {
434
- text-align: center;
435
- margin: 0 0 8px 0;
436
- font-size: 28px;
437
- font-weight: 700;
438
- color: #1f2937;
439
- letter-spacing: -0.02em;
440
- }
441
-
442
- .login-subtitle {
443
- text-align: center;
444
- margin: 0 0 32px 0;
445
- font-size: 15px;
446
- color: #6b7280;
447
- font-weight: 400;
448
- }
449
-
450
- .login-input label {
451
- color: #374151 !important;
452
- font-weight: 600 !important;
453
- font-size: 14px !important;
454
- }
455
-
456
- .login-input input {
457
- background: white !important;
458
- border: 2px solid #e5e7eb !important;
459
- border-radius: 10px !important;
460
- padding: 12px 16px !important;
461
- font-size: 16px !important;
462
- color: #111827 !important;
463
- }
464
-
465
- .login-input input:focus {
466
- border-color: #667eea !important;
467
- background: white !important;
468
- outline: none !important;
469
- box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1) !important;
470
- }
471
-
472
- .login-error {
473
- color: #dc2626;
474
- background: #fee2e2;
475
- border: 1px solid #fca5a5;
476
- padding: 12px;
477
- border-radius: 10px;
478
- text-align: center;
479
- font-weight: 500;
480
- }
481
-
482
- .freepik-credit {
483
- margin-top: 24px;
484
- text-align: center;
485
- font-size: 12px;
486
- color: #9ca3af;
487
- }
488
-
489
- .freepik-credit a {
490
- color: #667eea;
491
- text-decoration: none;
492
- font-weight: 500;
493
- }
494
-
495
- .freepik-credit a:hover {
496
- text-decoration: underline;
497
  }
498
  """
499
 
500
- # Create the interface with password protection
501
  def create_interface():
502
  with gr.Blocks(css=modern_css, title="Python to C++ Code Optimizer", theme=gr.themes.Soft()) as app:
503
- authorized = gr.State(False)
504
- BANNER_URL = os.getenv("BANNER_URL", "")
505
- BACKGROUND_URL = os.getenv("BACKGROUND_URL", "")
506
- # Intentionally not rendering a banner image to avoid empty placeholders
507
-
508
- def check_password(pw):
509
- ok = pw == APP_PASSWORD
510
- return (
511
- gr.update(visible=not ok), # login hidden when ok
512
- gr.update(visible=ok), # main shown when ok
513
- gr.update(value="" if ok else "Invalid password", visible=not ok)
514
- )
515
-
516
- # Login gate - DO NOT wrap in custom HTML divs for HF compatibility
517
- with gr.Column(visible=True, elem_classes=["login-column"]) as login_group:
518
- gr.HTML("""
519
- <div class="login-wrapper">
520
- <div class="login-card">
521
- <div class="login-icon">🔐</div>
522
- <div class="login-title">Private Access</div>
523
- <div class="login-subtitle">Enter password to continue</div>
524
- </div>
525
- </div>
526
- """)
527
- with gr.Column(elem_classes=["login-form"]):
528
- pw = gr.Textbox(
529
- label="Password",
530
- type="password",
531
- placeholder="Enter password",
532
- elem_classes=["login-input"],
533
- container=True,
534
- interactive=True
535
- )
536
- login_btn = gr.Button("Continue", elem_classes=["modern-button"], size="lg", variant="primary")
537
- login_error = gr.Markdown(visible=False, elem_classes=["login-error"])
538
- gr.HTML("""
539
- <div class="freepik-credit">Background design inspired by <a href="https://www.freepik.com" target="_blank">Freepik</a></div>
540
- """)
541
-
542
- # Main UI wrapped for toggling visibility
543
- with gr.Group(visible=False) as main_group:
544
  main_group.elem_id = "main_group"
545
  # Header Section
546
  gr.HTML("""
@@ -636,13 +504,6 @@ def create_interface():
636
  outputs=cpp_execution_output
637
  )
638
 
639
- # Bind login after main_group is defined
640
- login_btn.click(
641
- fn=check_password,
642
- inputs=[pw],
643
- outputs=[login_group, main_group, login_error]
644
- )
645
-
646
  return app
647
 
648
  # Launch the app
@@ -662,6 +523,8 @@ if __name__ == "__main__":
662
  print("🚀 Launching Python to C++ Code Optimizer on Hugging Face Spaces")
663
  print("🔐 Password protection enabled")
664
  app.launch(
 
 
665
  show_error=True
666
  )
667
  else:
@@ -685,6 +548,8 @@ if __name__ == "__main__":
685
  app.launch(
686
  server_name="127.0.0.1",
687
  server_port=port,
 
 
688
  show_error=True
689
  )
690
 
 
378
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
379
  }
380
 
381
+ /* Login styling - Simple and clean */
382
+ .login-row {
383
+ position: fixed !important;
384
+ top: 0 !important;
385
+ left: 0 !important;
386
+ right: 0 !important;
387
+ bottom: 0 !important;
388
+ z-index: 10000 !important;
389
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
 
 
 
390
  display: flex !important;
 
391
  align-items: center !important;
392
  justify-content: center !important;
 
 
393
  }
394
 
395
+ .login-row > div {
 
 
 
 
 
 
 
396
  max-width: 400px;
397
+ width: 90%;
398
  background: rgba(255, 255, 255, 0.95);
399
  backdrop-filter: blur(10px);
 
400
  border-radius: 20px;
401
+ padding: 40px;
402
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
  }
404
  """
405
 
406
+ # Create the interface - simple, no custom login
407
  def create_interface():
408
  with gr.Blocks(css=modern_css, title="Python to C++ Code Optimizer", theme=gr.themes.Soft()) as app:
409
+
410
+ # Main UI - just the app, no login gate
411
+ with gr.Group() as main_group:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
412
  main_group.elem_id = "main_group"
413
  # Header Section
414
  gr.HTML("""
 
504
  outputs=cpp_execution_output
505
  )
506
 
 
 
 
 
 
 
 
507
  return app
508
 
509
  # Launch the app
 
523
  print("🚀 Launching Python to C++ Code Optimizer on Hugging Face Spaces")
524
  print("🔐 Password protection enabled")
525
  app.launch(
526
+ auth=[("user", APP_PASSWORD)],
527
+ auth_message="🔐 Enter password to access Python→C++ Optimizer",
528
  show_error=True
529
  )
530
  else:
 
548
  app.launch(
549
  server_name="127.0.0.1",
550
  server_port=port,
551
+ auth=[("user", APP_PASSWORD)],
552
+ auth_message="🔐 Enter password to access Python→C++ Optimizer",
553
  show_error=True
554
  )
555