Spaces:
Sleeping
Sleeping
ibcplateformes Claude Opus 4.6 commited on
Commit ·
7a237b9
1
Parent(s): 80d0f11
Pin starlette<0.38.0 to fix TemplateResponse API incompatibility
Browse filesThe root cause of the jinja2 crashes was a starlette version mismatch:
newer starlette changed TemplateResponse(name, context) signature to
TemplateResponse(request, name, context), causing the context dict to
be passed as the template name. Pinning starlette fixes this.
Also removed the now-unnecessary jinja2 LRU cache patch.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- app.py +0 -52
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -9,58 +9,6 @@ import logging
|
|
| 9 |
import tempfile
|
| 10 |
import shutil
|
| 11 |
|
| 12 |
-
# ── Patch jinja2 LRU cache BEFORE importing gradio ──────────────────────────
|
| 13 |
-
# Gradio 4.44.0 has a bug where component JSON schemas with
|
| 14 |
-
# `additionalProperties: true` (a bool) corrupt gradio's internal state,
|
| 15 |
-
# causing jinja2's LRU cache to receive unhashable keys (dicts/lists).
|
| 16 |
-
# We patch jinja2's LRUCache to treat unhashable keys as cache misses
|
| 17 |
-
# instead of crashing the entire app.
|
| 18 |
-
try:
|
| 19 |
-
import jinja2.utils as _j2utils
|
| 20 |
-
|
| 21 |
-
_OrigLRUCache = _j2utils.LRUCache
|
| 22 |
-
|
| 23 |
-
class _SafeLRUCache(_OrigLRUCache):
|
| 24 |
-
def __getitem__(self, key):
|
| 25 |
-
try:
|
| 26 |
-
return super().__getitem__(key)
|
| 27 |
-
except TypeError:
|
| 28 |
-
raise KeyError(key)
|
| 29 |
-
|
| 30 |
-
def get(self, key, default=None):
|
| 31 |
-
try:
|
| 32 |
-
return super().get(key, default)
|
| 33 |
-
except TypeError:
|
| 34 |
-
return default
|
| 35 |
-
|
| 36 |
-
def __setitem__(self, key, value):
|
| 37 |
-
try:
|
| 38 |
-
super().__setitem__(key, value)
|
| 39 |
-
except TypeError:
|
| 40 |
-
pass # Skip caching for unhashable keys
|
| 41 |
-
|
| 42 |
-
def __contains__(self, key):
|
| 43 |
-
try:
|
| 44 |
-
return super().__contains__(key)
|
| 45 |
-
except TypeError:
|
| 46 |
-
return False
|
| 47 |
-
|
| 48 |
-
_j2utils.LRUCache = _SafeLRUCache
|
| 49 |
-
|
| 50 |
-
# Also patch any already-created Environment caches
|
| 51 |
-
import jinja2.environment
|
| 52 |
-
_OrigEnvInit = jinja2.environment.Environment.__init__
|
| 53 |
-
|
| 54 |
-
def _patched_env_init(self, *args, **kwargs):
|
| 55 |
-
_OrigEnvInit(self, *args, **kwargs)
|
| 56 |
-
if isinstance(self.cache, _OrigLRUCache) and not isinstance(self.cache, _SafeLRUCache):
|
| 57 |
-
old_cap = self.cache.capacity
|
| 58 |
-
self.cache = _SafeLRUCache(old_cap)
|
| 59 |
-
|
| 60 |
-
jinja2.environment.Environment.__init__ = _patched_env_init
|
| 61 |
-
except Exception:
|
| 62 |
-
pass
|
| 63 |
-
|
| 64 |
import gradio as gr
|
| 65 |
|
| 66 |
# ── Monkey-patch gradio_client schema parsing bugs ──────────────────────────
|
|
|
|
| 9 |
import tempfile
|
| 10 |
import shutil
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
import gradio as gr
|
| 13 |
|
| 14 |
# ── Monkey-patch gradio_client schema parsing bugs ──────────────────────────
|
requirements.txt
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# Gradio + HuggingFace
|
| 2 |
gradio==4.44.0
|
|
|
|
| 3 |
spaces
|
| 4 |
huggingface_hub>=0.23.0
|
| 5 |
|
|
|
|
| 1 |
# Gradio + HuggingFace
|
| 2 |
gradio==4.44.0
|
| 3 |
+
starlette<0.38.0
|
| 4 |
spaces
|
| 5 |
huggingface_hub>=0.23.0
|
| 6 |
|