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}")