Spaces:
Running
Running
Jin Zhu
commited on
Commit
·
992f591
1
Parent(s):
f744179
Update app.py
Browse files- src/app.py +29 -0
src/app.py
CHANGED
|
@@ -28,6 +28,35 @@ if os.environ.get('SPACE_ID'):
|
|
| 28 |
streamlit_dir = Path('/tmp/.streamlit')
|
| 29 |
streamlit_dir.mkdir(exist_ok=True, parents=True)
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
import streamlit as st
|
| 32 |
from FineTune.model import ComputeScore
|
| 33 |
import time
|
|
|
|
| 28 |
streamlit_dir = Path('/tmp/.streamlit')
|
| 29 |
streamlit_dir.mkdir(exist_ok=True, parents=True)
|
| 30 |
|
| 31 |
+
# ======================================================
|
| 32 |
+
# ✅ 新增:在运行时从 Hugging Face 下载私有 model.py
|
| 33 |
+
# ======================================================
|
| 34 |
+
|
| 35 |
+
target_path = APP_DIR / "FineTune" / "model.py"
|
| 36 |
+
if not target_path.exists():
|
| 37 |
+
print(f"📥 Attempting to download private model.py to: {target_path}")
|
| 38 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 39 |
+
if not hf_token:
|
| 40 |
+
raise RuntimeError(
|
| 41 |
+
"❌ HF_TOKEN not found. Please configure it in Hugging Face Space → Settings → Secrets."
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
url = "https://huggingface.co/mamba413/ada-core/resolve/main/model.py"
|
| 45 |
+
headers = {"Authorization": f"Bearer {hf_token}"}
|
| 46 |
+
response = requests.get(url, headers=headers)
|
| 47 |
+
|
| 48 |
+
if response.status_code != 200:
|
| 49 |
+
raise RuntimeError(
|
| 50 |
+
f"❌ Failed to download model.py (HTTP {response.status_code}): {response.text[:200]}"
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
os.makedirs(target_path.parent, exist_ok=True)
|
| 54 |
+
with open(target_path, "wb") as f:
|
| 55 |
+
f.write(response.content)
|
| 56 |
+
print("✅ Successfully downloaded private model.py")
|
| 57 |
+
else:
|
| 58 |
+
print("✅ model.py already exists, skipping download.")
|
| 59 |
+
|
| 60 |
import streamlit as st
|
| 61 |
from FineTune.model import ComputeScore
|
| 62 |
import time
|