Download hf_upload.py from PureOne/AXIORYN-CRYSTAL: direct link, hf CLI and curl.
- Browser
- Download file 5.37 kB
-
https://huggingface.co/datasets/PureOne/AXIORYN-CRYSTAL/resolve/main/hf_upload.py
- Command line
-
hf download hf://datasets/PureOne/AXIORYN-CRYSTAL/hf_upload.py
-
curl -L -o hf_upload.py https://huggingface.co/datasets/PureOne/AXIORYN-CRYSTAL/resolve/main/hf_upload.py
5.37 kB
| from __future__ import annotations | |
| import getpass | |
| import os | |
| from pathlib import Path | |
| import sys | |
| import time | |
| import webbrowser | |
| def _import_hub(): | |
| try: | |
| from huggingface_hub import HfApi, login | |
| return HfApi, login | |
| except Exception as exc: | |
| print("ERROR: huggingface_hub is not installed in this Python environment.") | |
| print("Run: py -3 -m pip install --upgrade huggingface_hub") | |
| print(f"Import error: {exc}") | |
| raise SystemExit(2) | |
| def _yes(prompt: str, default: bool = True) -> bool: | |
| suffix = " [Y/n]: " if default else " [y/N]: " | |
| ans = input(prompt + suffix).strip().lower() | |
| if not ans: | |
| return default | |
| return ans in {"y", "yes"} | |
| def _login(api, login): | |
| try: | |
| info = api.whoami() | |
| print(f"Authenticated as: {info.get('name') or info.get('fullname') or info}") | |
| return api, info | |
| except Exception: | |
| pass | |
| token = os.environ.get("HF_TOKEN", "").strip() | |
| if not token: | |
| print("\nNo active Hugging Face login was found.") | |
| print("A WRITE token is required to create/upload a repository.") | |
| print("Token page: https://huggingface.co/settings/tokens") | |
| try: | |
| webbrowser.open("https://huggingface.co/settings/tokens") | |
| except Exception: | |
| pass | |
| token = getpass.getpass("Paste your Hugging Face WRITE token (input hidden): ").strip() | |
| if not token: | |
| raise SystemExit("ERROR: no token supplied.") | |
| # Hugging Face stores authentication in the user's HF cache, never in this repository. | |
| login(token=token, add_to_git_credential=False) | |
| api = type(api)(token=token) | |
| info = api.whoami() | |
| print(f"Authenticated as: {info.get('name') or info.get('fullname') or info}") | |
| return api, info | |
| def main() -> int: | |
| HfApi, login = _import_hub() | |
| root = Path(__file__).resolve().parent | |
| print("=" * 68) | |
| print(" AXIORYN-CRYSTAL v1.0.0 - Hugging Face Python uploader") | |
| print("=" * 68) | |
| print("Uploads the EXTRACTED repository contents, not only the ZIP.") | |
| print("No token is written into the repository.\n") | |
| api = HfApi() | |
| api, info = _login(api, login) | |
| username = str(info.get("name") or "").strip() | |
| default_repo = f"{username}/AXIORYN-CRYSTAL" if username else "YOUR_USERNAME/AXIORYN-CRYSTAL" | |
| repo_id = input(f"Full repo ID [{default_repo}]: ").strip() or default_repo | |
| if "/" not in repo_id or repo_id.startswith("YOUR_USERNAME/"): | |
| print("ERROR: use a full repo ID such as yourname/AXIORYN-CRYSTAL") | |
| return 2 | |
| kind = (input("Repo type [model/dataset] (default model): ").strip().lower() or "model") | |
| if kind not in {"model", "dataset"}: | |
| print("ERROR: repo type must be model or dataset.") | |
| return 2 | |
| private = _yes("Create as private if it does not exist?", default=False) | |
| print("\nRepository :", repo_id) | |
| print("Type :", kind) | |
| print("Private :", private) | |
| print("Local root :", root) | |
| if not _yes("Start upload now?", default=True): | |
| print("Cancelled. No files were sent.") | |
| return 0 | |
| ignore = [ | |
| ".git/**", "__pycache__/**", "*.pyc", "*.pyo", "*.egg-info/**", | |
| ".pytest_cache/**", ".mypy_cache/**", ".venv/**", "venv/**", | |
| ] | |
| # Retry transient network/5xx failures. upload_folder is resumable when rerun. | |
| waits = [0, 5, 15, 30] | |
| last_exc = None | |
| for attempt, wait in enumerate(waits, start=1): | |
| if wait: | |
| print(f"Retrying in {wait} seconds...") | |
| time.sleep(wait) | |
| try: | |
| print(f"\nCreating/checking repository (attempt {attempt}/{len(waits)})...") | |
| api.create_repo(repo_id=repo_id, repo_type=kind, private=private, exist_ok=True) | |
| print("Uploading repository folder...") | |
| out = api.upload_folder( | |
| repo_id=repo_id, | |
| repo_type=kind, | |
| folder_path=str(root), | |
| path_in_repo=".", | |
| ignore_patterns=ignore, | |
| commit_message="AXIORYN-CRYSTAL v1.0.0 research release", | |
| commit_description=( | |
| "Complete expert-review release: manuscript, proofs, exact-arithmetic " | |
| "reference implementation, tests, counterexamples, audits, validation " | |
| "records, and citation metadata." | |
| ), | |
| ) | |
| print("\n" + "=" * 68) | |
| print("UPLOAD COMPLETED SUCCESSFULLY") | |
| print("=" * 68) | |
| print(out) | |
| if kind == "dataset": | |
| print(f"https://huggingface.co/datasets/{repo_id}") | |
| else: | |
| print(f"https://huggingface.co/{repo_id}") | |
| print("\nVerify that README.md renders and the manuscript PDF is visible.") | |
| return 0 | |
| except KeyboardInterrupt: | |
| print("\nCancelled by user.") | |
| return 130 | |
| except Exception as exc: | |
| last_exc = exc | |
| print(f"Upload attempt failed: {type(exc).__name__}: {exc}") | |
| print("\nUPLOAD DID NOT COMPLETE after retries.") | |
| if last_exc: | |
| print(f"Last error: {type(last_exc).__name__}: {last_exc}") | |
| print("Re-run this uploader later; Hugging Face upload_folder safely skips files already present.") | |
| return 1 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |