Spaces:
Sleeping
Sleeping
| import os | |
| import subprocess | |
| import tempfile | |
| import shutil | |
| BACKUP_REPO = os.environ.get("BACKUP_REPO") | |
| HF_TOKEN = os.environ.get("HF_TOKEN") | |
| if not BACKUP_REPO or not HF_TOKEN: | |
| print("[Restore] Skipping: BACKUP_REPO or HF_TOKEN not set") | |
| exit(0) | |
| env = os.environ.copy() | |
| env["HF_HOME"] = "/tmp/hf_cache" | |
| env["XDG_CACHE_HOME"] = "/tmp/xdg_cache" | |
| env["TMPDIR"] = "/tmp" | |
| env["HF_TOKEN"] = HF_TOKEN | |
| os.makedirs(env["HF_HOME"], exist_ok=True) | |
| os.makedirs(env["XDG_CACHE_HOME"], exist_ok=True) | |
| os.makedirs(env["TMPDIR"], exist_ok=True) | |
| subprocess.run( | |
| ["hf", "download", BACKUP_REPO, "--repo-type", "dataset", "--local-dir", "/home/vscode", "--force", "--exclude", ".gitattributes", "--exclude", "*.md"], | |
| check=True, | |
| env=env, | |
| ) | |
| print("[Restore] Completed") | |