Andrew Gibbs commited on
Commit ·
df86e24
1
Parent(s): f1dd567
Fix port-7860 double-bind crash: attach the custom route to Gradio's own app instead of manually running a second server
Browse files- app.py +9 -6
- requirements.txt +0 -1
app.py
CHANGED
|
@@ -324,15 +324,18 @@ _SERVER_CARD = {
|
|
| 324 |
}
|
| 325 |
|
| 326 |
if __name__ == "__main__":
|
| 327 |
-
import uvicorn
|
| 328 |
-
from fastapi import FastAPI
|
| 329 |
from fastapi.responses import JSONResponse
|
| 330 |
|
| 331 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 332 |
|
| 333 |
-
@
|
| 334 |
async def server_card():
|
| 335 |
return JSONResponse(_SERVER_CARD)
|
| 336 |
|
| 337 |
-
|
| 338 |
-
uvicorn.run(fastapi_app, host="0.0.0.0", port=7860)
|
|
|
|
| 324 |
}
|
| 325 |
|
| 326 |
if __name__ == "__main__":
|
|
|
|
|
|
|
| 327 |
from fastapi.responses import JSONResponse
|
| 328 |
|
| 329 |
+
# Let Gradio create and bind its own server first (the same mechanism
|
| 330 |
+
# that already worked reliably) — then attach the custom route to that
|
| 331 |
+
# same app afterward. Manually building a second FastAPI app + uvicorn.run()
|
| 332 |
+
# here previously caused a real port-7860 double-bind crash on HF's
|
| 333 |
+
# infrastructure (Errno 98: address already in use) — confirmed via the
|
| 334 |
+
# Space's actual runtime error logs, not guessed.
|
| 335 |
+
demo.launch(mcp_server=True, prevent_thread_lock=True)
|
| 336 |
|
| 337 |
+
@demo.app.get("/.well-known/mcp/server-card.json")
|
| 338 |
async def server_card():
|
| 339 |
return JSONResponse(_SERVER_CARD)
|
| 340 |
|
| 341 |
+
demo.block_thread()
|
|
|
requirements.txt
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
gradio[mcp]>=5.0.0
|
| 2 |
requests
|
| 3 |
fastapi
|
| 4 |
-
uvicorn
|
|
|
|
| 1 |
gradio[mcp]>=5.0.0
|
| 2 |
requests
|
| 3 |
fastapi
|
|
|