Spaces:
Running
Running
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import os | |
| import shutil | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| def main() -> int: | |
| parser = argparse.ArgumentParser(description="publish the AirGPT Hub Docker Space") | |
| parser.add_argument("--repo-id", default="airgpt/airgpt-hub") | |
| parser.add_argument("--private", action="store_true") | |
| args = parser.parse_args() | |
| token = os.getenv("HF_TOKEN") | |
| if not token: | |
| parser.error("HF_TOKEN is required") | |
| try: | |
| from huggingface_hub import HfApi, hf_hub_download | |
| except ImportError as exc: | |
| raise SystemExit("install huggingface_hub before publishing") from exc | |
| api = HfApi(token=token) | |
| for filename in ("index.json", "community-models.json", "datasets.json"): | |
| catalog_path = hf_hub_download( | |
| repo_id="airgpt/embodied-model-index", | |
| repo_type="dataset", | |
| filename=filename, | |
| token=token, | |
| ) | |
| json.loads(Path(catalog_path).read_text(encoding="utf-8")) | |
| shutil.copyfile(catalog_path, ROOT / "data" / filename) | |
| api.create_repo( | |
| repo_id=args.repo_id, | |
| repo_type="space", | |
| space_sdk="docker", | |
| private=args.private, | |
| exist_ok=True, | |
| ) | |
| result = api.upload_folder( | |
| repo_id=args.repo_id, | |
| repo_type="space", | |
| folder_path=str(ROOT), | |
| commit_message="Publish AirGPT Hub H1.2", | |
| ignore_patterns=[ | |
| ".git/**", | |
| ".pytest_cache/**", | |
| ".ruff_cache/**", | |
| "**/__pycache__/**", | |
| "**/*.pyc", | |
| ], | |
| ) | |
| print(result) | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |