code: def upscale(
      img,
      model,
      tile=None,
      tile_overlap=None,
      window_size=8,
      scale=4,
  ):
      tile = tile or opts.SWIN_tile
      tile_overlap = tile_overlap or opts.SWIN_tile_overlap
  
      img = np.array(img)
      img = img[:, :, ::-1]
      img = np.moveaxis(img, 2, 0) / 255
      img = torch.from_numpy(img).float()
      img = img.unsqueeze(0).to(device_swinir, dtype=devices.dtype)
      with torch.no_grad(), devices.autocast():
          _, _, h_old, w_old = img.size()
          h_pad = (h_old // window_size + 1) * window_size - h_old
          w_pad = (w_old // window_size + 1) * window_size - w_old
          img = torch.cat([img, torch.flip(img, [2])], 2)[
              :, :, : h_old + h_pad, :
          ]
          img = torch.cat([img, torch.flip(img, [3])], 3)[
              :, :, :, : w_old + w_pad
          ]
          output = inference(
              img, model, tile, tile_overlap, window_size, scale
          )
          output = output[..., : h_old * scale, : w_old * scale]
          output = (
              output.data.squeeze().float().cpu().clamp_(0, 1).numpy()
          )
          if output.ndim == 3:
              output = np.transpose(
                  output[[2, 1, 0], :, :], (1, 2, 0)
              )  # CHW-RGB to HCW-BGR
          output = (
              (output * 255.0).round().astype(np.uint8)
          )  # float32 to uint8
          return Image.fromarray(output, "RGB")
  
file_path: stable-diffusion-webui/extensions-builtin/SwinIR/scripts/swinir_model.py
imports: import sys
  import platform
  import numpy
  import torch
  from PIL import Image
  from tqdm import tqdm
  from modules import modelloader, devices, script_callbacks, shared
  from modules.shared import opts, state
  from swinir_model_arch import SwinIR
  from swinir_model_arch_v2 import Swin2SR
  from modules.upscaler import Upscaler, UpscalerData
label_desc: Use image node_id 1 for calling a global function with example usage: upscale(img, model, tile, tile_overlap, window_size, scale) and returns: Image