Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,27 @@
|
|
| 1 |
-
import os
|
| 2 |
-
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
os.environ["
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
os.
|
| 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
|