Xiaojie0903
commited on
Commit
•
2b3dd8e
1
Parent(s):
720814a
Upload upload_hf.py
Browse files- upload_hf.py +36 -0
upload_hf.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import HfApi, HfFolder, upload_file
|
2 |
+
import os
|
3 |
+
|
4 |
+
# Hugging Face 仓库名称
|
5 |
+
repo_name = "genview_pretrained_models"
|
6 |
+
repo_id = f"Xiaojie0903/{repo_name}" # 完整仓库名称
|
7 |
+
|
8 |
+
# 模型文件目录
|
9 |
+
model_dir = "/home/xiaojie/work_dirs_gao/work_dirs/genview_upload_hf"
|
10 |
+
|
11 |
+
# 检查是否创建了仓库
|
12 |
+
api = HfApi()
|
13 |
+
try:
|
14 |
+
api.create_repo(name=repo_name, exist_ok=True)
|
15 |
+
print(f"Repository created or exists: https://huggingface.co/{repo_id}")
|
16 |
+
except Exception as e:
|
17 |
+
print(f"Error creating repository: {e}")
|
18 |
+
|
19 |
+
# 遍历模型文件并上传
|
20 |
+
for model_file in os.listdir(model_dir):
|
21 |
+
model_path = os.path.join(model_dir, model_file)
|
22 |
+
if os.path.isfile(model_path):
|
23 |
+
try:
|
24 |
+
# 上传文件到仓库的根目录
|
25 |
+
upload_file(
|
26 |
+
path_or_fileobj=model_path,
|
27 |
+
path_in_repo=model_file,
|
28 |
+
repo_id=repo_id,
|
29 |
+
commit_message=f"Upload {model_file}"
|
30 |
+
)
|
31 |
+
print(f"Uploaded: {model_file}")
|
32 |
+
except Exception as e:
|
33 |
+
print(f"Error uploading {model_file}: {e}")
|
34 |
+
|
35 |
+
print(f"All models uploaded to: https://huggingface.co/{repo_id}")
|
36 |
+
|