Spaces:
Sleeping
Sleeping
improve: simplify tocken use
Browse files- modules/ai_model.py +9 -30
modules/ai_model.py
CHANGED
|
@@ -33,36 +33,15 @@ class AIModel:
|
|
| 33 |
log.info(f"设置缓存目录: {cache_dir}")
|
| 34 |
|
| 35 |
def _authenticate_hf(self):
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
log.info(f"HUGGINGFACE_HUB_TOKEN: {'存在' if hf_token else '不存在'}")
|
| 46 |
-
log.info(f"HF_TOKEN: {'存在' if hf_token_alt else '不存在'}")
|
| 47 |
-
|
| 48 |
-
# 使用找到的token
|
| 49 |
-
token_to_use = assitant_token or hf_token or hf_token_alt
|
| 50 |
-
|
| 51 |
-
if token_to_use:
|
| 52 |
-
log.info(f"使用token: {token_to_use[:10]}...")
|
| 53 |
-
|
| 54 |
-
# 设置缓存目录用于认证
|
| 55 |
-
cache_dir = "/app/.cache/huggingface"
|
| 56 |
-
login(token=token_to_use, add_to_git_credential=False)
|
| 57 |
-
log.info("✅ HuggingFace 认证成功")
|
| 58 |
-
return token_to_use
|
| 59 |
-
else:
|
| 60 |
-
log.error("❌ 未找到任何有效的 HuggingFace token")
|
| 61 |
-
return None
|
| 62 |
-
|
| 63 |
-
except Exception as e:
|
| 64 |
-
log.error(f"❌ HuggingFace 认证失败: {e}")
|
| 65 |
-
return None
|
| 66 |
|
| 67 |
def _initialize_model(self):
|
| 68 |
"""初始化Gemma模型"""
|
|
|
|
| 33 |
log.info(f"设置缓存目录: {cache_dir}")
|
| 34 |
|
| 35 |
def _authenticate_hf(self):
|
| 36 |
+
|
| 37 |
+
assitant_token = os.getenv("Assitant_tocken")
|
| 38 |
+
token_to_use = assitant_token
|
| 39 |
+
|
| 40 |
+
cache_dir = "/app/.cache/huggingface"
|
| 41 |
+
login(token=token_to_use, add_to_git_credential=False)
|
| 42 |
+
log.info("✅ HuggingFace 认证成功")
|
| 43 |
+
|
| 44 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
def _initialize_model(self):
|
| 47 |
"""初始化Gemma模型"""
|