Commit f8d0cf6a authored by AUTOMATIC's avatar AUTOMATIC
Browse files

rework #6329 to remove duplicate code and add prevent tab names for showing in...

rework #6329 to remove duplicate code and add prevent tab names for showing in ids for scripts that only exist on one tab
parent 997461d3
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
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

+0 −6
Original line number Diff line number Diff line
@@ -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

+0 −6
Original line number Diff line number Diff line
@@ -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

+0 −6
Original line number Diff line number Diff line
@@ -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

+0 −6
Original line number Diff line number Diff line
@@ -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

Loading