Created
April 13, 2023 11:05
-
-
Save laksjdjf/ef23b8290b0e1e1f9a9701168c396ffa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import modules.scripts as scripts | |
import gradio as gr | |
from modules.processing import StableDiffusionProcessing, process_images | |
class Script(scripts.Script): | |
def __init__(self): | |
pass | |
def title(self): | |
return "scale" | |
def ui(self, is_img2img): | |
with gr.Group(): | |
with gr.Row(): | |
scale = gr.Textbox(label="scale factor:number or list of 4 numbers(a,b,c,d)",value=1) | |
return [scale] | |
def run( | |
self, | |
p: StableDiffusionProcessing, | |
scale:str, | |
): | |
pre_scale_factor = p.sd_model.scale_factor | |
scale = [pre_scale_factor / float(s) for s in scale.split(",")] | |
#(batch_size, channel, height, width) | |
p.sd_model.scale_factor = torch.tensor(scale).unsqueeze(0).unsqueeze(-1).unsqueeze(-1).to("cuda", dtype=p.sd_model.first_stage_model.dtype) | |
result = process_images(p) | |
p.sd_model.scale_factor = pre_scale_factor | |
return result | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment