Jin Zhu commited on
Commit
0ca4954
·
1 Parent(s): 9821888

Update app.py

Browse files
Files changed (1) hide show
  1. src/app.py +10 -4
src/app.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  from pathlib import Path
3
  import requests
 
4
 
5
  # -----------------
6
  # Get the directory where app.py is located
@@ -30,10 +31,11 @@ if os.environ.get('SPACE_ID'):
30
  streamlit_dir.mkdir(exist_ok=True, parents=True)
31
 
32
  # ======================================================
33
- # ✅ 新增:在运行时从 Hugging Face 下载私有 model.py
34
  # ======================================================
 
 
35
 
36
- target_path = APP_DIR / "FineTune" / "model.py"
37
  if not target_path.exists():
38
  print(f"📥 Attempting to download private model.py to: {target_path}")
39
  hf_token = os.getenv("HF_TOKEN")
@@ -51,12 +53,16 @@ if not target_path.exists():
51
  f"❌ Failed to download model.py (HTTP {response.status_code}): {response.text[:200]}"
52
  )
53
 
54
- os.makedirs(target_path.parent, exist_ok=True)
55
  with open(target_path, "wb") as f:
56
  f.write(response.content)
57
  print("✅ Successfully downloaded private model.py")
58
  else:
59
- print("✅ model.py already exists, skipping download.")
 
 
 
 
60
 
61
  import streamlit as st
62
  from FineTune.model import ComputeScore
 
1
  import os
2
  from pathlib import Path
3
  import requests
4
+ import sys
5
 
6
  # -----------------
7
  # Get the directory where app.py is located
 
31
  streamlit_dir.mkdir(exist_ok=True, parents=True)
32
 
33
  # ======================================================
34
+ # ✅ 新增:在运行时从 Hugging Face 下载私有 model.py(写入 /tmp)
35
  # ======================================================
36
+ target_dir = Path("/tmp/FineTune")
37
+ target_path = target_dir / "model.py"
38
 
 
39
  if not target_path.exists():
40
  print(f"📥 Attempting to download private model.py to: {target_path}")
41
  hf_token = os.getenv("HF_TOKEN")
 
53
  f"❌ Failed to download model.py (HTTP {response.status_code}): {response.text[:200]}"
54
  )
55
 
56
+ os.makedirs(target_dir, exist_ok=True)
57
  with open(target_path, "wb") as f:
58
  f.write(response.content)
59
  print("✅ Successfully downloaded private model.py")
60
  else:
61
+ print("✅ model.py already exists in /tmp, skipping download.")
62
+
63
+ # ✅ 添加 /tmp 到 Python 导入路径
64
+ if str(target_dir.parent) not in sys.path:
65
+ sys.path.insert(0, str(target_dir.parent))
66
 
67
  import streamlit as st
68
  from FineTune.model import ComputeScore