ambujm22 commited on
Commit
7108aaf
·
verified ·
1 Parent(s): 96d8a66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -4
app.py CHANGED
@@ -215,9 +215,28 @@ with gr.Blocks(title="SonicMaster – Text-Guided Restoration & Mastering", fill
215
  concurrency_limit=1,
216
  )
217
 
218
- # Warm up cache & repo, then launch
 
 
 
 
 
 
219
  _ = get_weights_path()
220
  _ = ensure_repo()
221
- demo.queue(max_size=16).launch()
222
- # Or, a global default for all events:
223
- # demo.queue(max_size=16, default_concurrency_limit=1).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+