Hermes Bot Nanoboozhoo commited on
fix: export app at module level to prevent double-launch on HF Spaces
Browse filesRoot cause of RUNTIME_ERROR on tinybard: the __main__ block started
uvicorn.run() while the HF Spaces Gradio SDK ALSO auto-launches
a server on the same PORT. Two servers = Errno 98 port in use.
Fix across all 3 projects:
- Remove if __name__ == '__main__': uvicorn.run()/app.launch()
- Export app = <app_object> at module level
- HF Spaces SDK imports the module and launches exactly one server
Co-Authored-By: Nanoboozhoo <nanoboozhoo@git-aaaki>
- projects/crittercalm/app.py +3 -11
- projects/focusfriend/app.py +3 -12
- projects/tinybard/app.py +3 -11
projects/crittercalm/app.py
CHANGED
|
@@ -818,15 +818,7 @@ def create_app() -> gr.Blocks:
|
|
| 818 |
|
| 819 |
|
| 820 |
# ---------------------------------------------------------------------------
|
| 821 |
-
# Entry point
|
| 822 |
# ---------------------------------------------------------------------------
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
server_name="0.0.0.0",
|
| 827 |
-
server_port=int(os.environ.get("PORT", "7860")),
|
| 828 |
-
share=False,
|
| 829 |
-
show_error=True,
|
| 830 |
-
mcp_server=True,
|
| 831 |
-
css=CUSTOM_CSS,
|
| 832 |
-
)
|
|
|
|
| 818 |
|
| 819 |
|
| 820 |
# ---------------------------------------------------------------------------
|
|
|
|
| 821 |
# ---------------------------------------------------------------------------
|
| 822 |
+
# Entry point — exported for HF Spaces Gradio SDK
|
| 823 |
+
# ---------------------------------------------------------------------------
|
| 824 |
+
app = create_app()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
projects/focusfriend/app.py
CHANGED
|
@@ -1051,16 +1051,7 @@ def create_app() -> gr.Blocks:
|
|
| 1051 |
|
| 1052 |
|
| 1053 |
# ---------------------------------------------------------------------------
|
| 1054 |
-
# Entry point
|
| 1055 |
# ---------------------------------------------------------------------------
|
| 1056 |
-
|
| 1057 |
-
|
| 1058 |
-
|
| 1059 |
-
server_name="0.0.0.0",
|
| 1060 |
-
server_port=int(os.environ.get("PORT", "7861")),
|
| 1061 |
-
share=False,
|
| 1062 |
-
show_error=True,
|
| 1063 |
-
mcp_server=True,
|
| 1064 |
-
css=FOCUSFRIEND_CSS,
|
| 1065 |
-
head=FOCUSFRIEND_JS,
|
| 1066 |
-
)
|
|
|
|
| 1051 |
|
| 1052 |
|
| 1053 |
# ---------------------------------------------------------------------------
|
|
|
|
| 1054 |
# ---------------------------------------------------------------------------
|
| 1055 |
+
# Entry point — exported for HF Spaces Gradio SDK
|
| 1056 |
+
# ---------------------------------------------------------------------------
|
| 1057 |
+
app = create_app()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
projects/tinybard/app.py
CHANGED
|
@@ -516,14 +516,6 @@ fastapi_app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="stati
|
|
| 516 |
gradio_blocks = create_gradio_app()
|
| 517 |
mount_gradio_app(fastapi_app, gradio_blocks, path="/gradio")
|
| 518 |
|
| 519 |
-
#
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
if __name__ == "__main__":
|
| 523 |
-
import uvicorn
|
| 524 |
-
port = int(os.environ.get("PORT", "7860"))
|
| 525 |
-
log.info(f"Starting TinyBard on port {port}")
|
| 526 |
-
log.info(f"Frontend: http://localhost:{port}/")
|
| 527 |
-
log.info(f"Gradio API: http://localhost:{port}/gradio/")
|
| 528 |
-
log.info(f"MCP schema: http://localhost:{port}/gradio/gradio_api/mcp/schema")
|
| 529 |
-
uvicorn.run(fastapi_app, host="0.0.0.0", port=port)
|
|
|
|
| 516 |
gradio_blocks = create_gradio_app()
|
| 517 |
mount_gradio_app(fastapi_app, gradio_blocks, path="/gradio")
|
| 518 |
|
| 519 |
+
# Export app for HF Spaces Gradio SDK / uvicorn
|
| 520 |
+
app = fastapi_app
|
| 521 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|