Download download.py from Grio43/OppaiOracle-experimental-X1.1: direct link, hf CLI and curl.
- Browser
- Download file 3.22 kB
-
https://huggingface.co/Grio43/OppaiOracle-experimental-X1.1/resolve/main/download.py
- Command line
-
hf download hf://Grio43/OppaiOracle-experimental-X1.1/download.py
-
curl -L -o download.py https://huggingface.co/Grio43/OppaiOracle-experimental-X1.1/resolve/main/download.py
3.22 kB
| #!/usr/bin/env python3 | |
| """Download an immutable OppaiOracle release snapshot using Hugging Face Hub.""" | |
| import argparse | |
| import json | |
| from pathlib import Path, PurePosixPath | |
| DEFAULT_REPO_ID = 'Grio43/OppaiOracle-experimental-X1.1' | |
| SUPPORT_FILES = [ | |
| 'README.md', 'LICENSE', 'config.json', 'selected_tags.csv', 'thresholds.json', | |
| 'infer.py', 'download.py', 'model_architecture.py', 'custom_drop_path.py', | |
| 'mask_utils.py', 'requirements*.txt', 'release_manifest.json', | |
| 'preprocessing.json', 'training_metadata.json', 'validation.json', | |
| 'comparison_v1_1.json', 'comparison_v1_1_per_tag.csv', 'comparison_groups.csv', | |
| 'checkpoint_evidence.json', 'frozen_evaluation_contract.json', | |
| 'training_epochs.csv', 'training_buckets.csv', 'inference_checks.json', 'SHA256SUMS', | |
| ] | |
| def release_filename(name): | |
| """Require ordinary relative Hub filenames, without glob expansion.""" | |
| path = PurePosixPath(name) | |
| if (not name or path.is_absolute() or '..' in path.parts | |
| or any(char in name for char in ('\\', ':', '*', '?', '[', ']'))): | |
| raise ValueError(f'Invalid release filename: {name!r}') | |
| return name | |
| def download_release(destination, repo_id=DEFAULT_REPO_ID, model_format='onnx', revision='main'): | |
| from huggingface_hub import HfApi, hf_hub_download, snapshot_download | |
| # Resolve once, so config and model files cannot straddle a moving main. | |
| commit = HfApi().model_info(repo_id=repo_id, revision=revision).sha | |
| if not commit: | |
| raise RuntimeError('Hugging Face did not return an immutable commit SHA') | |
| destination = Path(destination) | |
| config_path = hf_hub_download(repo_id=repo_id, filename='config.json', | |
| revision=commit, local_dir=destination) | |
| config = json.loads(Path(config_path).read_text(encoding='utf-8-sig')) | |
| formats = ('onnx', 'safetensors') if model_format == 'all' else (model_format,) | |
| models = [release_filename(config[f'model_file_{kind}']) for kind in formats] | |
| vocab = release_filename(config.get('vocab_file', 'vocabulary.json')) | |
| patterns = SUPPORT_FILES + [vocab] + models | |
| snapshot_download(repo_id=repo_id, revision=commit, local_dir=destination, | |
| allow_patterns=patterns) | |
| record = {'repo_id': repo_id, 'commit': commit, 'format': model_format, | |
| 'model_files': models} | |
| (destination / 'download_info.json').write_text( | |
| json.dumps(record, indent=2) + '\n', encoding='utf-8') | |
| return record | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument('destination', nargs='?', type=Path, | |
| default=Path('OppaiOracle-experimental-X1.1')) | |
| parser.add_argument('--repo-id', default=DEFAULT_REPO_ID) | |
| parser.add_argument('--revision', default='main', help='Branch, tag, or commit; resolved to a pinned commit') | |
| parser.add_argument('--format', choices=('onnx', 'safetensors', 'all'), default='onnx') | |
| args = parser.parse_args() | |
| record = download_release(args.destination, args.repo_id, args.format, args.revision) | |
| print(json.dumps({'directory': str(args.destination.resolve()), **record}, indent=2)) | |
| if __name__ == '__main__': | |
| main() | |