Fix blank screen: keep Gradio / intact, React at /app
#2
by Asma-F - opened
- app_custom.py +4 -17
app_custom.py
CHANGED
|
@@ -134,18 +134,10 @@ def _domain(url: str) -> str:
|
|
| 134 |
|
| 135 |
def _attach_routes(app):
|
| 136 |
"""Inject React frontend + all API routes into Gradio's FastAPI app."""
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
# Remove Gradio's "/" and "/{path:path}" catch-all so React can own /
|
| 140 |
-
app.router.routes = [
|
| 141 |
-
r for r in app.router.routes
|
| 142 |
-
if not (isinstance(r, APIRoute) and r.path in ("/", "/{path:path}"))
|
| 143 |
-
]
|
| 144 |
-
|
| 145 |
-
# React at /
|
| 146 |
if _index_html:
|
| 147 |
-
@app.get("/", response_class=HTMLResponse)
|
| 148 |
-
@app.head("/", response_class=HTMLResponse)
|
| 149 |
def frontend_root():
|
| 150 |
return _index_html
|
| 151 |
|
|
@@ -375,11 +367,6 @@ def _attach_routes(app):
|
|
| 375 |
return {"summary": summary, "total_points": total,
|
| 376 |
"daily_stats": daily_stats, "concepts": concepts}
|
| 377 |
|
| 378 |
-
# SPA catch-all β must be last so Gradio's own routes (/config, /queue/*, etc.) match first
|
| 379 |
-
if _index_html:
|
| 380 |
-
@app.get("/{path:path}", response_class=HTMLResponse)
|
| 381 |
-
def spa_fallback(path: str):
|
| 382 |
-
return _index_html
|
| 383 |
|
| 384 |
|
| 385 |
# ββ Monkey-patch Gradio's App.create_app βββββββββββββββββββββββββββββββββββββ
|
|
@@ -410,7 +397,7 @@ if not _space_host:
|
|
| 410 |
if _sid and "/" in _sid:
|
| 411 |
_org, _repo = _sid.lower().split("/", 1)
|
| 412 |
_space_host = f"{_org}-{_repo}.hf.space"
|
| 413 |
-
_embed_url = f"https://{_space_host}/" if _space_host else "/"
|
| 414 |
|
| 415 |
with gr.Blocks(title="French Coach", css=(
|
| 416 |
".gradio-container{max-width:100%!important;padding:0!important;"
|
|
|
|
| 134 |
|
| 135 |
def _attach_routes(app):
|
| 136 |
"""Inject React frontend + all API routes into Gradio's FastAPI app."""
|
| 137 |
+
# Serve React at /app (leave Gradio's "/" intact so HF can load the Gradio frontend)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
if _index_html:
|
| 139 |
+
@app.get("/app", response_class=HTMLResponse)
|
| 140 |
+
@app.head("/app", response_class=HTMLResponse)
|
| 141 |
def frontend_root():
|
| 142 |
return _index_html
|
| 143 |
|
|
|
|
| 367 |
return {"summary": summary, "total_points": total,
|
| 368 |
"daily_stats": daily_stats, "concepts": concepts}
|
| 369 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
|
| 371 |
|
| 372 |
# ββ Monkey-patch Gradio's App.create_app βββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 397 |
if _sid and "/" in _sid:
|
| 398 |
_org, _repo = _sid.lower().split("/", 1)
|
| 399 |
_space_host = f"{_org}-{_repo}.hf.space"
|
| 400 |
+
_embed_url = f"https://{_space_host}/app" if _space_host else "/app"
|
| 401 |
|
| 402 |
with gr.Blocks(title="French Coach", css=(
|
| 403 |
".gradio-container{max-width:100%!important;padding:0!important;"
|