Hermes Bot commited on
Commit
350b6c0
·
unverified ·
1 Parent(s): d73d9a6

fix: skip uvicorn on HF Spaces — Gradio launcher handles serving

Browse files
Files changed (1) hide show
  1. projects/tinybard/app.py +13 -9
projects/tinybard/app.py CHANGED
@@ -620,17 +620,21 @@ async def get_config():
620
  fastapi_app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
621
 
622
  # Mount Gradio app at /gradio — this creates the API + MCP endpoints
623
- gradio_blocks = create_gradio_app()
624
- mount_gradio_app(fastapi_app, gradio_blocks, path="/gradio")
625
 
626
  # ---------------------------------------------------------------------------
627
  # Entrypoint
628
  # ---------------------------------------------------------------------------
629
  if __name__ == "__main__":
630
- import uvicorn
631
- port = int(os.environ.get("PORT", "7860"))
632
- log.info(f"Starting TinyBard on port {port}")
633
- log.info(f"Frontend: http://localhost:{port}/")
634
- log.info(f"Gradio API: http://localhost:{port}/gradio/")
635
- log.info(f"MCP schema: http://localhost:{port}/gradio/gradio_api/mcp/schema")
636
- uvicorn.run(fastapi_app, host="0.0.0.0", port=port)
 
 
 
 
 
620
  fastapi_app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
621
 
622
  # Mount Gradio app at /gradio — this creates the API + MCP endpoints
623
+ demo = create_gradio_app()
624
+ app = mount_gradio_app(fastapi_app, demo, path="/gradio")
625
 
626
  # ---------------------------------------------------------------------------
627
  # Entrypoint
628
  # ---------------------------------------------------------------------------
629
  if __name__ == "__main__":
630
+ # On HF Spaces, Gradio manages the server — don't start uvicorn.
631
+ if os.environ.get("SPACE_ID"):
632
+ log.info("Running on HF Spaces — Gradio launcher handles serving.")
633
+ else:
634
+ import uvicorn
635
+ port = int(os.environ.get("PORT", "7860"))
636
+ log.info(f"Starting TinyBard on port {port}")
637
+ log.info(f"Frontend: http://localhost:{port}/")
638
+ log.info(f"Gradio API: http://localhost:{port}/gradio/")
639
+ log.info(f"MCP schema: http://localhost:{port}/gradio/gradio_api/mcp/schema")
640
+ uvicorn.run(fastapi_app, host="0.0.0.0", port=port)