Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -597,4 +597,51 @@ def get_url_params(request: gr.Request):
|
|
| 597 |
return "Load Distributor", None
|
| 598 |
|
| 599 |
def handle_user_access(request: gr.Request):
|
| 600 |
-
"""Handle user access
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 597 |
return "Load Distributor", None
|
| 598 |
|
| 599 |
def handle_user_access(request: gr.Request):
|
| 600 |
+
"""Handle user access and perform load balancing"""
|
| 601 |
+
title, check_id = get_url_params(request)
|
| 602 |
+
|
| 603 |
+
if not check_id:
|
| 604 |
+
# No student ID provided
|
| 605 |
+
error_html = """
|
| 606 |
+
<div style="max-width: 600px; margin: 50px auto; padding: 30px; text-align: center;
|
| 607 |
+
background: #fff3cd; border: 1px solid #ffeaa7; border-radius: 12px;">
|
| 608 |
+
<h2 style="color: #856404;">⚠️ Invalid Access</h2>
|
| 609 |
+
<p style="color: #856404; font-size: 16px; line-height: 1.6;">
|
| 610 |
+
This load distributor requires a valid student ID parameter.<br><br>
|
| 611 |
+
<strong>Please access this system through the official link provided in Moodle.</strong>
|
| 612 |
+
</p>
|
| 613 |
+
</div>
|
| 614 |
+
"""
|
| 615 |
+
return title, gr.HTML(error_html)
|
| 616 |
+
|
| 617 |
+
# Valid student ID - perform load balancing
|
| 618 |
+
try:
|
| 619 |
+
result = load_balance_user(check_id)
|
| 620 |
+
return title, result
|
| 621 |
+
except Exception as e:
|
| 622 |
+
# Handle any errors during load balancing
|
| 623 |
+
error_html = f"""
|
| 624 |
+
<div style="max-width: 600px; margin: 50px auto; padding: 30px; text-align: center;
|
| 625 |
+
background: #f8d7da; border: 1px solid #f5c6cb; border-radius: 12px;">
|
| 626 |
+
<h2 style="color: #721c24;">🚫 Load Balancing Error</h2>
|
| 627 |
+
<p style="color: #721c24; font-size: 16px; line-height: 1.6;">
|
| 628 |
+
{str(e)}<br><br>
|
| 629 |
+
Please try again in a few moments or contact your instructor if the problem persists.
|
| 630 |
+
</p>
|
| 631 |
+
</div>
|
| 632 |
+
"""
|
| 633 |
+
return title, gr.HTML(error_html)
|
| 634 |
+
|
| 635 |
+
# Create Gradio interface
|
| 636 |
+
with gr.Blocks(title="CIV3283 Load Distributor") as interface:
|
| 637 |
+
title_display = gr.Markdown("# 🔄 CIV3283 Learning Assistant Load Distributor", elem_id="title")
|
| 638 |
+
content_display = gr.HTML("")
|
| 639 |
+
|
| 640 |
+
# Initialize on page load
|
| 641 |
+
interface.load(
|
| 642 |
+
fn=handle_user_access,
|
| 643 |
+
outputs=[title_display, content_display]
|
| 644 |
+
)
|
| 645 |
+
|
| 646 |
+
if __name__ == "__main__":
|
| 647 |
+
interface.launch()
|