Download sync_workspace.py from ummmar/cloudcode: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/ummmar/cloudcode/resolve/2e8869ecaa2bbd1e47ec58fe726524ae97c9bb68/sync_workspace.py
- Command line
-
hf download hf://spaces/ummmar/cloudcode@2e8869ecaa2bbd1e47ec58fe726524ae97c9bb68/sync_workspace.py
-
curl -L -o sync_workspace.py https://huggingface.co/spaces/ummmar/cloudcode/resolve/2e8869ecaa2bbd1e47ec58fe726524ae97c9bb68/sync_workspace.py
1.1 kB
| import os, time | |
| from huggingface_hub import HfApi | |
| TOKEN = os.getenv("MY_HF_TOKEN") | |
| DATASET = os.getenv("HF_DATASET_REPO") | |
| WORKSPACE = "/workspace/projects" | |
| if not TOKEN or not DATASET: | |
| print("⏭️ Sync skipped: MY_HF_TOKEN or HF_DATASET_REPO not set.") | |
| exit(0) | |
| # Pass token directly to HfApi instead of using global login() | |
| api = HfApi(token=TOKEN) | |
| try: | |
| api.create_repo(repo_id=DATASET, repo_type="dataset", private=True, exist_ok=True) | |
| print(f"✅ Dataset {DATASET} verified/created.") | |
| except Exception as e: | |
| print(f"❌ Dataset access failed: {e}") | |
| print(" Ensure MY_HF_TOKEN has WRITE permission and dataset name is correct.") | |
| exit(0) | |
| IGNORES = [ | |
| ".git", "node_modules", ".venv", "__pycache__", "dist", "build", | |
| "*.log", "*.tmp", "*.pyc", ".next", ".cache", "vendor", "target" | |
| ] | |
| while True: | |
| try: | |
| api.upload_folder( | |
| folder_path=WORKSPACE, repo_id=DATASET, repo_type="dataset", | |
| commit_message="Auto-sync", ignore_patterns=IGNORES | |
| ) | |
| except Exception as e: | |
| print(f"Sync failed: {e}") | |
| time.sleep(300) |