Download download_dataset.py from bcbl190626/SpanishBCBL: direct link, hf CLI and curl.
- Browser
- Download file 3.72 kB
-
https://huggingface.co/datasets/bcbl190626/SpanishBCBL/resolve/main/download_dataset.py
- Command line
-
hf download hf://datasets/bcbl190626/SpanishBCBL/download_dataset.py
-
curl -L -o download_dataset.py https://huggingface.co/datasets/bcbl190626/SpanishBCBL/resolve/main/download_dataset.py
3.72 kB
| #!/usr/bin/env python3 | |
| """Download the SpanishBCBL dataset (MEG + EEG typing recordings) from the Hugging Face Hub. | |
| Repository: https://huggingface.co/datasets/bcbl190626/SpanishBCBL | |
| Examples | |
| -------- | |
| # Download everything (~262 GB) into ./SpanishBCBL | |
| python download_dataset.py | |
| # Download only the MEG modality into a custom folder | |
| python download_dataset.py --modality meg --local-dir /data/SpanishBCBL | |
| # Pass a token explicitly (otherwise uses your cached login / HF_TOKEN env var) | |
| python download_dataset.py --token hf_xxx | |
| Notes | |
| ----- | |
| - Requires `huggingface_hub`: pip install -U "huggingface_hub[cli]" | |
| - While the repository is private you must be authenticated: run `hf auth login` | |
| once, set the HF_TOKEN environment variable, or pass --token. | |
| - Downloads resume automatically: re-running skips files already present. | |
| """ | |
| import argparse | |
| import sys | |
| REPO_ID = "bcbl190626/SpanishBCBL" | |
| REPO_TYPE = "dataset" | |
| # Per-modality file filters (None = no filter, i.e. download everything). | |
| MODALITY_PATTERNS = { | |
| "all": None, | |
| "meg": ["MEG/*", "README.md"], | |
| "eeg": ["EEG/*", "README.md"], | |
| } | |
| def parse_args() -> argparse.Namespace: | |
| p = argparse.ArgumentParser( | |
| description="Download the SpanishBCBL dataset from the Hugging Face Hub.", | |
| formatter_class=argparse.ArgumentDefaultsHelpFormatter, | |
| ) | |
| p.add_argument( | |
| "--local-dir", | |
| default="SpanishBCBL", | |
| help="Destination directory for the downloaded dataset.", | |
| ) | |
| p.add_argument( | |
| "--modality", | |
| choices=sorted(MODALITY_PATTERNS), | |
| default="all", | |
| help="Which modality to download.", | |
| ) | |
| p.add_argument( | |
| "--token", | |
| default=None, | |
| help="Hugging Face access token (defaults to cached login / HF_TOKEN env var).", | |
| ) | |
| p.add_argument( | |
| "--revision", | |
| default=None, | |
| help="Specific git revision (branch, tag, or commit) to download.", | |
| ) | |
| p.add_argument( | |
| "--workers", | |
| type=int, | |
| default=8, | |
| help="Number of parallel download workers.", | |
| ) | |
| return p.parse_args() | |
| def main() -> int: | |
| args = parse_args() | |
| try: | |
| from huggingface_hub import snapshot_download | |
| except ImportError: | |
| sys.exit( | |
| 'huggingface_hub is not installed. Install it with:\n' | |
| ' pip install -U "huggingface_hub[cli]"' | |
| ) | |
| allow_patterns = MODALITY_PATTERNS[args.modality] | |
| print(f"Repository : {REPO_ID} ({REPO_TYPE})") | |
| print(f"Modality : {args.modality}") | |
| print(f"Destination: {args.local_dir}") | |
| if allow_patterns: | |
| print(f"Patterns : {allow_patterns}") | |
| print("Starting download (this may take a while; downloads resume if interrupted)...\n") | |
| try: | |
| path = snapshot_download( | |
| repo_id=REPO_ID, | |
| repo_type=REPO_TYPE, | |
| local_dir=args.local_dir, | |
| allow_patterns=allow_patterns, | |
| revision=args.revision, | |
| token=args.token, | |
| max_workers=args.workers, | |
| ) | |
| except Exception as exc: # noqa: BLE001 - surface a friendly message | |
| msg = str(exc) | |
| if "401" in msg or "403" in msg or "gated" in msg.lower() or "authenticate" in msg.lower(): | |
| sys.exit( | |
| f"Authentication/authorization failed: {exc}\n\n" | |
| "If the dataset is private, make sure you are logged in:\n" | |
| " hf auth login\n" | |
| "or pass a token with --token / set the HF_TOKEN environment variable." | |
| ) | |
| sys.exit(f"Download failed: {exc}") | |
| print(f"\nDone. Dataset available at: {path}") | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |