Download utils/__init__.py from amish1729/LFUNet: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/amish1729/LFUNet/resolve/main/utils/__init__.py
- Command line
-
hf download hf://spaces/amish1729/LFUNet/utils/__init__.py
-
curl -L -o __init__.py https://huggingface.co/spaces/amish1729/LFUNet/resolve/main/utils/__init__.py
1.03 kB
| import numpy as np | |
| from PIL import Image | |
| import requests | |
| import functools | |
| from tqdm.notebook import tqdm | |
| import shutil | |
| def image_to_array(image: Image) -> np.ndarray: | |
| """Convert Image to array""" | |
| return np.asarray(image).astype('uint8') | |
| def load_image(img_path: str) -> Image: | |
| """Load image to array""" | |
| return Image.open(img_path) | |
| def download_data(url, save_path, file_size=None): | |
| """Downloads data from `url` to `save_path`""" | |
| r = requests.get(url, stream=True, allow_redirects=True) | |
| if r.status_code != 200: | |
| r.raise_for_status() | |
| raise RuntimeError(f'Request to {url} returned status code {r.status_code}') | |
| if file_size is None: | |
| file_size = int(r.headers.get('content-length', 0)) | |
| r.raw.read = functools.partial(r.raw.read, decode_content=True) # Decompress if needed | |
| with tqdm.wrapattr(r.raw, 'read', total=file_size, desc='') as r_raw: | |
| with open(save_path, 'wb') as f: | |
| shutil.copyfileobj(r_raw, f) | |
| def plot_image_triple(): | |
| pass |