Download restore_shared_assets.py from starstone3/HFD-TextOp-Training: direct link, hf CLI and curl.
- Browser
- Download file 840 Bytes
-
https://huggingface.co/starstone3/HFD-TextOp-Training/resolve/main/restore_shared_assets.py
- Command line
-
hf download hf://starstone3/HFD-TextOp-Training/restore_shared_assets.py
-
curl -L -o restore_shared_assets.py https://huggingface.co/starstone3/HFD-TextOp-Training/resolve/main/restore_shared_assets.py
840 Bytes
| from pathlib import Path | |
| import json,hashlib,shutil | |
| from huggingface_hub import hf_hub_download | |
| root=Path(__file__).resolve().parent | |
| for x in json.loads((root/'SHARED_ASSETS.json').read_text())['files']: | |
| dest=root/x['destination'] | |
| def digest(p): | |
| h=hashlib.sha256() | |
| with p.open('rb') as f: | |
| for b in iter(lambda:f.read(8*2**20),b''):h.update(b) | |
| return h.hexdigest() | |
| if dest.exists(): | |
| if dest.stat().st_size!=x['bytes'] or digest(dest)!=x['sha256']:raise RuntimeError('Existing file differs: '+str(dest)) | |
| continue | |
| p=Path(hf_hub_download(repo_id=x['repo_id'],filename=x['path'],revision=x['revision'])) | |
| assert p.stat().st_size==x['bytes'] and digest(p)==x['sha256'],x['path'] | |
| dest.parent.mkdir(parents=True,exist_ok=True);shutil.copyfile(p,dest) | |
| assert digest(dest)==x['sha256'] | |
| print('Verified restored',x['destination']) | |