Takosaga commited on
Commit
869f490
Β·
1 Parent(s): 19abb72

fix: export works again

Browse files
Files changed (1) hide show
  1. app.py +24 -26
app.py CHANGED
@@ -7,6 +7,30 @@ No backend connection β€” visual preview only.
7
  Run: uv sync && python app.py
8
  """
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  import logging
11
  import os
12
  from pathlib import Path
@@ -405,32 +429,6 @@ def _handle_export_apkg_stub():
405
 
406
 
407
  if __name__ == "__main__":
408
- # ─── Disable Gradio's BrotliMiddleware ─────────────────────────
409
- # Gradio 6.x adds BrotliMiddleware which has a known bug with h11:
410
- # For streaming responses (generator yields), the middleware deletes
411
- # Content-Length and uses chunked transfer encoding, but h11 can
412
- # miscalculate content length from the first compressed chunk,
413
- # then reject subsequent chunks as "Too much data for declared
414
- # Content-Length". We disable it by replacing the class in routes.py
415
- # before build_ui() creates the Gradio app.
416
- try:
417
- import gradio.routes as _routes_mod
418
- from gradio.brotli_middleware import BrotliMiddleware
419
-
420
- class _PassthroughMiddleware:
421
- """Drop-in replacement that passes all requests through uncompressed."""
422
-
423
- def __init__(self, app, **kwargs):
424
- self.app = app
425
-
426
- async def __call__(self, scope, receive, send):
427
- await self.app(scope, receive, send)
428
-
429
- # Replace in routes.py's local namespace so create_app uses passthrough
430
- _routes_mod.BrotliMiddleware = _PassthroughMiddleware # type: ignore[assignment]
431
- except Exception:
432
- pass # Non-critical; app will work without this patch
433
-
434
  from frontend.ui.widgets import build_ui
435
 
436
  css_path = os.path.join(os.path.dirname(__file__), "frontend", "css", "custom.css")
 
7
  Run: uv sync && python app.py
8
  """
9
 
10
+ # ─── Disable Gradio's BrotliMiddleware BEFORE any other imports ────
11
+ # Gradio 6.x adds BrotliMiddleware which has a known bug with h11:
12
+ # For streaming responses (generator yields), the middleware deletes
13
+ # Content-Length and uses chunked transfer encoding, but h11 can
14
+ # miscalculate content length from the first compressed chunk,
15
+ # then reject subsequent chunks as "Too much data for declared
16
+ # Content-Length". We disable it by replacing the class in routes.py.
17
+ try:
18
+ import gradio.routes as _routes_mod
19
+ from gradio.brotli_middleware import BrotliMiddleware
20
+
21
+ class _PassthroughMiddleware:
22
+ """Drop-in replacement that passes all requests through uncompressed."""
23
+
24
+ def __init__(self, app, **kwargs):
25
+ self.app = app
26
+
27
+ async def __call__(self, scope, receive, send):
28
+ await self.app(scope, receive, send)
29
+
30
+ _routes_mod.BrotliMiddleware = _PassthroughMiddleware # type: ignore[assignment]
31
+ except Exception:
32
+ pass # Non-critical; app will work without this patch
33
+
34
  import logging
35
  import os
36
  from pathlib import Path
 
429
 
430
 
431
  if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
432
  from frontend.ui.widgets import build_ui
433
 
434
  css_path = os.path.join(os.path.dirname(__file__), "frontend", "css", "custom.css")