mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2024-12-29 19:05:05 +08:00
rework #6329 to remove duplicate code and add prevent tab names for showing in ids for scripts that only exist on one tab
This commit is contained in:
parent
997461d3dd
commit
f8d0cf6a6e
@ -1,4 +1,5 @@
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import traceback
|
||||
from collections import namedtuple
|
||||
@ -128,6 +129,15 @@ class Script:
|
||||
"""unused"""
|
||||
return ""
|
||||
|
||||
def elem_id(self, item_id):
|
||||
"""helper function to generate id for a HTML element, constructs final id out of script name, tab and user-supplied item_id"""
|
||||
|
||||
need_tabname = self.show(True) == self.show(False)
|
||||
tabname = ('img2img' if self.is_img2img else 'txt2txt') + "_" if need_tabname else ""
|
||||
title = re.sub(r'[^a-z_0-9]', '', re.sub(r'\s', '_', self.title().lower()))
|
||||
|
||||
return f'script_{tabname}{title}_{item_id}'
|
||||
|
||||
|
||||
current_basedir = paths.script_path
|
||||
|
||||
|
@ -3,18 +3,12 @@ import gradio as gr
|
||||
|
||||
from modules.processing import Processed
|
||||
from modules.shared import opts, cmd_opts, state
|
||||
import re
|
||||
|
||||
class Script(scripts.Script):
|
||||
|
||||
def title(self):
|
||||
return "Custom code"
|
||||
|
||||
def elem_id(self, item_id):
|
||||
gen_elem_id = ('img2img' if self.is_img2img else 'txt2txt') + '_script_' + re.sub(r'\s', '_', self.title().lower()) + '_' + item_id
|
||||
gen_elem_id = re.sub(r'[^a-z_0-9]', '', gen_elem_id)
|
||||
return gen_elem_id
|
||||
|
||||
def show(self, is_img2img):
|
||||
return cmd_opts.allow_code
|
||||
|
||||
|
@ -16,7 +16,6 @@ import k_diffusion as K
|
||||
from PIL import Image
|
||||
from torch import autocast
|
||||
from einops import rearrange, repeat
|
||||
import re
|
||||
|
||||
|
||||
def find_noise_for_image(p, cond, uncond, cfg_scale, steps):
|
||||
@ -123,11 +122,6 @@ class Script(scripts.Script):
|
||||
def title(self):
|
||||
return "img2img alternative test"
|
||||
|
||||
def elem_id(self, item_id):
|
||||
gen_elem_id = ('img2img' if self.is_img2img else 'txt2txt') + '_script_' + re.sub(r'\s', '_', self.title().lower()) + '_' + item_id
|
||||
gen_elem_id = re.sub(r'[^a-z_0-9]', '', gen_elem_id)
|
||||
return gen_elem_id
|
||||
|
||||
def show(self, is_img2img):
|
||||
return is_img2img
|
||||
|
||||
|
@ -8,18 +8,12 @@ from modules import processing, shared, sd_samplers, images
|
||||
from modules.processing import Processed
|
||||
from modules.sd_samplers import samplers
|
||||
from modules.shared import opts, cmd_opts, state
|
||||
import re
|
||||
|
||||
|
||||
class Script(scripts.Script):
|
||||
def title(self):
|
||||
return "Loopback"
|
||||
|
||||
def elem_id(self, item_id):
|
||||
gen_elem_id = ('img2img' if self.is_img2img else 'txt2txt') + '_script_' + re.sub(r'\s', '_', self.title().lower()) + '_' + item_id
|
||||
gen_elem_id = re.sub(r'[^a-z_0-9]', '', gen_elem_id)
|
||||
return gen_elem_id
|
||||
|
||||
def show(self, is_img2img):
|
||||
return is_img2img
|
||||
|
||||
|
@ -10,7 +10,6 @@ from PIL import Image, ImageDraw
|
||||
from modules import images, processing, devices
|
||||
from modules.processing import Processed, process_images
|
||||
from modules.shared import opts, cmd_opts, state
|
||||
import re
|
||||
|
||||
|
||||
# this function is taken from https://github.com/parlance-zz/g-diffuser-bot
|
||||
@ -123,11 +122,6 @@ class Script(scripts.Script):
|
||||
def title(self):
|
||||
return "Outpainting mk2"
|
||||
|
||||
def elem_id(self, item_id):
|
||||
gen_elem_id = ('img2img' if self.is_img2img else 'txt2txt') + '_script_' + re.sub(r'\s', '_', self.title().lower()) + '_' + item_id
|
||||
gen_elem_id = re.sub(r'[^a-z_0-9]', '', gen_elem_id)
|
||||
return gen_elem_id
|
||||
|
||||
def show(self, is_img2img):
|
||||
return is_img2img
|
||||
|
||||
|
@ -7,18 +7,12 @@ from PIL import Image, ImageDraw
|
||||
from modules import images, processing, devices
|
||||
from modules.processing import Processed, process_images
|
||||
from modules.shared import opts, cmd_opts, state
|
||||
import re
|
||||
|
||||
|
||||
class Script(scripts.Script):
|
||||
def title(self):
|
||||
return "Poor man's outpainting"
|
||||
|
||||
def elem_id(self, item_id):
|
||||
gen_elem_id = ('img2img' if self.is_img2img else 'txt2txt') + '_script_' + re.sub(r'\s', '_', self.title().lower()) + '_' + item_id
|
||||
gen_elem_id = re.sub(r'[^a-z_0-9]', '', gen_elem_id)
|
||||
return gen_elem_id
|
||||
|
||||
def show(self, is_img2img):
|
||||
return is_img2img
|
||||
|
||||
|
@ -10,7 +10,6 @@ from modules import images
|
||||
from modules.processing import process_images, Processed
|
||||
from modules.shared import opts, cmd_opts, state
|
||||
import modules.sd_samplers
|
||||
import re
|
||||
|
||||
|
||||
def draw_xy_grid(xs, ys, x_label, y_label, cell):
|
||||
@ -45,11 +44,6 @@ class Script(scripts.Script):
|
||||
def title(self):
|
||||
return "Prompt matrix"
|
||||
|
||||
def elem_id(self, item_id):
|
||||
gen_elem_id = ('img2img' if self.is_img2img else 'txt2txt') + '_script_' + re.sub(r'\s', '_', self.title().lower()) + '_' + item_id
|
||||
gen_elem_id = re.sub(r'[^a-z_0-9]', '', gen_elem_id)
|
||||
return gen_elem_id
|
||||
|
||||
def ui(self, is_img2img):
|
||||
put_at_start = gr.Checkbox(label='Put variable parts at start of prompt', value=False, elem_id=self.elem_id("put_at_start"))
|
||||
different_seeds = gr.Checkbox(label='Use different seed for each picture', value=False, elem_id=self.elem_id("different_seeds"))
|
||||
|
@ -13,7 +13,6 @@ from modules import sd_samplers
|
||||
from modules.processing import Processed, process_images
|
||||
from PIL import Image
|
||||
from modules.shared import opts, cmd_opts, state
|
||||
import re
|
||||
|
||||
|
||||
def process_string_tag(tag):
|
||||
@ -112,11 +111,6 @@ class Script(scripts.Script):
|
||||
def title(self):
|
||||
return "Prompts from file or textbox"
|
||||
|
||||
def elem_id(self, item_id):
|
||||
gen_elem_id = ('img2img' if self.is_img2img else 'txt2txt') + '_script_' + re.sub(r'\s', '_', self.title().lower()) + '_' + item_id
|
||||
gen_elem_id = re.sub(r'[^a-z_0-9]', '', gen_elem_id)
|
||||
return gen_elem_id
|
||||
|
||||
def ui(self, is_img2img):
|
||||
checkbox_iterate = gr.Checkbox(label="Iterate seed every line", value=False, elem_id=self.elem_id("checkbox_iterate"))
|
||||
checkbox_iterate_batch = gr.Checkbox(label="Use same random seed for all lines", value=False, elem_id=self.elem_id("checkbox_iterate_batch"))
|
||||
|
@ -7,18 +7,12 @@ from PIL import Image
|
||||
from modules import processing, shared, sd_samplers, images, devices
|
||||
from modules.processing import Processed
|
||||
from modules.shared import opts, cmd_opts, state
|
||||
import re
|
||||
|
||||
|
||||
class Script(scripts.Script):
|
||||
def title(self):
|
||||
return "SD upscale"
|
||||
|
||||
def elem_id(self, item_id):
|
||||
gen_elem_id = ('img2img' if self.is_img2img else 'txt2txt') + '_script_' + re.sub(r'\s', '_', self.title().lower()) + '_' + item_id
|
||||
gen_elem_id = re.sub(r'[^a-z_0-9]', '', gen_elem_id)
|
||||
return gen_elem_id
|
||||
|
||||
def show(self, is_img2img):
|
||||
return is_img2img
|
||||
|
||||
|
@ -290,11 +290,6 @@ class Script(scripts.Script):
|
||||
def title(self):
|
||||
return "X/Y plot"
|
||||
|
||||
def elem_id(self, item_id):
|
||||
gen_elem_id = ('img2img' if self.is_img2img else 'txt2txt') + '_script_' + re.sub(r'\s', '_', self.title().lower()) + '_' + item_id
|
||||
gen_elem_id = re.sub(r'[^a-z_0-9]', '', gen_elem_id)
|
||||
return gen_elem_id
|
||||
|
||||
def ui(self, is_img2img):
|
||||
current_axis_options = [x for x in axis_options if type(x) == AxisOption or type(x) == AxisOptionImg2Img and is_img2img]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user