Spaces:
Runtime error
Runtime error
Update app.py
Browse files2βRuntime patch that really disables numba caching
Why the previous attempts still failed
NUMBA_DISABLE_CACHE=1 prevents writing to the on-disk cache,
but numba still creates a FunctionCache object.
In 0 .56 that creation raises if it canβt locate the source file.
So we need to patch Dispatcher.enable_caching() to a no-op before
UMAP (and therefore BERTopic) is imported.
app.py
CHANGED
@@ -1,22 +1,38 @@
|
|
1 |
# ---------- BEGIN app.py ----------
|
2 |
import os, sys, json, uuid
|
3 |
|
4 |
-
# ββ
|
5 |
-
|
6 |
-
print("ENV-snapshot:", json.dumps(dict(list(os.environ.items())[:20])))
|
7 |
sys.stdout.flush()
|
8 |
|
9 |
-
# ββ
|
10 |
-
os.environ
|
11 |
-
os.environ.setdefault("NUMBA_CACHE_DIR", "/tmp/numba") # fallback dir
|
12 |
os.makedirs(os.environ["NUMBA_CACHE_DIR"], exist_ok=True)
|
13 |
|
14 |
-
# ββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
from typing import List
|
16 |
from fastapi import FastAPI, HTTPException
|
17 |
from pydantic import BaseModel
|
18 |
from bertopic import BERTopic
|
19 |
from sentence_transformers import SentenceTransformer
|
|
|
|
|
|
|
20 |
|
21 |
# ββ 4. Configuration via env vars βββββββββββββββββββββββββββββββββββββββββββββ
|
22 |
MODEL_NAME = os.getenv("EMBED_MODEL", "Seznam/simcse-small-e-czech")
|
|
|
1 |
# ---------- BEGIN app.py ----------
|
2 |
import os, sys, json, uuid
|
3 |
|
4 |
+
# ββ 0. Quick env print β keep for now βββββββββββββββββββββββββββββββββββ
|
5 |
+
print("ENV-snapshot:", json.dumps(dict(list(os.environ.items())[:25])))
|
|
|
6 |
sys.stdout.flush()
|
7 |
|
8 |
+
# ββ 1. Safety: make a writable cache dir (still useful) ββββββββββββββββ
|
9 |
+
os.environ.setdefault("NUMBA_CACHE_DIR", "/tmp/numba_cache")
|
|
|
10 |
os.makedirs(os.environ["NUMBA_CACHE_DIR"], exist_ok=True)
|
11 |
|
12 |
+
# ββ 2. **Hard-patch numba** so enable_caching does nothing ββββββββββββ
|
13 |
+
try:
|
14 |
+
import numba
|
15 |
+
from numba.core import dispatcher
|
16 |
+
|
17 |
+
def _disable_cache(self):
|
18 |
+
"""Monkey-patch: skip creating FunctionCache altogether."""
|
19 |
+
return
|
20 |
+
|
21 |
+
dispatcher.Dispatcher.enable_caching = _disable_cache
|
22 |
+
os.environ["NUMBA_DISABLE_CACHE"] = "1" # belt & braces
|
23 |
+
except ImportError:
|
24 |
+
# numba isn't installed yet (first pip install) β safe to ignore
|
25 |
+
pass
|
26 |
+
|
27 |
+
# ββ 3. Heavy imports (UMAP, BERTopic) ββββββββββββββββββββββββββββββββββ
|
28 |
from typing import List
|
29 |
from fastapi import FastAPI, HTTPException
|
30 |
from pydantic import BaseModel
|
31 |
from bertopic import BERTopic
|
32 |
from sentence_transformers import SentenceTransformer
|
33 |
+
...
|
34 |
+
# ---------- rest of the file unchanged ----------
|
35 |
+
|
36 |
|
37 |
# ββ 4. Configuration via env vars βββββββββββββββββββββββββββββββββββββββββββββ
|
38 |
MODEL_NAME = os.getenv("EMBED_MODEL", "Seznam/simcse-small-e-czech")
|