Delete upload_to_huggingface.py
Browse files- upload_to_huggingface.py +0 -83
upload_to_huggingface.py
DELETED
|
@@ -1,83 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
上传Detection模型到Hugging Face Hub
|
| 3 |
-
"""
|
| 4 |
-
from huggingface_hub import HfApi, create_repo
|
| 5 |
-
import os
|
| 6 |
-
|
| 7 |
-
# 配置
|
| 8 |
-
REPO_NAME = "your-username/longemotion-detection" # 修改为你的用户名
|
| 9 |
-
MODEL_PATH = "model/best_model.pt"
|
| 10 |
-
LOCAL_DIR = "."
|
| 11 |
-
|
| 12 |
-
def upload_model():
|
| 13 |
-
"""上传模型到Hugging Face"""
|
| 14 |
-
|
| 15 |
-
print("="*60)
|
| 16 |
-
print("上传LongEmotion Detection模型到Hugging Face")
|
| 17 |
-
print("="*60)
|
| 18 |
-
|
| 19 |
-
# 初始化API
|
| 20 |
-
api = HfApi()
|
| 21 |
-
|
| 22 |
-
# 步骤1: 创建仓库(如果不存在)
|
| 23 |
-
print("\n[1/3] 创建仓库...")
|
| 24 |
-
try:
|
| 25 |
-
create_repo(
|
| 26 |
-
repo_id=REPO_NAME,
|
| 27 |
-
repo_type="model",
|
| 28 |
-
exist_ok=True,
|
| 29 |
-
private=False # 设置为True则为私有仓库
|
| 30 |
-
)
|
| 31 |
-
print(f"✅ 仓库创建/确认: {REPO_NAME}")
|
| 32 |
-
except Exception as e:
|
| 33 |
-
print(f"❌ 创建仓库失败: {e}")
|
| 34 |
-
return
|
| 35 |
-
|
| 36 |
-
# 步骤2: 上传模型文件
|
| 37 |
-
print("\n[2/3] 上传模型文件...")
|
| 38 |
-
try:
|
| 39 |
-
api.upload_file(
|
| 40 |
-
path_or_fileobj=MODEL_PATH,
|
| 41 |
-
path_in_repo="best_model.pt",
|
| 42 |
-
repo_id=REPO_NAME,
|
| 43 |
-
repo_type="model",
|
| 44 |
-
)
|
| 45 |
-
print("✅ 模型文件上传成功")
|
| 46 |
-
except Exception as e:
|
| 47 |
-
print(f"❌ 上传模型失败: {e}")
|
| 48 |
-
return
|
| 49 |
-
|
| 50 |
-
# 步骤3: 上传README和其他文件
|
| 51 |
-
print("\n[3/3] 上传README和文档...")
|
| 52 |
-
files_to_upload = [
|
| 53 |
-
("README.md", "README.md"),
|
| 54 |
-
("快速使用指南.md", "快速使用指南.md"),
|
| 55 |
-
("scripts/inference_longemotion.py", "inference_longemotion.py"),
|
| 56 |
-
("scripts/detection_model.py", "detection_model.py"),
|
| 57 |
-
]
|
| 58 |
-
|
| 59 |
-
for local_path, remote_path in files_to_upload:
|
| 60 |
-
if os.path.exists(local_path):
|
| 61 |
-
try:
|
| 62 |
-
api.upload_file(
|
| 63 |
-
path_or_fileobj=local_path,
|
| 64 |
-
path_in_repo=remote_path,
|
| 65 |
-
repo_id=REPO_NAME,
|
| 66 |
-
repo_type="model",
|
| 67 |
-
)
|
| 68 |
-
print(f"✅ 上传: {remote_path}")
|
| 69 |
-
except Exception as e:
|
| 70 |
-
print(f"⚠️ 上传 {remote_path} 失败: {e}")
|
| 71 |
-
|
| 72 |
-
print("\n" + "="*60)
|
| 73 |
-
print(f"🎉 上传完成!")
|
| 74 |
-
print(f"模型地址: https://huggingface.co/{REPO_NAME}")
|
| 75 |
-
print("="*60)
|
| 76 |
-
|
| 77 |
-
if __name__ == "__main__":
|
| 78 |
-
# 检查是否已登录
|
| 79 |
-
print("请确保已执行: huggingface-cli login")
|
| 80 |
-
input("按回车继续...")
|
| 81 |
-
|
| 82 |
-
upload_model()
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|