Spaces:
Running on Zero
Running on Zero
GitHub Actions commited on
Commit Β·
0572318
1
Parent(s): b8dcc7e
fix: disable Gradio SSR mode so Python FastAPI handles /webagent/ requests
Browse filesHF Space sets GRADIO_SSR_MODE=true which makes Node.js intercept ALL
requests before Python/FastAPI. Our StaticFiles mount at /webagent/ was
invisible because it lives in Python, below the Node.js layer.
Three-layer fix:
1. os.environ[GRADIO_SSR_MODE] = false β overrides the env var
2. Patch _resolve_ssr_mode to return False β handles explicit ssr_mode=True
3. Keep App.create_app patch for StaticFiles mount at routes[0]
With SSR disabled, Python FastAPI handles all requests and /webagent/*
is served correctly from the StaticFiles mount.
app.py
CHANGED
|
@@ -395,13 +395,22 @@ _ui = _build_ui(
|
|
| 395 |
|
| 396 |
demo = _ui.build()
|
| 397 |
|
| 398 |
-
# ββ Serve webagent at /webagent/
|
| 399 |
-
#
|
| 400 |
-
#
|
|
|
|
| 401 |
from pathlib import Path as _Path
|
|
|
|
| 402 |
|
| 403 |
_webagent_dir = _Path(__file__).parent / "webagent"
|
| 404 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
if _webagent_dir.exists():
|
| 406 |
try:
|
| 407 |
import gradio.routes as _gr_routes
|
|
@@ -414,11 +423,10 @@ if _webagent_dir.exists():
|
|
| 414 |
try:
|
| 415 |
if not any(getattr(r, "name", "") == "webagent" for r in result.routes):
|
| 416 |
result.mount("/webagent", _SF(directory=str(_webagent_dir)), name="webagent")
|
| 417 |
-
# Move to front so it is matched before Gradio's SPA catch-all
|
| 418 |
_wrt = result.routes.pop()
|
| 419 |
result.routes.insert(0, _wrt)
|
| 420 |
except Exception as _me:
|
| 421 |
-
print(f"[hearthnet] webagent mount
|
| 422 |
return result
|
| 423 |
|
| 424 |
_gr_routes.App.create_app = staticmethod(_patched_create_app)
|
|
|
|
| 395 |
|
| 396 |
demo = _ui.build()
|
| 397 |
|
| 398 |
+
# ββ Serve webagent at /webagent/ ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 399 |
+
# HF Space enables Gradio SSR mode (GRADIO_SSR_MODE=true), where a Node.js layer
|
| 400 |
+
# intercepts ALL requests before Python/FastAPI sees them, making StaticFiles
|
| 401 |
+
# mounts invisible. Fix: force SSR off so Python handles all requests directly.
|
| 402 |
from pathlib import Path as _Path
|
| 403 |
+
import gradio as _gr
|
| 404 |
|
| 405 |
_webagent_dir = _Path(__file__).parent / "webagent"
|
| 406 |
|
| 407 |
+
# 1) Override the env var that launch() reads when ssr_mode param is None
|
| 408 |
+
os.environ["GRADIO_SSR_MODE"] = "false"
|
| 409 |
+
|
| 410 |
+
# 2) Also patch _resolve_ssr_mode in case HF passes ssr_mode=True explicitly
|
| 411 |
+
_gr.Blocks._resolve_ssr_mode = lambda self, ssr_mode=None, **kw: False
|
| 412 |
+
|
| 413 |
+
# 3) Patch App.create_app to inject the StaticFiles mount after Gradio routes
|
| 414 |
if _webagent_dir.exists():
|
| 415 |
try:
|
| 416 |
import gradio.routes as _gr_routes
|
|
|
|
| 423 |
try:
|
| 424 |
if not any(getattr(r, "name", "") == "webagent" for r in result.routes):
|
| 425 |
result.mount("/webagent", _SF(directory=str(_webagent_dir)), name="webagent")
|
|
|
|
| 426 |
_wrt = result.routes.pop()
|
| 427 |
result.routes.insert(0, _wrt)
|
| 428 |
except Exception as _me:
|
| 429 |
+
print(f"[hearthnet] webagent mount: {_me}")
|
| 430 |
return result
|
| 431 |
|
| 432 |
_gr_routes.App.create_app = staticmethod(_patched_create_app)
|