Spaces:
Running on Zero
Running on Zero
File size: 2,255 Bytes
8aa9dcb f234112 8aa9dcb f234112 4dd7f1b 97d8bfc 8aa9dcb f234112 8aa9dcb 3e47796 8aa9dcb f234112 8aa9dcb eb16fd7 8aa9dcb 0bb91ff 8aa9dcb ea85c8e 8aa9dcb ea85c8e 8aa9dcb 32b6488 8aa9dcb 0bb91ff 924ea19 0bb91ff | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | """Hugging Face Gradio entry point with the React dashboard mounted in-app."""
from __future__ import annotations
import os
import sys
from pathlib import Path
os.environ["GRADIO_SSR_MODE"] = "false"
import gradio as gr
from starlette.routing import Mount
ROOT = Path(__file__).resolve().parent
sys.path.insert(0, str(ROOT))
sys.path.insert(0, str(ROOT / "src"))
sys.path.insert(0, str(ROOT / "src" / "near_miss"))
try:
import src.near_miss as near_miss
sys.modules["near_miss"] = near_miss
except Exception:
pass
from dashboard_api import app as fastapi_app
try:
import spaces
except ImportError:
class spaces:
@staticmethod
def GPU(fn=None, duration=120):
if fn is None:
return lambda function: function
return fn
@spaces.GPU(duration=120)
def zero_gpu_pipeline_worker(value: str = "") -> str:
"""Register the Space's ZeroGPU worker with Hugging Face's supervisor."""
return value
with gr.Blocks(title="AI Traffic Adaptation System") as demo:
gr.HTML(
"""
<style>
html, body, .gradio-container {
max-width: 100% !important;
width: 100% !important;
height: 100% !important;
margin: 0 !important;
padding: 0 !important;
overflow: hidden !important;
background: #020617 !important;
}
footer { display: none !important; }
</style>
<div style="width:100%;height:100vh;margin:0;padding:0;overflow:hidden;background:#020617">
<iframe src="/dashboard/" title="AI Traffic Adaptation Dashboard"
style="width:100%;height:100%;border:0;display:block"></iframe>
</div>
"""
)
# Gradio registers catch-all routes during Blocks construction. Put the mounted
# application first so its API, static files, and WebSocket routes are matched.
demo.app.router.routes.insert(
0,
Mount("/dashboard", app=fastapi_app, name="traffic_dashboard"),
)
app = demo.app
if __name__ == "__main__":
demo.launch(
server_name="0.0.0.0",
server_port=int(os.environ.get("PORT", "7860")),
theme=gr.themes.Soft(primary_hue="indigo"),
_app=app,
)
|