bep40 commited on
Commit
da8757c
·
verified ·
1 Parent(s): 510f4b7

Add restore runner for b9b6ba4

Browse files
Files changed (1) hide show
  1. restore_b9b6ba4_runner.py +34 -0
restore_b9b6ba4_runner.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ from huggingface_hub import snapshot_download
4
+
5
+ REVISION = os.environ.get("VNEWS_RESTORE_REVISION", "b9b6ba4")
6
+ REPO_ID = os.environ.get("VNEWS_REPO_ID", "bep40/vnews")
7
+
8
+ snapshot_dir = snapshot_download(
9
+ repo_id=REPO_ID,
10
+ repo_type="space",
11
+ revision=REVISION,
12
+ local_dir="/tmp/vnews_restore_b9b6ba4",
13
+ local_dir_use_symlinks=False,
14
+ )
15
+
16
+ os.chdir(snapshot_dir)
17
+ sys.path.insert(0, snapshot_dir)
18
+
19
+ # Prefer the app module used by that revision if present.
20
+ # Try ai_runtime first, then ai_patch, then main.
21
+ candidates = ["ai_runtime:app", "ai_patch:app", "main:app"]
22
+ for target in candidates:
23
+ mod, obj = target.split(":")
24
+ try:
25
+ __import__(mod)
26
+ app_target = target
27
+ break
28
+ except Exception:
29
+ app_target = None
30
+
31
+ if not app_target:
32
+ app_target = "main:app"
33
+
34
+ os.execvp("uvicorn", ["uvicorn", app_target, "--host", "0.0.0.0", "--port", "7860"])