Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -215,9 +215,28 @@ with gr.Blocks(title="SonicMaster – Text-Guided Restoration & Mastering", fill
|
|
| 215 |
concurrency_limit=1,
|
| 216 |
)
|
| 217 |
|
| 218 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
_ = get_weights_path()
|
| 220 |
_ = ensure_repo()
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
concurrency_limit=1,
|
| 216 |
)
|
| 217 |
|
| 218 |
+
# ---------- FastAPI mount with ClientDisconnect handler (Spaces-friendly) ----------
|
| 219 |
+
from fastapi import FastAPI, Request
|
| 220 |
+
from starlette.responses import PlainTextResponse
|
| 221 |
+
from starlette.requests import ClientDisconnect
|
| 222 |
+
import gradio as gr
|
| 223 |
+
|
| 224 |
+
# Warm up cache & repo (optional but nice)
|
| 225 |
_ = get_weights_path()
|
| 226 |
_ = ensure_repo()
|
| 227 |
+
|
| 228 |
+
app = FastAPI()
|
| 229 |
+
|
| 230 |
+
@app.exception_handler(ClientDisconnect)
|
| 231 |
+
async def client_disconnect_handler(request: Request, exc: ClientDisconnect):
|
| 232 |
+
# Treat as benign client cancel; avoids noisy tracebacks on Spaces
|
| 233 |
+
return PlainTextResponse("Client disconnected", status_code=499)
|
| 234 |
+
|
| 235 |
+
# Mount Gradio at root. Use queue if you were using it before.
|
| 236 |
+
app = gr.mount_gradio_app(app, demo.queue(max_size=16), path="/")
|
| 237 |
+
|
| 238 |
+
# Optional: allow local dev with `python app.py`
|
| 239 |
+
if __name__ == "__main__":
|
| 240 |
+
import uvicorn
|
| 241 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 242 |
+
|