Download code/scripts/download_imagebind_parallel.py from CollinMa/nextgpt-chapter6-report: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/CollinMa/nextgpt-chapter6-report/resolve/main/code/scripts/download_imagebind_parallel.py
- Command line
-
hf download hf://spaces/CollinMa/nextgpt-chapter6-report/code/scripts/download_imagebind_parallel.py
-
curl -L -o download_imagebind_parallel.py https://huggingface.co/spaces/CollinMa/nextgpt-chapter6-report/resolve/main/code/scripts/download_imagebind_parallel.py
1.13 kB
| """Fetch ImageBind directly from Meta and check its official multipart ETag.""" | |
| import hashlib | |
| import json | |
| import sys | |
| import urllib.request | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(ROOT)) | |
| from settings import IMAGEBIND_URL, weight_paths | |
| from range_download import download | |
| if __name__ == '__main__': | |
| with urllib.request.urlopen(urllib.request.Request(IMAGEBIND_URL,method='HEAD'),timeout=30) as response: | |
| size = int(response.headers['Content-Length']) | |
| etag = response.headers['ETag'].strip('"') | |
| target = weight_paths()['imagebind'] | |
| partial = target.with_suffix('.part') | |
| download(IMAGEBIND_URL,target,size,s3_etag=etag,seed_prefix=partial if partial.exists() else None) | |
| digest = hashlib.sha256() | |
| with target.open('rb') as source: | |
| for block in iter(lambda: source.read(8*1024*1024),b''): | |
| digest.update(block) | |
| target.with_suffix('.source.json').write_text(json.dumps({'url':IMAGEBIND_URL,'etag':etag, | |
| 'size':size,'sha256':digest.hexdigest()},indent=2)) | |
| print('Official ImageBind verified.',flush=True) | |