File size: 1,745 Bytes
aacc29a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Publish an accepted real research bundle to a confirmed private Hugging Face repo."""

from __future__ import annotations

import argparse
import os
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[3]
sys.path.insert(0, str(ROOT / "scribe" / "training"))

from soap.bundle import validate_bundle  # noqa: E402


def main() -> None:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--bundle", type=Path, required=True)
    parser.add_argument("--repo-id", required=True)
    parser.add_argument("--confirm-private-upload", action="store_true")
    args = parser.parse_args()
    if not args.confirm_private_upload:
        raise SystemExit("Pass --confirm-private-upload to authorize the private bundle upload")
    try:
        validate_bundle(args.bundle.resolve())
    except ValueError as exc:
        raise SystemExit(str(exc)) from exc
    token = os.environ.get("HF_TOKEN")
    if not token:
        raise SystemExit("HF_TOKEN is required from an environment variable or Colab Secret")
    from huggingface_hub import HfApi  # type: ignore

    api = HfApi(token=token)
    api.create_repo(args.repo_id, repo_type="model", private=True, exist_ok=True)
    info = api.repo_info(args.repo_id, repo_type="model")
    if not info.private:
        raise SystemExit("refusing upload because the Hugging Face repository is not private")
    api.upload_folder(
        repo_id=args.repo_id,
        repo_type="model",
        folder_path=str(args.bundle.resolve()),
        commit_message="Upload accepted CarePath research-only Scribe bundle",
    )
    print(f"Uploaded accepted research bundle to private model repository {args.repo_id}")


if __name__ == "__main__":
    main()