File size: 3,313 Bytes
01c7703
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4794722
01c7703
 
 
 
 
 
 
 
 
 
4794722
 
01c7703
 
 
 
 
4794722
 
 
 
 
 
 
 
 
 
 
 
 
 
 
01c7703
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
"""
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 = parent of scripts/
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"
    )

    # Check login first (avoid 401 later)
    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"

    # Create repo if it doesn't exist (skip if 401; repo may already exist)
    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}")
        # Continue; repo might already exist

    # Exclude cache/outputs; do NOT use .gitignore so checkpoints/ is included
    ignore_patterns = [
        "__pycache__",
        "*.pyc",
        ".git",
        "outputs",
        ".cursor",
        "*.egg-info",
        ".eggs",
    ]

    # Upload: use use_gitignore=False so checkpoints/ (in .gitignore) is included
    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:
        # Older huggingface_hub: no use_gitignore → upload checkpoints separately
        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()