Debdeep Banerjee commited on
Commit ·
5025730
1
Parent(s): fab64df
fix: mount Gradio before catch-all route so /gradio/config resolves correctly
Browse files
app.py
CHANGED
|
@@ -786,8 +786,11 @@ DIST_DIR = Path(__file__).parent / "dist"
|
|
| 786 |
|
| 787 |
_fastapi = FastAPI()
|
| 788 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 789 |
if DIST_DIR.exists():
|
| 790 |
-
# Static asset folders
|
| 791 |
for _subdir in ("assets", "avatars"):
|
| 792 |
_path = DIST_DIR / _subdir
|
| 793 |
if _path.exists():
|
|
@@ -803,18 +806,11 @@ if DIST_DIR.exists():
|
|
| 803 |
|
| 804 |
@_fastapi.get("/{full_path:path}")
|
| 805 |
async def _spa_fallback(full_path: str):
|
| 806 |
-
# Let Gradio handle its own paths
|
| 807 |
-
if full_path.startswith("gradio"):
|
| 808 |
-
from fastapi.responses import Response
|
| 809 |
-
return Response(status_code=404)
|
| 810 |
candidate = DIST_DIR / full_path
|
| 811 |
if candidate.exists() and candidate.is_file():
|
| 812 |
return FileResponse(str(candidate))
|
| 813 |
return FileResponse(str(DIST_DIR / "index.html"))
|
| 814 |
|
| 815 |
-
os.environ.setdefault("GRADIO_ALLOWED_PATHS", "/tmp")
|
| 816 |
-
app = gr.mount_gradio_app(_fastapi, demo, path="/gradio")
|
| 817 |
-
|
| 818 |
if __name__ == "__main__":
|
| 819 |
import uvicorn
|
| 820 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 786 |
|
| 787 |
_fastapi = FastAPI()
|
| 788 |
|
| 789 |
+
# Mount Gradio FIRST so its /gradio/* routes have priority over the catch-all.
|
| 790 |
+
os.environ.setdefault("GRADIO_ALLOWED_PATHS", "/tmp")
|
| 791 |
+
app = gr.mount_gradio_app(_fastapi, demo, path="/gradio")
|
| 792 |
+
|
| 793 |
if DIST_DIR.exists():
|
|
|
|
| 794 |
for _subdir in ("assets", "avatars"):
|
| 795 |
_path = DIST_DIR / _subdir
|
| 796 |
if _path.exists():
|
|
|
|
| 806 |
|
| 807 |
@_fastapi.get("/{full_path:path}")
|
| 808 |
async def _spa_fallback(full_path: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 809 |
candidate = DIST_DIR / full_path
|
| 810 |
if candidate.exists() and candidate.is_file():
|
| 811 |
return FileResponse(str(candidate))
|
| 812 |
return FileResponse(str(DIST_DIR / "index.html"))
|
| 813 |
|
|
|
|
|
|
|
|
|
|
| 814 |
if __name__ == "__main__":
|
| 815 |
import uvicorn
|
| 816 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|