Spaces:
Running
Running
kovacsvi
commited on
Commit
·
b1b87fb
1
Parent(s):
04d7b9c
hf http cache cleanup
Browse files
app.py
CHANGED
@@ -15,7 +15,7 @@ from interfaces.emotion9 import demo as e9_demo
|
|
15 |
from interfaces.cap_media_demo import demo as cap_media_demo
|
16 |
from interfaces.cap_media2 import demo as cap_media2_demo
|
17 |
from interfaces.cap_minor_media import demo as cap_minor_media_demo
|
18 |
-
from utils import download_hf_models, df_h, set_hf_cache_dir, scan_cache
|
19 |
|
20 |
|
21 |
|
@@ -54,10 +54,12 @@ with gr.Blocks(css=css) as demo:
|
|
54 |
|
55 |
if __name__ == "__main__":
|
56 |
set_hf_cache_dir("/data")
|
|
|
57 |
df_h() # debug -> check disk space before launching demo - TO-DO: smarter disk space usage
|
58 |
scan_cache()
|
59 |
download_spacy_models()
|
60 |
download_hf_models() # does this affect the build?
|
|
|
61 |
demo.launch()
|
62 |
|
63 |
# TODO: add all languages & domains
|
|
|
15 |
from interfaces.cap_media_demo import demo as cap_media_demo
|
16 |
from interfaces.cap_media2 import demo as cap_media2_demo
|
17 |
from interfaces.cap_minor_media import demo as cap_minor_media_demo
|
18 |
+
from utils import download_hf_models, hf_cleanup, df_h, set_hf_cache_dir, scan_cache
|
19 |
|
20 |
|
21 |
|
|
|
54 |
|
55 |
if __name__ == "__main__":
|
56 |
set_hf_cache_dir("/data")
|
57 |
+
hf_cleanup()
|
58 |
df_h() # debug -> check disk space before launching demo - TO-DO: smarter disk space usage
|
59 |
scan_cache()
|
60 |
download_spacy_models()
|
61 |
download_hf_models() # does this affect the build?
|
62 |
+
hf_cleanup()
|
63 |
demo.launch()
|
64 |
|
65 |
# TODO: add all languages & domains
|
utils.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import os
|
2 |
import shutil
|
|
|
3 |
import subprocess
|
4 |
|
5 |
import torch
|
@@ -114,6 +115,15 @@ def df_h():
|
|
114 |
print("=== Disk Usage for /data/ (du -h --max-depth=2) ===")
|
115 |
print(du_result.stdout)
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
def scan_cache():
|
118 |
# Scan Hugging Face model cache
|
119 |
cache_dir = os.environ.get("TRANSFORMERS_CACHE", os.path.expanduser("~/.cache/huggingface/transformers"))
|
|
|
1 |
import os
|
2 |
import shutil
|
3 |
+
import glob
|
4 |
import subprocess
|
5 |
|
6 |
import torch
|
|
|
115 |
print("=== Disk Usage for /data/ (du -h --max-depth=2) ===")
|
116 |
print(du_result.stdout)
|
117 |
|
118 |
+
|
119 |
+
def hf_cleanup():
|
120 |
+
http_folders = glob.glob("/data/http*")
|
121 |
+
for folder in http_folders:
|
122 |
+
if os.path.isdir(folder):
|
123 |
+
print(f"Deleting: {folder}")
|
124 |
+
shutil.rmtree(folder)
|
125 |
+
|
126 |
+
|
127 |
def scan_cache():
|
128 |
# Scan Hugging Face model cache
|
129 |
cache_dir = os.environ.get("TRANSFORMERS_CACHE", os.path.expanduser("~/.cache/huggingface/transformers"))
|