File size: 1,532 Bytes
c336648 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import math
import os
import sys
import traceback
import random
import modules.scripts as scripts
import modules.images as images
import gradio as gr
from modules.processing import Processed, process_images
from PIL import Image
from modules.shared import opts, cmd_opts, state
class Script(scripts.Script):
def title(self):
return "Lanczos quick upscale"
def ui(self, is_img2img):
upscale_factor = gr.Slider(minimum=1, maximum=4, step=0.1, label='Upscale factor', value=2)
return [upscale_factor]
def run(self, p, upscale_factor):
infotexts = []
def simple_upscale(img, upscale_factor):
w, h = img.size
w = int(w * upscale_factor)
h = int(h * upscale_factor)
return img.resize((w, h), Image.Resampling.LANCZOS)
state.job_count = p.n_iter
p.n_iter = 1
p.do_not_save_samples = True
output_images = []
for batch_no in range(state.job_count):
# print(f"\nJob : {batch_no}/{state.job_count}\nSeed : {p.seed}\nPrompt : {p.prompt}")
proc = process_images(p)
infotexts.append(proc.info)
proc.images[0] = simple_upscale(proc.images[0], upscale_factor)
images.save_image(proc.images[0], p.outpath_samples, "", proc.seed, proc.prompt, opts.samples_format, info= proc.info, p=p)
output_images += proc.images
p.seed = proc.seed + 1
return Processed(p, images, infotexts=infotexts,index_of_first_image=0)
|