Download code/scripts/diagnose_downloads.py from CollinMa/nextgpt-chapter6-report: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/CollinMa/nextgpt-chapter6-report/resolve/main/code/scripts/diagnose_downloads.py
- Command line
-
hf download hf://spaces/CollinMa/nextgpt-chapter6-report/code/scripts/diagnose_downloads.py
-
curl -L -o diagnose_downloads.py https://huggingface.co/spaces/CollinMa/nextgpt-chapter6-report/resolve/main/code/scripts/diagnose_downloads.py
1.1 kB
| """Anonymous small range probes; no credentials are sent to mirrors.""" | |
| import concurrent.futures | |
| import time | |
| import urllib.request | |
| URLS = [ | |
| "https://hf-mirror.com/ChocoWu/nextgpt_7b_tiva_v0/resolve/f28bea33714c810ef6cb9b9e440edcddb93297a4/pytorch_model.pt", | |
| "https://download.pytorch.org/whl/cu117/torch-1.13.1%2Bcu117-cp310-cp310-win_amd64.whl", | |
| ] | |
| def probe(url): | |
| start = time.monotonic() | |
| try: | |
| request = urllib.request.Request(url, headers={"Range": "bytes=0-1048575"}) | |
| with urllib.request.urlopen(request, timeout=20) as response: | |
| data = response.read(1048576) | |
| return dict(host=url.split('/')[2], status=response.status, bytes=len(data), | |
| content_range=response.headers.get("Content-Range"), seconds=round(time.monotonic()-start, 2)) | |
| except Exception as exc: | |
| return dict(host=url.split('/')[2], error=type(exc).__name__+": "+str(exc)) | |
| if __name__ == '__main__': | |
| with concurrent.futures.ThreadPoolExecutor() as pool: | |
| for result in pool.map(probe, URLS): | |
| print(result, flush=True) | |