o yf@sXddlmZmZmZddlmZddlmZmZddl m Z GdddeZ ddZ d S) ) modelloaderdeviceserrors)opts)Upscaler UpscalerData)upscale_with_modelcs2eZdZfddZddZdefddZZS)UpscalerESRGANcsd|_d|_d|_g|_||_t|jddgd}g}t|dkr2t |j|j|d}| ||D]}| d r?|j}nt |}t |||d}|j |q4dS) NESRGANz>https://github.com/cszn/KAIR/releases/download/v1.0/ESRGAN.pthZ ESRGAN_4xz.pt.pth) ext_filterrhttp)name model_url model_namescalers user_pathsuper__init__ find_modelslenrappend startswithr friendly_name)selfdirname model_pathsr scaler_datafiler __class__eC:\Users\Luke\Documents\Stable diffusion\Automatic1111\stable-diffusion-webui\modules\esrgan_model.pyrs$     zUpscalerESRGAN.__init__cCsPz||}Wntytjd|dd|YSw|tjt||S)NzUnable to load ESRGAN model T)exc_info) load_model Exceptionrreporttor device_esrganesrgan_upscale)rimgselected_modelmodelr"r"r# do_upscales   zUpscalerESRGAN.do_upscalepathcCsR|drtj|j|j|jdd}n|}tj|tjj dkr$dddSdddS)Nrr )url model_dir file_namempscpur )deviceexpected_architecture) rrload_file_from_urlrmodel_download_pathrload_spandrel_modelrr)type)rr/filenamer"r"r#r%&s  zUpscalerESRGAN.load_model)__name__ __module__ __qualname__rr.strr% __classcell__r"r"r r#r s  r cCst||tjtjdS)N) tile_size tile_overlap)rr ESRGAN_tileESRGAN_tile_overlap)r-r+r"r"r#r*8s r*N) modulesrrrmodules.sharedrmodules.upscalerrrZmodules.upscaler_utilsrr r*r"r"r"r#s    1