gabejavitt commited on
Commit
90e745d
·
verified ·
1 Parent(s): bc1a487

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -12,22 +12,6 @@ Improvements:
12
  import gc
13
  import os
14
  import io
15
-
16
- # Workaround: Gradio 5.x bug where Queue.pending_message_lock stays None if the
17
- # ASGI lifespan startup events don't fire (a Python 3.13 asyncio compatibility issue).
18
- # Patch Queue.push to lazily initialize the lock before its first use.
19
- try:
20
- import asyncio as _asyncio
21
- from gradio.queueing import Queue as _GradioQueue
22
- _orig_push = _GradioQueue.push
23
- async def _patched_push(self, *args, **kwargs):
24
- if getattr(self, "pending_message_lock", None) is None:
25
- self.pending_message_lock = _asyncio.Lock()
26
- return await _orig_push(self, *args, **kwargs)
27
- _GradioQueue.push = _patched_push
28
- print("✅ Applied Gradio queue lock workaround")
29
- except Exception as _patch_err:
30
- print(f"ℹ️ Gradio queue patch skipped: {_patch_err}")
31
  import subprocess
32
  import json
33
  import re
@@ -41,6 +25,23 @@ from pathlib import Path
41
  from collections import Counter, defaultdict
42
  from functools import wraps, lru_cache
43
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  import pandas as pd
45
  import numpy as np
46
  import torch
 
12
  import gc
13
  import os
14
  import io
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  import subprocess
16
  import json
17
  import re
 
25
  from collections import Counter, defaultdict
26
  from functools import wraps, lru_cache
27
  import gradio as gr
28
+
29
+ # Workaround: Gradio 5.x/6.x bug where Queue.pending_message_lock stays None if the
30
+ # ASGI lifespan startup events don't fire (Python 3.13 asyncio compatibility issue).
31
+ # Must be patched AFTER gradio is fully imported.
32
+ try:
33
+ import asyncio as _asyncio
34
+ from gradio.queueing import Queue as _GradioQueue
35
+ _orig_push = _GradioQueue.push
36
+ async def _patched_push(self, *args, **kwargs):
37
+ if getattr(self, "pending_message_lock", None) is None:
38
+ self.pending_message_lock = _asyncio.Lock()
39
+ return await _orig_push(self, *args, **kwargs)
40
+ _GradioQueue.push = _patched_push
41
+ print("✅ Applied Gradio queue lock workaround")
42
+ except Exception as _patch_err:
43
+ print(f"ℹ️ Gradio queue patch skipped: {_patch_err}")
44
+
45
  import pandas as pd
46
  import numpy as np
47
  import torch