chemistry-knowledge / upload.py
janwein's picture
Release ChemBricks curated knowledge 2026-09-17.1
7943e63 verified
Raw History Blame Contribute Delete
1.55 kB
"""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()