Spaces:
Sleeping
Sleeping
Fix: Set writable cache directory for model download
Browse files- src/download_models.py +21 -7
src/download_models.py
CHANGED
|
@@ -2,10 +2,16 @@
|
|
| 2 |
import os
|
| 3 |
from huggingface_hub import snapshot_download
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
|
|
|
| 9 |
MODEL_STORAGE_PATH = "/data/models"
|
| 10 |
|
| 11 |
# Daftar model yang akan diunduh
|
|
@@ -27,18 +33,26 @@ def main():
|
|
| 27 |
# Tentukan direktori tujuan untuk model ini
|
| 28 |
local_dir_path = os.path.join(MODEL_STORAGE_PATH, model_key)
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
try:
|
| 31 |
-
#
|
|
|
|
| 32 |
snapshot_download(
|
| 33 |
repo_id=model_id,
|
| 34 |
local_dir=local_dir_path,
|
| 35 |
-
local_dir_use_symlinks=False,
|
| 36 |
-
resume_download=True
|
| 37 |
)
|
| 38 |
print(f"---> {model_key.upper()} berhasil diunduh ke {local_dir_path}")
|
| 39 |
except Exception as e:
|
| 40 |
print(f"[ERROR] Gagal mengunduh {model_key.upper()}: {e}")
|
| 41 |
-
# Kita
|
|
|
|
| 42 |
pass
|
| 43 |
|
| 44 |
print("\n==================================================")
|
|
|
|
| 2 |
import os
|
| 3 |
from huggingface_hub import snapshot_download
|
| 4 |
|
| 5 |
+
# --- Perbaikan Kunci: Atur HF_HOME secara eksplisit ---
|
| 6 |
+
# Ini memberitahu pustaka huggingface untuk menggunakan /data/.cache sebagai
|
| 7 |
+
# folder cache, yang berada di dalam persistent storage yang bisa kita tulis.
|
| 8 |
+
cache_dir = "/data/.cache"
|
| 9 |
+
os.environ['HF_HOME'] = cache_dir
|
| 10 |
+
os.makedirs(cache_dir, exist_ok=True)
|
| 11 |
+
print(f"Hugging Face home/cache directory set to: {os.environ['HF_HOME']}")
|
| 12 |
|
| 13 |
+
|
| 14 |
+
# Path utama untuk menyimpan model final
|
| 15 |
MODEL_STORAGE_PATH = "/data/models"
|
| 16 |
|
| 17 |
# Daftar model yang akan diunduh
|
|
|
|
| 33 |
# Tentukan direktori tujuan untuk model ini
|
| 34 |
local_dir_path = os.path.join(MODEL_STORAGE_PATH, model_key)
|
| 35 |
|
| 36 |
+
# Periksa apakah model sudah ada untuk menghemat waktu saat restart
|
| 37 |
+
# Kita periksa keberadaan config.json sebagai penanda
|
| 38 |
+
if os.path.exists(os.path.join(local_dir_path, "config.json")):
|
| 39 |
+
print(f"---> Model {model_key.upper()} sudah ada. Melewati unduhan.")
|
| 40 |
+
continue
|
| 41 |
+
|
| 42 |
try:
|
| 43 |
+
# Fungsi snapshot_download akan secara otomatis menggunakan
|
| 44 |
+
# variabel lingkungan HF_HOME yang telah kita atur untuk cache.
|
| 45 |
snapshot_download(
|
| 46 |
repo_id=model_id,
|
| 47 |
local_dir=local_dir_path,
|
| 48 |
+
local_dir_use_symlinks=False,
|
| 49 |
+
resume_download=True
|
| 50 |
)
|
| 51 |
print(f"---> {model_key.upper()} berhasil diunduh ke {local_dir_path}")
|
| 52 |
except Exception as e:
|
| 53 |
print(f"[ERROR] Gagal mengunduh {model_key.upper()}: {e}")
|
| 54 |
+
# Kita biarkan skrip berlanjut jika satu model gagal,
|
| 55 |
+
# agar tidak menghentikan seluruh proses build.
|
| 56 |
pass
|
| 57 |
|
| 58 |
print("\n==================================================")
|