Spaces:
Running
Running
Jin Zhu
commited on
Commit
·
e23375b
1
Parent(s):
a0edf7a
update code
Browse files- requirements.txt +2 -1
- src/app.py +12 -0
requirements.txt
CHANGED
|
@@ -7,4 +7,5 @@ numpy==2.1.3
|
|
| 7 |
transformers==4.55.2
|
| 8 |
peft==0.17.1
|
| 9 |
tqdm
|
| 10 |
-
scikit-learn
|
|
|
|
|
|
| 7 |
transformers==4.55.2
|
| 8 |
peft==0.17.1
|
| 9 |
tqdm
|
| 10 |
+
scikit-learn
|
| 11 |
+
huggingface_hub
|
src/app.py
CHANGED
|
@@ -28,6 +28,18 @@ def load_model(from_pretrained, base_model, cache_dir, device):
|
|
| 28 |
cache_dir = str(Path.home() / '.cache' / 'huggingface')
|
| 29 |
device = 'cpu'
|
| 30 |
print("Using **CPU** now!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
else:
|
| 32 |
cache_dir = cache_dir
|
| 33 |
with st.spinner("🔄 Loading model... This may take a moment on first launch."):
|
|
|
|
| 28 |
cache_dir = str(Path.home() / '.cache' / 'huggingface')
|
| 29 |
device = 'cpu'
|
| 30 |
print("Using **CPU** now!")
|
| 31 |
+
|
| 32 |
+
# 获取 HF Token(用于访问 gated 模型)
|
| 33 |
+
hf_token = os.environ.get('HF_TOKEN', None)
|
| 34 |
+
if hf_token:
|
| 35 |
+
kwargs['token'] = hf_token
|
| 36 |
+
# 也可以用 login 方式
|
| 37 |
+
try:
|
| 38 |
+
from huggingface_hub import login
|
| 39 |
+
login(token=hf_token)
|
| 40 |
+
print("✅ Successfully authenticated with HF token")
|
| 41 |
+
except Exception as e:
|
| 42 |
+
print(f"⚠️ HF login warning: {e}")
|
| 43 |
else:
|
| 44 |
cache_dir = cache_dir
|
| 45 |
with st.spinner("🔄 Loading model... This may take a moment on first launch."):
|