Spaces:
Sleeping
Sleeping
Update clean docs and app
Browse files
app.py
CHANGED
|
@@ -41,7 +41,7 @@ from starlette.responses import FileResponse, JSONResponse
|
|
| 41 |
from starlette.routing import Route, WebSocketRoute
|
| 42 |
from starlette.websockets import WebSocket, WebSocketDisconnect
|
| 43 |
|
| 44 |
-
#
|
| 45 |
# HF detects @spaces.GPU at scan/import time. No UI elements required.
|
| 46 |
@_gpu_decorator
|
| 47 |
def _gpu_ready():
|
|
@@ -53,7 +53,7 @@ WEB_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "web")
|
|
| 53 |
os.makedirs(WEB_DIR, exist_ok=True)
|
| 54 |
|
| 55 |
|
| 56 |
-
#
|
| 57 |
with gr.Blocks(title="DOOM-FlyWire Connectome", fill_width=True, fill_height=True) as demo:
|
| 58 |
gr.HTML("""
|
| 59 |
<style>
|
|
@@ -75,7 +75,7 @@ with gr.Blocks(title="DOOM-FlyWire Connectome", fill_width=True, fill_height=Tru
|
|
| 75 |
""")
|
| 76 |
|
| 77 |
|
| 78 |
-
#
|
| 79 |
_agent = None
|
| 80 |
_agent_lock = threading.Lock()
|
| 81 |
_agent_error = None
|
|
@@ -104,7 +104,7 @@ def _get_agent():
|
|
| 104 |
return None
|
| 105 |
|
| 106 |
|
| 107 |
-
#
|
| 108 |
_orig_create_app = GradioApp.__dict__["create_app"] # staticmethod descriptor
|
| 109 |
|
| 110 |
|
|
@@ -134,7 +134,7 @@ def _patched_create_app(*args, **kwargs):
|
|
| 134 |
async def three_page(request): return _serve(os.path.join("js", "three.min.js"), "application/javascript")
|
| 135 |
async def orbit_page(request): return _serve(os.path.join("js", "OrbitControls.js"), "application/javascript")
|
| 136 |
|
| 137 |
-
#
|
| 138 |
async def ws_game(websocket: WebSocket):
|
| 139 |
await websocket.accept()
|
| 140 |
print("[WS] Client connected.")
|
|
@@ -217,7 +217,7 @@ def _patched_create_app(*args, **kwargs):
|
|
| 217 |
GradioApp.create_app = _patched_create_app
|
| 218 |
|
| 219 |
|
| 220 |
-
#
|
| 221 |
if __name__ == "__main__":
|
| 222 |
port = int(os.environ.get("PORT", 7860))
|
| 223 |
print(f"[HF Space] Launching DOOM-FlyWire on 0.0.0.0:{port}...")
|
|
|
|
| 41 |
from starlette.routing import Route, WebSocketRoute
|
| 42 |
from starlette.websockets import WebSocket, WebSocketDisconnect
|
| 43 |
|
| 44 |
+
# --- ZeroGPU Stub ---
|
| 45 |
# HF detects @spaces.GPU at scan/import time. No UI elements required.
|
| 46 |
@_gpu_decorator
|
| 47 |
def _gpu_ready():
|
|
|
|
| 53 |
os.makedirs(WEB_DIR, exist_ok=True)
|
| 54 |
|
| 55 |
|
| 56 |
+
# --- Fullscreen Edge-to-Edge Visualizer ---
|
| 57 |
with gr.Blocks(title="DOOM-FlyWire Connectome", fill_width=True, fill_height=True) as demo:
|
| 58 |
gr.HTML("""
|
| 59 |
<style>
|
|
|
|
| 75 |
""")
|
| 76 |
|
| 77 |
|
| 78 |
+
# --- Game Agent (Lazy Initialization) ---
|
| 79 |
_agent = None
|
| 80 |
_agent_lock = threading.Lock()
|
| 81 |
_agent_error = None
|
|
|
|
| 104 |
return None
|
| 105 |
|
| 106 |
|
| 107 |
+
# --- FastAPI Route Injection ---
|
| 108 |
_orig_create_app = GradioApp.__dict__["create_app"] # staticmethod descriptor
|
| 109 |
|
| 110 |
|
|
|
|
| 134 |
async def three_page(request): return _serve(os.path.join("js", "three.min.js"), "application/javascript")
|
| 135 |
async def orbit_page(request): return _serve(os.path.join("js", "OrbitControls.js"), "application/javascript")
|
| 136 |
|
| 137 |
+
# --- WebSocket Game Stream ---
|
| 138 |
async def ws_game(websocket: WebSocket):
|
| 139 |
await websocket.accept()
|
| 140 |
print("[WS] Client connected.")
|
|
|
|
| 217 |
GradioApp.create_app = _patched_create_app
|
| 218 |
|
| 219 |
|
| 220 |
+
# --- Application Launch ---
|
| 221 |
if __name__ == "__main__":
|
| 222 |
port = int(os.environ.get("PORT", 7860))
|
| 223 |
print(f"[HF Space] Launching DOOM-FlyWire on 0.0.0.0:{port}...")
|