spacedout-bits Oz commited on
Commit
f5245eb
·
1 Parent(s): d8aa682

Fix Gradio static asset 404s: use demo.app instead of mount_gradio_app

Browse files

mount_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>

Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -632,17 +632,17 @@ The AI assistant is here to help with practical, actionable guidance.
632
  )
633
 
634
 
635
- # Mount the Gradio Blocks app inside a FastAPI app so we can expose
636
- # our own REST endpoints (see rest_api.py) alongside the UI.
637
- from fastapi import FastAPI # noqa: E402 (kept here so module-level Gradio init runs first)
 
 
 
638
  from rest_api import build_router # noqa: E402
639
 
640
- api = FastAPI(title="Farm Layout Model API")
641
- api.include_router(build_router())
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
- import uvicorn
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)