Upload folder using huggingface_hub
Browse files- persistence.py +8 -4
persistence.py
CHANGED
|
@@ -96,16 +96,20 @@ class PersistenceManager:
|
|
| 96 |
"""将数据库上传到 Hugging Face Dataset"""
|
| 97 |
try:
|
| 98 |
from huggingface_hub import HfApi
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
api = HfApi(token=self.hf_token)
|
| 100 |
-
print(f"[*] 正在备份数据库到云端
|
| 101 |
|
| 102 |
api.upload_file(
|
| 103 |
path_or_fileobj=self.db_path,
|
| 104 |
path_in_repo=self.db_path,
|
| 105 |
repo_id=self.dataset_repo,
|
| 106 |
repo_type="dataset",
|
| 107 |
-
commit_message=f"Persist Gemini
|
| 108 |
)
|
| 109 |
-
print("✅ 云端备份成功")
|
| 110 |
except Exception as e:
|
| 111 |
-
print(f"❌ 云端备份失败: {e}")
|
|
|
|
| 96 |
"""将数据库上传到 Hugging Face Dataset"""
|
| 97 |
try:
|
| 98 |
from huggingface_hub import HfApi
|
| 99 |
+
if not self.hf_token:
|
| 100 |
+
print("❌ 云端备份失败: 未检测到 HF_TOKEN 环境变量")
|
| 101 |
+
return
|
| 102 |
+
|
| 103 |
api = HfApi(token=self.hf_token)
|
| 104 |
+
print(f"[*] 正在备份数据库到云端: {self.db_path} -> {self.dataset_repo} ...")
|
| 105 |
|
| 106 |
api.upload_file(
|
| 107 |
path_or_fileobj=self.db_path,
|
| 108 |
path_in_repo=self.db_path,
|
| 109 |
repo_id=self.dataset_repo,
|
| 110 |
repo_type="dataset",
|
| 111 |
+
commit_message=f"Persist Gemini db at {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
|
| 112 |
)
|
| 113 |
+
print("✅ 云端备份成功!文件已推送到 Dataset。")
|
| 114 |
except Exception as e:
|
| 115 |
+
print(f"❌ 云端备份失败,详细错误: {str(e)}")
|