|
|
|
|
|
""" |
|
|
Upload Infinite-World repo to Hugging Face Hub (including checkpoints). |
|
|
|
|
|
Prerequisites: |
|
|
1. pip install huggingface_hub |
|
|
2. huggingface-cli login # or: from huggingface_hub import login; login() |
|
|
|
|
|
Usage: |
|
|
cd infinite-world |
|
|
python scripts/upload_to_hf.py [REPO_ID] |
|
|
|
|
|
Examples: |
|
|
python scripts/upload_to_hf.py |
|
|
python scripts/upload_to_hf.py your-username/infinite-world |
|
|
""" |
|
|
|
|
|
import os |
|
|
import sys |
|
|
|
|
|
|
|
|
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
|
|
|
|
|
|
|
|
def main(): |
|
|
try: |
|
|
from huggingface_hub import HfApi, create_repo, whoami |
|
|
except ImportError: |
|
|
print("Install: pip install huggingface_hub") |
|
|
sys.exit(1) |
|
|
|
|
|
repo_id = ( |
|
|
(sys.argv[1] if len(sys.argv) > 1 else None) |
|
|
or os.environ.get("HF_REPO_ID") |
|
|
or "MeiGen-AI/Infinite-World" |
|
|
) |
|
|
|
|
|
|
|
|
try: |
|
|
info = whoami() |
|
|
print(f"[HF] Logged in as: {info.get('name', info.get('type', '?'))}") |
|
|
except Exception as e: |
|
|
print("[HF] Not logged in or token invalid (401).") |
|
|
print(" Run: huggingface-cli login") |
|
|
print(" Get a token with WRITE at: https://huggingface.co/settings/tokens") |
|
|
print(" For org repo MeiGen-AI/Infinite-World, your account must have write access to the MeiGen-AI org.") |
|
|
sys.exit(1) |
|
|
|
|
|
api = HfApi() |
|
|
repo_type = "model" |
|
|
|
|
|
|
|
|
try: |
|
|
create_repo(repo_id, repo_type=repo_type, exist_ok=True) |
|
|
print(f"[HF] Repo ready: https://huggingface.co/{repo_id}") |
|
|
except Exception as e: |
|
|
err = str(e).lower() |
|
|
if "401" in err or "unauthorized" in err: |
|
|
print("[HF] No write permission for this repo. Fix: use a token with write access; for MeiGen-AI/Infinite-World, be a member of MeiGen-AI org or use the org token.") |
|
|
sys.exit(1) |
|
|
print(f"[HF] Create repo: {e}") |
|
|
|
|
|
|
|
|
|
|
|
ignore_patterns = [ |
|
|
"__pycache__", |
|
|
"*.pyc", |
|
|
".git", |
|
|
"outputs", |
|
|
".cursor", |
|
|
"*.egg-info", |
|
|
".eggs", |
|
|
] |
|
|
|
|
|
|
|
|
upload_kw = dict( |
|
|
folder_path=PROJECT_ROOT, |
|
|
repo_id=repo_id, |
|
|
repo_type=repo_type, |
|
|
ignore_patterns=ignore_patterns, |
|
|
) |
|
|
print(f"[HF] Uploading from {PROJECT_ROOT} to {repo_id} (including checkpoints/) ...") |
|
|
try: |
|
|
api.upload_folder(**upload_kw, use_gitignore=False) |
|
|
except TypeError: |
|
|
|
|
|
api.upload_folder(**upload_kw) |
|
|
checkpoints_dir = os.path.join(PROJECT_ROOT, "checkpoints") |
|
|
if os.path.isdir(checkpoints_dir): |
|
|
print(f"[HF] Uploading checkpoints/ to {repo_id} ...") |
|
|
api.upload_folder( |
|
|
folder_path=checkpoints_dir, |
|
|
repo_id=repo_id, |
|
|
path_in_repo="checkpoints", |
|
|
repo_type=repo_type, |
|
|
) |
|
|
print(f"[HF] Done: https://huggingface.co/{repo_id}") |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|