File size: 1,086 Bytes
1dd14a3
 
 
ce2e318
1dd14a3
e3a9f69
d1c760f
e3a9f69
1dd14a3
d1c760f
 
8e5d423
 
d1c760f
ce2e318
 
1dd14a3
d1c760f
1dd14a3
ce2e318
d1c760f
1dd14a3
d1c760f
 
 
 
 
 
 
 
1dd14a3
d1c760f
1dd14a3
d1c760f
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
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)