bep40 commited on
Commit
4f67223
·
verified ·
1 Parent(s): a5363a4

Upload restore_runner.py

Browse files
Files changed (1) hide show
  1. restore_runner.py +17 -29
restore_runner.py CHANGED
@@ -1,31 +1,19 @@
1
- import os
2
- import sys
3
- import subprocess
4
- from huggingface_hub import snapshot_download
5
 
6
- REVISION = os.environ.get("VNEWS_RESTORE_REVISION", "bcaa2dc")
7
- REPO_ID = os.environ.get("VNEWS_REPO_ID", "bep40/vnews")
 
 
 
 
 
 
 
 
 
 
 
8
 
9
- # Download exact Space snapshot from Hugging Face Hub.
10
- # This avoids manually copying huge files from an old commit.
11
- snapshot_dir = snapshot_download(
12
- repo_id=REPO_ID,
13
- repo_type="space",
14
- revision=REVISION,
15
- local_dir="/tmp/vnews_restore",
16
- local_dir_use_symlinks=False,
17
- )
18
-
19
- os.chdir(snapshot_dir)
20
- sys.path.insert(0, snapshot_dir)
21
-
22
- # Commit bcaa2dc Dockerfile ran ai_patch:app.
23
- cmd = [
24
- "uvicorn",
25
- "ai_patch:app",
26
- "--host",
27
- "0.0.0.0",
28
- "--port",
29
- "7860",
30
- ]
31
- os.execvp(cmd[0], cmd)
 
1
+ """Emergency restore runner - reverts main.py to last known good state."""
2
+ import os, sys
 
 
3
 
4
+ def restore():
5
+ """Copy backup files back to main."""
6
+ backup_dir = os.path.join(os.path.dirname(__file__), 'backup')
7
+ if not os.path.isdir(backup_dir):
8
+ print("[restore] No backup dir found")
9
+ return
10
+ import shutil
11
+ for f in os.listdir(backup_dir):
12
+ src = os.path.join(backup_dir, f)
13
+ dst = os.path.join(os.path.dirname(__file__), f)
14
+ if os.path.isfile(src):
15
+ shutil.copy2(src, dst)
16
+ print(f"[restore] Restored {f}")
17
 
18
+ if __name__ == '__main__':
19
+ restore()