"""Upload the submission (forecasts, write-up, code, data, reports) to the team's Hugging Face dataset. Not part of reproducing the forecasts. Needs `pip install huggingface_hub` and a token with write access to that one dataset in the HF_TOKEN environment variable (never in a file). Usage: HF_TOKEN=... python code/push_to_hub.py / [--create] [-m "commit message"] """ import sys from pathlib import Path from huggingface_hub import HfApi ROOT = Path(__file__).resolve().parents[1] ALLOW = ["README.md", "submission.csv", "NOTES.md", "OBSTACLES.md", "Makefile", "requirements.txt", ".gitignore", "code/**", "data/**", "reports/**"] IGNORE = ["**/__pycache__/**", "**/*.pyc", "data/raw/daily.parquet", "**/*.part", ".venv/**", ".git/**"] def main() -> int: args = [a for a in sys.argv[1:] if not a.startswith("-")] if len(args) != 1 or "/" not in args[0]: print(__doc__) return 2 repo_id = args[0] message = sys.argv[sys.argv.index("-m") + 1] if "-m" in sys.argv else "Update submission" readme = (ROOT / "README.md").read_text() if "{{" in readme: print("README.md still has {{placeholders}}: fill them in before uploading") return 1 api = HfApi() if "--create" in sys.argv: api.create_repo(repo_id, repo_type="dataset", private=False, exist_ok=True) commit = api.upload_folder(folder_path=str(ROOT), repo_id=repo_id, repo_type="dataset", allow_patterns=ALLOW, ignore_patterns=IGNORE, commit_message=message) print(f"uploaded to https://huggingface.co/datasets/{repo_id} commit {commit.oid}") return 0 if __name__ == "__main__": sys.exit(main())