Claude Claude Opus 5.5 commited on
Commit
bffb18c
·
unverified ·
1 Parent(s): 510a1f1

Fix start on Hugging Face: turn off Gradio SSR so its Node server doesn't take port 7860

Browse files

HF sets GRADIO_SSR_MODE=true; mount_gradio_app then starts Gradio's Node server on
GRADIO_SERVER_PORT (7860) and uvicorn failed with 'address already in use'. Also
read the port from GRADIO_SERVER_PORT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Eg7PDh5Nquz9zWpYMKwZBv

Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -214,9 +214,11 @@ def space_config():
214
  "api": "gradio", "slow": DEVICE == "cpu"})
215
 
216
 
217
- app = gr.mount_gradio_app(app, api, path="/gradio")
 
 
218
  app.mount("/", StaticFiles(directory=GAME, html=True), name="game")
219
 
220
  if __name__ == "__main__":
221
  import uvicorn
222
- uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", 7860)))
 
214
  "api": "gradio", "slow": DEVICE == "cpu"})
215
 
216
 
217
+ # ssr_mode=False: Hugging Face sets GRADIO_SSR_MODE=true, which would start Gradio's Node server on
218
+ # port 7860 itself, and then this server could not bind there ("address already in use").
219
+ app = gr.mount_gradio_app(app, api, path="/gradio", ssr_mode=False)
220
  app.mount("/", StaticFiles(directory=GAME, html=True), name="game")
221
 
222
  if __name__ == "__main__":
223
  import uvicorn
224
+ uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("GRADIO_SERVER_PORT") or os.environ.get("PORT") or 7860))