SpaceNugget commited on
Commit
7fea3ce
·
1 Parent(s): 9c97c10

fix: inject wsproto as uvicorn WebSocket backend, bypass broken websockets legacy

Browse files
Files changed (2) hide show
  1. app.py +14 -0
  2. requirements.txt +1 -1
app.py CHANGED
@@ -342,4 +342,18 @@ with gr.Blocks(title="Cloth Swap", theme=gr.themes.Soft()) as demo:
342
  outputs=[gate, main_app, error_msg],
343
  )
344
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
345
  demo.launch(show_error=True)
 
342
  outputs=[gate, main_app, error_msg],
343
  )
344
 
345
+ # The HF base image ships websockets v13+ which removed the legacy API that
346
+ # the installed uvicorn version uses. Redirect uvicorn's WebSocket backend to
347
+ # wsproto before demo.launch() triggers the import of uvicorn.protocols.websockets.auto.
348
+ import sys as _sys
349
+ from types import ModuleType as _ModuleType
350
+ _ws_auto = _ModuleType("uvicorn.protocols.websockets.auto")
351
+ _sys.modules["uvicorn.protocols.websockets.auto"] = _ws_auto
352
+ try:
353
+ from uvicorn.protocols.websockets.wsproto_impl import WSProtocol as _WSP
354
+ _ws_auto.AutoWebSocketsProtocol = _WSP
355
+ print("uvicorn → wsproto WebSocket backend active")
356
+ except Exception as _e:
357
+ print(f"WARNING: wsproto backend setup failed: {_e}")
358
+
359
  demo.launch(show_error=True)
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
  requests
2
  Pillow
3
  python-dotenv
4
- uvicorn>=0.30.0
 
1
  requests
2
  Pillow
3
  python-dotenv
4
+ wsproto