File size: 1,550 Bytes
7943e63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Upload only the verified public files to a named Hugging Face dataset."""
import argparse
import os
from pathlib import Path
import sys

sys.dont_write_bytecode = True
ROOT = Path(__file__).resolve().parent


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--repo-id", required=True, help="Your organization/dataset-name")
    parser.add_argument("--private", action="store_true", help="Create a new repository as private")
    args = parser.parse_args()
    if "/" not in args.repo_id or args.repo_id.startswith("YOUR_ORG/"):
        parser.error("Supply your actual organization and dataset name.")
    if not os.environ.get("HF_TOKEN"):
        parser.error("Supply HF_TOKEN through your environment.")
    from verify import verify
    manifest = verify(ROOT)
    os.environ.setdefault("HF_HOME", str(ROOT / ".cache/huggingface"))
    try:
        from huggingface_hub import HfApi
    except ImportError:
        parser.error("The optional uploader requires the official huggingface_hub package.")
    api = HfApi(token=os.environ["HF_TOKEN"])
    api.create_repo(args.repo_id, repo_type="dataset", private=args.private, exist_ok=True)
    result = api.upload_folder(
        repo_id=args.repo_id, repo_type="dataset", folder_path=str(ROOT),
        allow_patterns=sorted([*manifest["files"], "manifest.json", "SHA256SUMS"]),
        commit_message="Release ChemBricks curated knowledge " + manifest["release_version"],
    )
    print(result.commit_url)


if __name__ == "__main__":
    main()