Itachi-1824 commited on
Commit Β·
a2bdc87
1
Parent(s): 5d5e37e
fix: robust gradio mount with html fallback for hf spaces
Browse files- server/app.py +28 -5
server/app.py
CHANGED
|
@@ -199,6 +199,8 @@ async def api_close(req: CloseRequest):
|
|
| 199 |
# Gradio Landing Page
|
| 200 |
# ---------------------------------------------------------------------------
|
| 201 |
|
|
|
|
|
|
|
| 202 |
try:
|
| 203 |
import gradio as gr
|
| 204 |
|
|
@@ -281,7 +283,7 @@ try:
|
|
| 281 |
.tab-nav button.selected { color: #00d4aa !important; border-bottom: 2px solid #00d4aa !important; }
|
| 282 |
"""
|
| 283 |
|
| 284 |
-
with gr.Blocks(
|
| 285 |
with gr.Tabs():
|
| 286 |
with gr.Tab("Overview"):
|
| 287 |
gr.HTML(_build_hero_html())
|
|
@@ -354,10 +356,31 @@ python inference.py --space https://Itachi1824-compliance-auditor-env.hf.space</
|
|
| 354 |
""")
|
| 355 |
|
| 356 |
gr.mount_gradio_app(app, landing_app, path="/")
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
|
| 362 |
|
| 363 |
# ---------------------------------------------------------------------------
|
|
|
|
| 199 |
# Gradio Landing Page
|
| 200 |
# ---------------------------------------------------------------------------
|
| 201 |
|
| 202 |
+
_gradio_mounted = False
|
| 203 |
+
|
| 204 |
try:
|
| 205 |
import gradio as gr
|
| 206 |
|
|
|
|
| 283 |
.tab-nav button.selected { color: #00d4aa !important; border-bottom: 2px solid #00d4aa !important; }
|
| 284 |
"""
|
| 285 |
|
| 286 |
+
with gr.Blocks(title="EU AI Act Compliance Auditor") as landing_app:
|
| 287 |
with gr.Tabs():
|
| 288 |
with gr.Tab("Overview"):
|
| 289 |
gr.HTML(_build_hero_html())
|
|
|
|
| 356 |
""")
|
| 357 |
|
| 358 |
gr.mount_gradio_app(app, landing_app, path="/")
|
| 359 |
+
_gradio_mounted = True
|
| 360 |
+
|
| 361 |
+
except Exception as e:
|
| 362 |
+
import traceback
|
| 363 |
+
print(f"[WARN] Gradio UI failed to mount: {e}", flush=True)
|
| 364 |
+
traceback.print_exc()
|
| 365 |
+
|
| 366 |
+
# Fallback root handler if Gradio didn't mount
|
| 367 |
+
if not _gradio_mounted:
|
| 368 |
+
from fastapi.responses import HTMLResponse
|
| 369 |
+
|
| 370 |
+
@app.get("/", response_class=HTMLResponse)
|
| 371 |
+
def root_fallback():
|
| 372 |
+
return """<!DOCTYPE html><html><head><title>EU AI Act Compliance Auditor</title></head>
|
| 373 |
+
<body style="background:#0a0a0a;color:#e0e0ff;font-family:sans-serif;padding:40px;">
|
| 374 |
+
<h1 style="color:#00d4aa;">EU AI Act Compliance Auditor</h1>
|
| 375 |
+
<p>MCP-based environment for auditing AI systems. 8 scenarios, 11 tools, 6-component reward.</p>
|
| 376 |
+
<h3>API Endpoints</h3>
|
| 377 |
+
<ul>
|
| 378 |
+
<li><code>GET /health</code> β Health check</li>
|
| 379 |
+
<li><code>GET /tasks</code> β List scenarios</li>
|
| 380 |
+
<li><code>POST /api/reset</code> β Start audit session</li>
|
| 381 |
+
<li><code>POST /api/call_tool</code> β Call an audit tool</li>
|
| 382 |
+
<li><code>POST /api/close</code> β End session</li>
|
| 383 |
+
</ul></body></html>"""
|
| 384 |
|
| 385 |
|
| 386 |
# ---------------------------------------------------------------------------
|