28 lines
871 B
Python

from PIL import Image
from utils import tensor_to_pil, pil_to_tensor
from comfy_extras.nodes_upscale_model import ImageUpscaleWithModel
from modules import shared
if (not hasattr(Image, 'Resampling')): # For older versions of Pillow
Image.Resampling = Image
class Upscaler:
def upscale(self, img: Image, scale, selected_model: str = None):
if scale == 1.0:
return img
if (shared.actual_upscaler is None):
return img.resize((img.width * scale, img.height * scale), Image.Resampling.LANCZOS)
(upscaled,) = ImageUpscaleWithModel().upscale(shared.actual_upscaler, shared.batch_as_tensor)
shared.batch = [tensor_to_pil(upscaled, i) for i in range(len(upscaled))]
return shared.batch[0]
class UpscalerData:
name = ""
data_path = ""
def __init__(self):
self.scaler = Upscaler()