ummmar commited on
Commit
d1c760f
·
verified ·
1 Parent(s): 223a9a6

Update restore_workspace.py

Browse files
Files changed (1) hide show
  1. restore_workspace.py +16 -19
restore_workspace.py CHANGED
@@ -4,34 +4,31 @@ from huggingface_hub import snapshot_download
4
  TOKEN = os.getenv("MY_HF_TOKEN")
5
  DATASET = os.getenv("HF_DATASET_REPO")
6
  CONFIG_DIR = "/workspace/config"
 
7
  PROJECTS_DIR = "/workspace/projects"
8
 
9
- os.makedirs(CONFIG_DIR, exist_ok=True)
10
- os.makedirs(PROJECTS_DIR, exist_ok=True)
11
 
12
  if not TOKEN or not DATASET:
13
- print("⏭️ Restore skipped: MY_HF_TOKEN or HF_DATASET_REPO not set.")
14
  exit(0)
15
 
16
  try:
17
- print("⬇️ Restoring config from HF Dataset...")
18
  snapshot_download(
19
  repo_id=DATASET, repo_type="dataset",
20
- local_dir="/tmp/config_restore", token=TOKEN
21
  )
22
- # Only restore config dir, NOT projects
23
- if os.path.exists("/tmp/config_restore"):
24
- for item in os.listdir("/tmp/config_restore"):
25
- src = os.path.join("/tmp/config_restore", item)
26
- dst = os.path.join(CONFIG_DIR, item)
27
- if os.path.isdir(src):
28
- if os.path.exists(dst):
29
- shutil.rmtree(dst)
30
- shutil.copytree(src, dst)
31
- else:
32
- shutil.copy2(src, dst)
33
- print("✅ Config restored.")
34
  except Exception as e:
35
- print(f"⏭️ Fresh config start: {e}")
36
  finally:
37
- shutil.rmtree("/tmp/config_restore", ignore_errors=True)
 
4
  TOKEN = os.getenv("MY_HF_TOKEN")
5
  DATASET = os.getenv("HF_DATASET_REPO")
6
  CONFIG_DIR = "/workspace/config"
7
+ DATA_DIR = "/workspace/data"
8
  PROJECTS_DIR = "/workspace/projects"
9
 
10
+ for d in [CONFIG_DIR, DATA_DIR, PROJECTS_DIR]:
11
+ os.makedirs(d, exist_ok=True)
12
 
13
  if not TOKEN or not DATASET:
14
+ print("⏭️ Restore skipped.")
15
  exit(0)
16
 
17
  try:
18
+ print("⬇️ Restoring config & sessions...")
19
  snapshot_download(
20
  repo_id=DATASET, repo_type="dataset",
21
+ local_dir="/tmp/ws_restore", token=TOKEN
22
  )
23
+ # Restore config/ and sessions/ subdirs from dataset
24
+ for subdir, target in [("config", CONFIG_DIR), ("sessions", DATA_DIR)]:
25
+ src = os.path.join("/tmp/ws_restore", subdir)
26
+ if os.path.exists(src):
27
+ if os.path.exists(target):
28
+ shutil.rmtree(target)
29
+ shutil.copytree(src, target)
30
+ print(f"✅ {subdir} restored.")
 
 
 
 
31
  except Exception as e:
32
+ print(f"⏭️ Fresh start: {e}")
33
  finally:
34
+ shutil.rmtree("/tmp/ws_restore", ignore_errors=True)