File size: 1,171 Bytes
2b3dd8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from huggingface_hub import HfApi, HfFolder, upload_file
import os

# Hugging Face 仓库名称
repo_name = "genview_pretrained_models"
repo_id = f"Xiaojie0903/{repo_name}"       # 完整仓库名称

# 模型文件目录
model_dir = "/home/xiaojie/work_dirs_gao/work_dirs/genview_upload_hf"

# 检查是否创建了仓库
api = HfApi()
try:
    api.create_repo(name=repo_name, exist_ok=True)
    print(f"Repository created or exists: https://huggingface.co/{repo_id}")
except Exception as e:
    print(f"Error creating repository: {e}")

# 遍历模型文件并上传
for model_file in os.listdir(model_dir):
    model_path = os.path.join(model_dir, model_file)
    if os.path.isfile(model_path):
        try:
            # 上传文件到仓库的根目录
            upload_file(
                path_or_fileobj=model_path,
                path_in_repo=model_file,
                repo_id=repo_id,
                commit_message=f"Upload {model_file}"
            )
            print(f"Uploaded: {model_file}")
        except Exception as e:
            print(f"Error uploading {model_file}: {e}")

print(f"All models uploaded to: https://huggingface.co/{repo_id}")