Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -378,37 +378,147 @@ modern_css = """
|
|
| 378 |
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
| 379 |
}
|
| 380 |
|
| 381 |
-
/* Login styling
|
| 382 |
-
.
|
| 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-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
max-width: 400px;
|
| 397 |
-
width:
|
| 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
|
| 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 |
-
|
| 411 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
main_group.elem_id = "main_group"
|
| 413 |
# Header Section
|
| 414 |
gr.HTML("""
|
|
@@ -504,6 +614,13 @@ def create_interface():
|
|
| 504 |
outputs=cpp_execution_output
|
| 505 |
)
|
| 506 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 507 |
return app
|
| 508 |
|
| 509 |
# Launch the app
|
|
@@ -523,8 +640,6 @@ if __name__ == "__main__":
|
|
| 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,8 +663,6 @@ if __name__ == "__main__":
|
|
| 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 |
|
|
|
|
| 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-wrapper {
|
| 387 |
+
display: flex;
|
| 388 |
+
align-items: center;
|
| 389 |
+
justify-content: center;
|
| 390 |
+
min-height: 100vh;
|
| 391 |
+
padding: 24px;
|
| 392 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
.login-card {
|
| 396 |
max-width: 400px;
|
| 397 |
+
width: 100%;
|
| 398 |
background: rgba(255, 255, 255, 0.95);
|
| 399 |
backdrop-filter: blur(10px);
|
| 400 |
+
border: 1px solid rgba(255, 255, 255, 0.3);
|
| 401 |
border-radius: 20px;
|
| 402 |
+
padding: 48px 40px;
|
| 403 |
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
| 404 |
}
|
| 405 |
+
|
| 406 |
+
.login-icon {
|
| 407 |
+
font-size: 56px;
|
| 408 |
+
text-align: center;
|
| 409 |
+
margin-bottom: 16px;
|
| 410 |
+
filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
.login-title {
|
| 414 |
+
text-align: center;
|
| 415 |
+
margin: 0 0 8px 0;
|
| 416 |
+
font-size: 28px;
|
| 417 |
+
font-weight: 700;
|
| 418 |
+
color: #1f2937;
|
| 419 |
+
letter-spacing: -0.02em;
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
.login-subtitle {
|
| 423 |
+
text-align: center;
|
| 424 |
+
margin: 0 0 32px 0;
|
| 425 |
+
font-size: 15px;
|
| 426 |
+
color: #6b7280;
|
| 427 |
+
font-weight: 400;
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
.login-input label {
|
| 431 |
+
color: #374151 !important;
|
| 432 |
+
font-weight: 600 !important;
|
| 433 |
+
font-size: 14px !important;
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
.login-input input {
|
| 437 |
+
background: white !important;
|
| 438 |
+
border: 2px solid #e5e7eb !important;
|
| 439 |
+
border-radius: 10px !important;
|
| 440 |
+
padding: 12px 16px !important;
|
| 441 |
+
font-size: 16px !important;
|
| 442 |
+
color: #111827 !important;
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
.login-input input:focus {
|
| 446 |
+
border-color: #667eea !important;
|
| 447 |
+
background: white !important;
|
| 448 |
+
outline: none !important;
|
| 449 |
+
box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1) !important;
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
.login-error {
|
| 453 |
+
color: #dc2626;
|
| 454 |
+
background: #fee2e2;
|
| 455 |
+
border: 1px solid #fca5a5;
|
| 456 |
+
padding: 12px;
|
| 457 |
+
border-radius: 10px;
|
| 458 |
+
text-align: center;
|
| 459 |
+
font-weight: 500;
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
.freepik-credit {
|
| 463 |
+
margin-top: 24px;
|
| 464 |
+
text-align: center;
|
| 465 |
+
font-size: 12px;
|
| 466 |
+
color: #9ca3af;
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
.freepik-credit a {
|
| 470 |
+
color: #667eea;
|
| 471 |
+
text-decoration: none;
|
| 472 |
+
font-weight: 500;
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
.freepik-credit a:hover {
|
| 476 |
+
text-decoration: underline;
|
| 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("""
|
|
|
|
| 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],
|
| 621 |
+
outputs=[login_group, main_group, login_error]
|
| 622 |
+
)
|
| 623 |
+
|
| 624 |
return app
|
| 625 |
|
| 626 |
# Launch the app
|
|
|
|
| 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 |
)
|
| 645 |
else:
|
|
|
|
| 663 |
app.launch(
|
| 664 |
server_name="127.0.0.1",
|
| 665 |
server_port=port,
|
|
|
|
|
|
|
| 666 |
show_error=True
|
| 667 |
)
|
| 668 |
|