Spaces:
Running on Zero
Running on Zero
Keep models on attached storage when it is available
Browse files
app.py
CHANGED
|
@@ -6,6 +6,31 @@ Step 3: MusicGen medium writes a soundtrack and attaches it to the clip.
|
|
| 6 |
Step 4: a small planning model (Qwen2.5 1.5B) writes narration and decides when each line starts;
|
| 7 |
Kokoro speaks it, and it is mixed over the music.
|
| 8 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
import json
|
| 10 |
import random
|
| 11 |
import re
|
|
|
|
| 6 |
Step 4: a small planning model (Qwen2.5 1.5B) writes narration and decides when each line starts;
|
| 7 |
Kokoro speaks it, and it is mixed over the music.
|
| 8 |
"""
|
| 9 |
+
import os
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def _pick_model_store():
|
| 13 |
+
"""Keep downloaded models on the Space's attached storage, so restarts don't download them again.
|
| 14 |
+
Uses MODEL_STORE if that variable is set, else the first writable mount it finds."""
|
| 15 |
+
candidates = [os.environ.get("MODEL_STORE"), "/data", "/bucket", "/storage", "/mnt/bucket", "/mnt/data"]
|
| 16 |
+
for path in [c for c in candidates if c]:
|
| 17 |
+
try:
|
| 18 |
+
os.makedirs(os.path.join(path, "huggingface"), exist_ok=True)
|
| 19 |
+
probe = os.path.join(path, "huggingface", ".write_test")
|
| 20 |
+
open(probe, "w").close()
|
| 21 |
+
os.remove(probe)
|
| 22 |
+
return os.path.join(path, "huggingface")
|
| 23 |
+
except OSError:
|
| 24 |
+
continue
|
| 25 |
+
return None
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
_store = _pick_model_store()
|
| 29 |
+
if _store:
|
| 30 |
+
os.environ["HF_HOME"] = _store # Must be set before the Hugging Face libraries are imported
|
| 31 |
+
print("MODEL STORE:", _store or "none found, using the default temporary cache",
|
| 32 |
+
"| mounts seen:", [m for m in ("/data", "/bucket", "/storage", "/mnt") if os.path.isdir(m)], flush=True)
|
| 33 |
+
|
| 34 |
import json
|
| 35 |
import random
|
| 36 |
import re
|