File size: 1,104 Bytes
845f96d
4740fdd
845f96d
92ba885
4740fdd
 
 
 
 
92ba885
 
4740fdd
 
845f96d
4740fdd
 
 
 
 
 
 
845f96d
 
 
 
 
 
 
 
 
 
 
 
 
 
92ba885
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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)