| import os |
| import sys |
| import subprocess |
|
|
| |
| REPO = "HorizonRobotics/Uni3R" |
| REPO_DIR = "myrepo" |
| |
|
|
| def run(cmd): |
| """运行 shell 命令,失败则抛异常""" |
| print(f"➡️ 运行: {' '.join(cmd)}") |
| result = subprocess.run(cmd) |
| if result.returncode != 0: |
| raise RuntimeError(f"命令失败: {' '.join(cmd)}") |
|
|
| def main(): |
| if len(sys.argv) < 2: |
| print("❌ 用法: python upload.py /path/to/local/file [提交说明]") |
| sys.exit(1) |
|
|
| file_path = sys.argv[1] |
| if not os.path.exists(file_path): |
| print(f"❌ 文件不存在: {file_path}") |
| sys.exit(1) |
|
|
| commit_msg = sys.argv[2] if len(sys.argv) > 2 else "update" |
|
|
| |
| if not os.path.exists(REPO_DIR): |
| run(["git", "clone", f"https://huggingface.co/{REPO}", REPO_DIR]) |
|
|
| os.chdir(REPO_DIR) |
|
|
| |
| run(["cp", file_path, "."]) |
|
|
| |
| run(["git", "add", "."]) |
| run(["git", "commit", "-m", commit_msg]) |
| run(["git", "push"]) |
|
|
| print("✅ 上传成功!") |
|
|
| if __name__ == "__main__": |
| main() |
|
|
|
|