johnisafridge commited on
Commit
52f78d8
·
verified ·
1 Parent(s): c12d71c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -0
app.py CHANGED
@@ -184,6 +184,19 @@ with gr.Blocks(css=css) as demo:
184
  [model_output_text, model_output_box, annotated_image],
185
  )
186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  # -------- Launch (Spaces-friendly) --------
188
  demo.queue().launch(
189
  server_name="0.0.0.0",
 
184
  [model_output_text, model_output_box, annotated_image],
185
  )
186
 
187
+ # ---- Make Gradio/Starlette error responses small & safe (no Content-Length drama) ----
188
+ from fastapi import Request
189
+ from starlette.responses import PlainTextResponse
190
+
191
+ app = demo.app # FastAPI app behind Gradio Blocks
192
+
193
+ @app.exception_handler(Exception)
194
+ async def _catch_all_exceptions(request: Request, exc: Exception):
195
+ # Return a very small body so Starlette/Uvicorn never miscounts bytes
196
+ return PlainTextResponse("Internal Server Error", status_code=500)
197
+ # --------------------------------------------------------------------------------------
198
+
199
+
200
  # -------- Launch (Spaces-friendly) --------
201
  demo.queue().launch(
202
  server_name="0.0.0.0",