PluginsKers commited on
Commit
faa40cd
·
verified ·
1 Parent(s): b9c0d32

Delete upload.py

Browse files
Files changed (1) hide show
  1. upload.py +0 -131
upload.py DELETED
@@ -1,131 +0,0 @@
1
- import os
2
- import time
3
- from pathlib import Path
4
-
5
- # 如果使用本地HF镜像,取消注释下面这行
6
- # os.environ["HF_ENDPOINT"] = "http://localhost:5564"
7
- os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
8
-
9
- from huggingface_hub import HfApi, logging
10
-
11
- # 配置
12
- REPO_ID = "PluginsKers/Convbased-Studio" # 请修改为您的仓库ID
13
- REPO_TYPE = "model"
14
- COMMIT_MESSAGE = "Upload Convbased Studio models and assets"
15
-
16
- # 设置日志级别
17
- logging.set_verbosity_info()
18
- hf = HfApi()
19
-
20
- def upload_file_with_retry(file_path, repo_path, max_retries=3):
21
- """带重试功能的文件上传"""
22
- for attempt in range(max_retries):
23
- try:
24
- print(f"上传文件 {file_path} -> {repo_path} (尝试 {attempt + 1}/{max_retries})")
25
- result = hf.upload_file(
26
- path_or_fileobj=str(file_path),
27
- path_in_repo=repo_path,
28
- repo_id=REPO_ID,
29
- repo_type=REPO_TYPE,
30
- commit_message=f"{COMMIT_MESSAGE}: {repo_path}"
31
- )
32
- print(f"✅ 成功上传: {repo_path}")
33
- return result
34
- except Exception as e:
35
- print(f"❌ 上传失败 (尝试 {attempt + 1}): {e}")
36
- if attempt < max_retries - 1:
37
- time.sleep(5) # 等待5秒后重试
38
- else:
39
- print(f"❌ 文件 {file_path} 上传最终失败")
40
- raise e
41
-
42
- def main():
43
- """主上传函数"""
44
- project_root = Path(".")
45
-
46
- print("🚀 开始上传 Convbased Studio 项目到 HuggingFace Hub")
47
- print(f"📁 项目目录: {project_root.absolute()}")
48
- print(f"🎯 目标仓库: {REPO_ID}")
49
- print("-" * 50)
50
-
51
- # 要上传的文件列表
52
- files_to_upload = []
53
-
54
- # 1. 添加 README.md
55
- readme_path = project_root / "README.md"
56
- if readme_path.exists():
57
- files_to_upload.append((readme_path, "README.md"))
58
-
59
- # 2. 添加主模型压缩包
60
- archive_path = project_root / "RVC1006Nvidia_Convbased_0611.7z"
61
- if archive_path.exists():
62
- files_to_upload.append((archive_path, "RVC1006Nvidia_Convbased_0611.7z"))
63
-
64
- # 3. 递归添加 embedders 目录下的所有文件
65
- embedders_dir = project_root / "embedders"
66
- if embedders_dir.exists():
67
- for file_path in embedders_dir.rglob("*"):
68
- if file_path.is_file():
69
- # 计算相对路径
70
- relative_path = file_path.relative_to(project_root)
71
- files_to_upload.append((file_path, str(relative_path).replace("\\", "/")))
72
-
73
- # 4. 添加 assets 目录下的文件(如果存在)
74
- assets_dir = project_root / "assets"
75
- if assets_dir.exists():
76
- for file_path in assets_dir.rglob("*"):
77
- if file_path.is_file():
78
- relative_path = file_path.relative_to(project_root)
79
- files_to_upload.append((file_path, str(relative_path).replace("\\", "/")))
80
-
81
- print(f"📋 发现 {len(files_to_upload)} 个文件待上传:")
82
- for i, (file_path, repo_path) in enumerate(files_to_upload, 1):
83
- file_size = file_path.stat().st_size / (1024 * 1024) # MB
84
- print(f" {i:2d}. {repo_path} ({file_size:.1f} MB)")
85
-
86
- print("-" * 50)
87
-
88
- # 按文件大小排序,先上传小文件
89
- files_to_upload.sort(key=lambda x: x[0].stat().st_size)
90
-
91
- success_count = 0
92
- failed_files = []
93
-
94
- for i, (file_path, repo_path) in enumerate(files_to_upload, 1):
95
- try:
96
- print(f"\n📤 [{i}/{len(files_to_upload)}] 上传文件...")
97
- upload_file_with_retry(file_path, repo_path)
98
- success_count += 1
99
- except Exception as e:
100
- failed_files.append((file_path, repo_path, str(e)))
101
- print(f"❌ 跳过文件: {repo_path}")
102
-
103
- # 上传结果统计
104
- print("\n" + "=" * 50)
105
- print("📊 上传结果统计:")
106
- print(f"✅ 成功上传: {success_count} 个文件")
107
- print(f"❌ 失败文件: {len(failed_files)} 个文件")
108
-
109
- if failed_files:
110
- print("\n❌ 失败文件列表:")
111
- for file_path, repo_path, error in failed_files:
112
- print(f" - {repo_path}: {error}")
113
-
114
- if success_count > 0:
115
- print(f"\n🎉 项目已成功上传到: https://huggingface.co/{REPO_ID}")
116
-
117
- print("=" * 50)
118
-
119
- if __name__ == "__main__":
120
- # 检查是否需要修改仓库ID
121
- if REPO_ID == "your-username/convbased-studio":
122
- print("⚠️ 请先修改脚本中的 REPO_ID 变量为您的实际仓库ID")
123
- print(" 例如: 'your-username/convbased-studio'")
124
- input(" 修改完成后按回车键继续...")
125
-
126
- try:
127
- main()
128
- except KeyboardInterrupt:
129
- print("\n\n⏹️ 用户中断上传")
130
- except Exception as e:
131
- print(f"\n\n💥 发生未预期的错误: {e}")