Download models/utils.py from yhzhai/WSCL: direct link, hf CLI and curl.
- Browser
- Download file 594 Bytes
-
https://huggingface.co/spaces/yhzhai/WSCL/resolve/main/models/utils.py
- Command line
-
hf download hf://spaces/yhzhai/WSCL/models/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/yhzhai/WSCL/resolve/main/models/utils.py
594 Bytes
| import os | |
| import sys | |
| try: | |
| from urllib import urlretrieve | |
| except ImportError: | |
| from urllib.request import urlretrieve | |
| import torch | |
| def load_url(url, model_dir="./pretrained", map_location=torch.device("cpu")): | |
| if not os.path.exists(model_dir): | |
| os.makedirs(model_dir) | |
| filename = url.split("/")[-1] | |
| cached_file = os.path.join(model_dir, filename) | |
| if not os.path.exists(cached_file): | |
| sys.stderr.write('Downloading: "{}" to {}\n'.format(url, cached_file)) | |
| urlretrieve(url, cached_file) | |
| return torch.load(cached_file, map_location=map_location) | |