Spaces:
Running
Running
Commit ·
f5245eb
1
Parent(s): d8aa682
Fix Gradio static asset 404s: use demo.app instead of mount_gradio_app
Browse filesmount_gradio_app mounts Gradio as a FastAPI sub-application, which
breaks /_app/immutable/* static file serving on HF Spaces. Instead,
add REST routes directly to Gradio's own FastAPI instance via demo.app.
Co-Authored-By: Oz <oz-agent@warp.dev>
app.py
CHANGED
|
@@ -632,17 +632,17 @@ The AI assistant is here to help with practical, actionable guidance.
|
|
| 632 |
)
|
| 633 |
|
| 634 |
|
| 635 |
-
#
|
| 636 |
-
#
|
| 637 |
-
|
|
|
|
|
|
|
|
|
|
| 638 |
from rest_api import build_router # noqa: E402
|
| 639 |
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
# `app` is the ASGI entrypoint HF Spaces / uvicorn will serve.
|
| 644 |
-
app = gr.mount_gradio_app(api, demo, path="/")
|
| 645 |
|
| 646 |
if __name__ == "__main__":
|
| 647 |
-
|
| 648 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 632 |
)
|
| 633 |
|
| 634 |
|
| 635 |
+
# Expose REST endpoints alongside the Gradio UI.
|
| 636 |
+
#
|
| 637 |
+
# Instead of mounting Gradio as a sub-app of FastAPI (which breaks
|
| 638 |
+
# /_app/immutable/* static-file serving on HF Spaces), we add our
|
| 639 |
+
# REST router directly to Gradio's own FastAPI app. This ensures
|
| 640 |
+
# Gradio's SvelteKit frontend assets are served correctly.
|
| 641 |
from rest_api import build_router # noqa: E402
|
| 642 |
|
| 643 |
+
demo.queue()
|
| 644 |
+
app = demo.app # Gradio's internal FastAPI instance
|
| 645 |
+
app.include_router(build_router()) # add /api/v1/* routes
|
|
|
|
|
|
|
| 646 |
|
| 647 |
if __name__ == "__main__":
|
| 648 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|