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)