Spaces:
Runtime error
Runtime error
Download modules/upscaler.py from adarshsmit/Fooocus: direct link, hf CLI and curl.
- Browser
- Download file 931 Bytes
-
https://huggingface.co/spaces/adarshsmit/Fooocus/resolve/main/modules/upscaler.py
- Command line
-
hf download hf://spaces/adarshsmit/Fooocus/modules/upscaler.py
-
curl -L -o upscaler.py https://huggingface.co/spaces/adarshsmit/Fooocus/resolve/main/modules/upscaler.py
931 Bytes
| from collections import OrderedDict | |
| import modules.core as core | |
| import torch | |
| from ldm_patched.contrib.external_upscale_model import ImageUpscaleWithModel | |
| from ldm_patched.pfn.architecture.RRDB import RRDBNet as ESRGAN | |
| from modules.config import downloading_upscale_model | |
| opImageUpscaleWithModel = ImageUpscaleWithModel() | |
| model = None | |
| def perform_upscale(img): | |
| global model | |
| print(f'Upscaling image with shape {str(img.shape)} ...') | |
| if model is None: | |
| model_filename = downloading_upscale_model() | |
| sd = torch.load(model_filename, weights_only=True) | |
| sdo = OrderedDict() | |
| for k, v in sd.items(): | |
| sdo[k.replace('residual_block_', 'RDB')] = v | |
| del sd | |
| model = ESRGAN(sdo) | |
| model.cpu() | |
| model.eval() | |
| img = core.numpy_to_pytorch(img) | |
| img = opImageUpscaleWithModel.upscale(model, img)[0] | |
| img = core.pytorch_to_numpy(img)[0] | |
| return img | |