VictorM-Coder commited on
Commit
344cbaa
·
verified ·
1 Parent(s): 46d3fde

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -18
app.py CHANGED
@@ -1,21 +1,27 @@
1
- import os
2
-
3
- # ============================================================
4
- # ✅ FIX FOR "state dict corrupted" ON SPACES (Xet downloads)
5
- # ============================================================
6
- # Disable hf-xet usage (forces download via LFS bridge instead).
7
- # HF docs: HF_HUB_DISABLE_XET disables using hf-xet. :contentReference[oaicite:2]{index=2}
8
- os.environ["HF_HUB_DISABLE_XET"] = "1"
9
-
10
- # Optional: place HF cache in a writable/temp location (Spaces friendly)
11
- # You can comment this out if you prefer default cache locations.
12
- os.environ.setdefault("HF_HOME", "/tmp/hf")
13
- os.environ.setdefault("HUGGINGFACE_HUB_CACHE", "/tmp/hf/hub")
14
- os.environ.setdefault("TRANSFORMERS_CACHE", "/tmp/hf/transformers")
15
-
16
- # (Optional) reduce parallelism issues
17
- os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
18
-
 
 
 
 
 
 
19
 
20
  import re
21
  import shutil
 
1
+ import os, shutil, glob
2
+
3
+ # Put HF caches somewhere "fresh" (avoid reusing an old corrupt cache)
4
+ os.environ["HF_HOME"] = "/tmp/hf"
5
+ os.environ["HUGGINGFACE_HUB_CACHE"] = "/tmp/hf/hub"
6
+ os.environ["TRANSFORMERS_CACHE"] = "/tmp/hf/transformers"
7
+ os.environ["HF_HUB_DISABLE_XET"] = "1" # also avoids xet-related partial downloads
8
+ os.environ["TOKENIZERS_PARALLELISM"] = "false"
9
+
10
+ def wipe_model_cache(model_id: str):
11
+ safe = model_id.replace("/", "--")
12
+ paths = [
13
+ f"/tmp/hf/hub/models--{safe}",
14
+ f"/tmp/hf/transformers/models--{safe}",
15
+ # also wipe common defaults in case something else wrote there
16
+ os.path.expanduser(f"~/.cache/huggingface/hub/models--{safe}"),
17
+ os.path.expanduser(f"~/.cache/huggingface/transformers/models--{safe}"),
18
+ ]
19
+ for p in paths:
20
+ if os.path.exists(p):
21
+ shutil.rmtree(p, ignore_errors=True)
22
+
23
+ # wipe the specific model cache on startup
24
+ wipe_model_cache("desklib/ai-text-detector-v1.01")
25
 
26
  import re
27
  import shutil