|
from huggingface_hub import HfApi, HfFolder, upload_file |
|
import os |
|
|
|
|
|
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}") |
|
|
|
|