Spaces:
Running
Running
kovacsvi
commited on
Commit
·
3f77878
1
Parent(s):
b1b87fb
hf cleanup as context
Browse files
app.py
CHANGED
@@ -18,7 +18,6 @@ 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 |
-
|
22 |
css = """
|
23 |
/* Make only the active tab bold */
|
24 |
.svelte-1uw5tnk[aria-selected="true"] {
|
@@ -54,12 +53,11 @@ with gr.Blocks(css=css) as demo:
|
|
54 |
|
55 |
if __name__ == "__main__":
|
56 |
set_hf_cache_dir("/data")
|
57 |
-
hf_cleanup()
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
hf_cleanup()
|
63 |
demo.launch()
|
64 |
|
65 |
# TODO: add all languages & domains
|
|
|
18 |
from utils import download_hf_models, hf_cleanup, df_h, set_hf_cache_dir, scan_cache
|
19 |
|
20 |
|
|
|
21 |
css = """
|
22 |
/* Make only the active tab bold */
|
23 |
.svelte-1uw5tnk[aria-selected="true"] {
|
|
|
53 |
|
54 |
if __name__ == "__main__":
|
55 |
set_hf_cache_dir("/data")
|
56 |
+
with hf_cleanup():
|
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
|
utils.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
import shutil
|
3 |
import glob
|
4 |
import subprocess
|
|
|
5 |
|
6 |
import torch
|
7 |
|
@@ -116,12 +117,21 @@ def df_h():
|
|
116 |
print(du_result.stdout)
|
117 |
|
118 |
|
119 |
-
def
|
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():
|
|
|
2 |
import shutil
|
3 |
import glob
|
4 |
import subprocess
|
5 |
+
from contextlib import contextmanager
|
6 |
|
7 |
import torch
|
8 |
|
|
|
117 |
print(du_result.stdout)
|
118 |
|
119 |
|
120 |
+
def delete_http_folders():
|
121 |
http_folders = glob.glob("/data/http*")
|
122 |
for folder in http_folders:
|
123 |
if os.path.isdir(folder):
|
124 |
print(f"Deleting: {folder}")
|
125 |
shutil.rmtree(folder)
|
126 |
+
|
127 |
+
|
128 |
+
@contextmanager
|
129 |
+
def hf_cleanup():
|
130 |
+
delete_http_folders()
|
131 |
+
try:
|
132 |
+
yield
|
133 |
+
finally:
|
134 |
+
delete_http_folders()
|
135 |
|
136 |
|
137 |
def scan_cache():
|