Datasets:
Download scripts/upload_to_hf.py from herbwood27/FORGE: direct link, hf CLI and curl.
- Browser
- Download file 1.63 kB
-
https://huggingface.co/datasets/herbwood27/FORGE/resolve/main/scripts/upload_to_hf.py
- Command line
-
hf download hf://datasets/herbwood27/FORGE/scripts/upload_to_hf.py
-
curl -L -o upload_to_hf.py https://huggingface.co/datasets/herbwood27/FORGE/resolve/main/scripts/upload_to_hf.py
1.63 kB
| import argparse,os,sys,subprocess | |
| from pathlib import Path | |
| def main(): | |
| ap=argparse.ArgumentParser(description='Validate then resumably upload this release only. Matching paths are updated.') | |
| ap.add_argument('--repo-id',required=True) | |
| ap.add_argument('--delete-stale',action='store_true',help='After upload remove remote files absent from this release, retaining Hub attributes.') | |
| args=ap.parse_args(); root=Path(__file__).resolve().parents[1] | |
| assert (root/'RELEASE_MANIFEST.json').is_file() | |
| subprocess.run([sys.executable,str(root/'scripts/validate_dataset.py'),'--root',str(root)],check=True) | |
| subprocess.run([sys.executable,str(root/'scripts/test_validator.py')],check=True) | |
| from huggingface_hub import HfApi,CommitOperationDelete | |
| token=os.environ.get('HF_TOKEN') | |
| if not token: raise SystemExit('Set HF_TOKEN in the environment before uploading.') | |
| api=HfApi(token=token); api.create_repo(repo_id=args.repo_id,repo_type='dataset',exist_ok=True) | |
| api.upload_large_folder(repo_id=args.repo_id,repo_type='dataset',folder_path=str(root),ignore_patterns=['.cache/**','**/__pycache__/**','*.pyc']) | |
| if args.delete_stale: | |
| local={p.relative_to(root).as_posix() for p in root.rglob('*') if p.is_file() and not any(x in {'.cache','__pycache__'} for x in p.relative_to(root).parts)} | |
| stale=set(api.list_repo_files(repo_id=args.repo_id,repo_type='dataset'))-local-{'.gitattributes'} | |
| if stale: api.create_commit(repo_id=args.repo_id,repo_type='dataset',operations=[CommitOperationDelete(path_in_repo=p) for p in sorted(stale)],commit_message='Remove obsolete files from replaced dataset release') | |
| if __name__=='__main__': main() | |