Hermes Bot commited on
fix: skip uvicorn on HF Spaces — Gradio launcher handles serving
Browse files- 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 |
-
|
| 624 |
-
mount_gradio_app(fastapi_app,
|
| 625 |
|
| 626 |
# ---------------------------------------------------------------------------
|
| 627 |
# Entrypoint
|
| 628 |
# ---------------------------------------------------------------------------
|
| 629 |
if __name__ == "__main__":
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|