Spaces:
Running
Running
Restore to commit 60e310a - restore script
Browse files- restore.py +40 -0
restore.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Restore all files from commit 60e310a on HuggingFace Hub"""
|
| 2 |
+
import os, sys
|
| 3 |
+
|
| 4 |
+
def run():
|
| 5 |
+
try:
|
| 6 |
+
from huggingface_hub import HfApi, snapshot_download
|
| 7 |
+
except ImportError:
|
| 8 |
+
os.system(f"{sys.executable} -m pip install -q huggingface_hub")
|
| 9 |
+
from huggingface_hub import HfApi, snapshot_download
|
| 10 |
+
|
| 11 |
+
repo_id = "bep40/VNEWS"
|
| 12 |
+
revision = "60e310a"
|
| 13 |
+
target_dir = "/app"
|
| 14 |
+
|
| 15 |
+
print(f"[RESTORE] Downloading snapshot from {repo_id}@{revision}...", flush=True)
|
| 16 |
+
|
| 17 |
+
# Download to temp dir
|
| 18 |
+
import tempfile
|
| 19 |
+
tmpdir = tempfile.mkdtemp()
|
| 20 |
+
local_dir = snapshot_download(repo_id=repo_id, revision=revision, repo_type="space", local_dir=tmpdir)
|
| 21 |
+
|
| 22 |
+
print(f"[RESTORE] Downloaded to {local_dir}", flush=True)
|
| 23 |
+
|
| 24 |
+
# Copy files to /app (overwrite)
|
| 25 |
+
import shutil
|
| 26 |
+
for root, dirs, files in os.walk(local_dir):
|
| 27 |
+
for f in files:
|
| 28 |
+
src = os.path.join(root, f)
|
| 29 |
+
rel = os.path.relpath(src, local_dir)
|
| 30 |
+
dst = os.path.join(target_dir, rel)
|
| 31 |
+
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
| 32 |
+
shutil.copy2(src, dst)
|
| 33 |
+
print(f"[RESTORE] {rel}", flush=True)
|
| 34 |
+
|
| 35 |
+
# Cleanup
|
| 36 |
+
shutil.rmtree(tmpdir)
|
| 37 |
+
print(f"[RESTORE] Done! All files restored from {revision}", flush=True)
|
| 38 |
+
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
run()
|