Download restore_workspace.py from ummmar/cloudcode: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/ummmar/cloudcode/resolve/main/restore_workspace.py
- Command line
-
hf download hf://spaces/ummmar/cloudcode/restore_workspace.py
-
curl -L -o restore_workspace.py https://huggingface.co/spaces/ummmar/cloudcode/resolve/main/restore_workspace.py
1.09 kB
| import os, shutil | |
| from huggingface_hub import snapshot_download | |
| TOKEN = os.getenv("MY_HF_TOKEN") | |
| DATASET = os.getenv("HF_DATASET_REPO") | |
| CONFIG_DIR = "/workspace/config" | |
| DATA_DIR = "/workspace/data" | |
| PROJECTS_DIR = "/workspace/projects" | |
| for d in [CONFIG_DIR, DATA_DIR, PROJECTS_DIR]: | |
| os.makedirs(d, exist_ok=True) | |
| if not TOKEN or not DATASET: | |
| print("⏭️ Restore skipped.") | |
| exit(0) | |
| try: | |
| print("⬇️ Restoring config & sessions...") | |
| snapshot_download( | |
| repo_id=DATASET, repo_type="dataset", | |
| local_dir="/tmp/ws_restore", token=TOKEN | |
| ) | |
| # Restore config/ and sessions/ subdirs from dataset | |
| for subdir, target in [("config", CONFIG_DIR), ("sessions", DATA_DIR)]: | |
| src = os.path.join("/tmp/ws_restore", subdir) | |
| if os.path.exists(src): | |
| if os.path.exists(target): | |
| shutil.rmtree(target) | |
| shutil.copytree(src, target) | |
| print(f"✅ {subdir} restored.") | |
| except Exception as e: | |
| print(f"⏭️ Fresh start: {e}") | |
| finally: | |
| shutil.rmtree("/tmp/ws_restore", ignore_errors=True) |