wenhanacademia commited on
Commit
ab9c854
·
verified ·
1 Parent(s): e90f6eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -1,25 +1,27 @@
1
- from huggingface_hub import snapshot_download
2
  import os
3
  import sys
 
 
 
 
 
4
 
5
- # =====================================
6
- # 0. Configuration
7
- # =====================================
8
- REPO_ID = "wenhanacademia/ai_paper_finder" # your private repo with DB + code
9
- HF_TOKEN = os.getenv("HF_TOKEN", "").strip() # set in Space Settings → Variables
10
- ENTRY_FILE = "app.py" # entry point inside that repo
11
 
12
- # =====================================
13
- # 1. Download private repo to runtime
14
- # =====================================
15
  print(f"Downloading repo {REPO_ID} ...")
16
  repo_dir = snapshot_download(repo_id=REPO_ID, token=HF_TOKEN)
 
17
 
18
- # =====================================
19
- # 2. Add to sys.path and execute app
20
- # =====================================
21
  sys.path.append(repo_dir)
22
- entry_path = os.path.join(repo_dir, ENTRY_FILE)
23
 
 
24
  print(f"Running {entry_path} ...")
25
- exec(open(entry_path).read())
 
 
 
 
1
  import os
2
  import sys
3
+ import datetime
4
+ import runpy
5
+ from huggingface_hub import snapshot_download
6
+
7
+ print(f"===== Application Startup at {datetime.datetime.now():%Y-%m-%d %H:%M:%S} =====")
8
 
9
+ # ---------------- CONFIG ----------------
10
+ REPO_ID = "wenhanacademia/ai_paper_finder" # private repo with full app + DB
11
+ HF_TOKEN = os.getenv("HF_TOKEN", "").strip() # stored as secret
12
+ ENTRY_FILE = "app.py" # entry point in that repo
13
+ # -----------------------------------------
 
14
 
 
 
 
15
  print(f"Downloading repo {REPO_ID} ...")
16
  repo_dir = snapshot_download(repo_id=REPO_ID, token=HF_TOKEN)
17
+ print(f"Repo downloaded to: {repo_dir}")
18
 
19
+ # Change to the repo directory so relative paths work
20
+ os.chdir(repo_dir)
 
21
  sys.path.append(repo_dir)
 
22
 
23
+ entry_path = os.path.join(repo_dir, ENTRY_FILE)
24
  print(f"Running {entry_path} ...")
25
+
26
+ # Execute your repo’s real app in its own context
27
+ runpy.run_path(entry_path, run_name="__main__")