diff --git a/CHANGELOG.md b/CHANGELOG.md
index a9f40cf66..81eb62014 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,8 +1,14 @@
# Change Log for SD.Next
-## Update for 2024-02-09
+## Update for 2024-02-10
- **improvements**:
+ - **IP Adapter** major refactor
+ - support for multiple input images per each ip adapter
+ - support for multiple concurrent ip adapters
+ *note*: you cannot mix&match ip adapters that use different CLiP models, for example `Base` and `Base ViT-G`
+ - unified interface in txt2img, img2img and control
+ - enhanced xyz grid support
- **FaceID** now works with multiple input images
- [DeepCache](https://github.com/horseee/DeepCache) model acceleration
it can produce massive speedups (2x-5x) with no overhead, but with some loss of quality
@@ -29,6 +35,7 @@
- better handling of `fp16` models/vae, thanks @lshqqytiger
- **OpenVINO**
- update to `torch 2.2.0`
+ - **HyperTile** add swap size option, thanks @Disty0
- add `--theme` cli param to force theme on startup
- add `--allow-paths` cli param to add additional paths that are allowed to be accessed via web, thanks @OuticNZ
- **wiki**:
diff --git a/cli/process.py b/cli/process.py
index 3bcd97ed9..0ad9a6347 100644
--- a/cli/process.py
+++ b/cli/process.py
@@ -22,7 +22,7 @@ all_images_by_type = {}
class Result():
- def __init__(self, typ: str, fn: str, tag: str = None, requested: list = []): # noqa: B006
+ def __init__(self, typ: str, fn: str, tag: str = None, requested: list = []):
self.type = typ
self.input = fn
self.output = ''
@@ -262,7 +262,7 @@ def save_image(res: Result, folder: str):
return res
-def file(filename: str, folder: str, tag = None, requested = []): # noqa: B006
+def file(filename: str, folder: str, tag = None, requested = []):
# initialize result dict
res = Result(fn = filename, typ='unknown', tag=tag, requested = requested)
# open image
diff --git a/javascript/sdnext.css b/javascript/sdnext.css
index b17a0db68..56f8c8f5b 100644
--- a/javascript/sdnext.css
+++ b/javascript/sdnext.css
@@ -264,6 +264,7 @@ table.settings-value-table td { padding: 0.4em; border: 1px solid #ccc; max-widt
/* control */
#control_input_type { max-width: 18em }
#control_settings .small-accordion .form { min-width: 350px !important }
+#control_script_container { display: block; margin-top: 1em; border-width: 2px 0 0 0; border-style: solid; border-color: var(--highlight-color); }
.control-button { min-height: 42px; max-height: 42px; line-height: 1em; }
.control-tabs > .tab-nav { margin-bottom: 0; margin-top: 0; }
.control-unit { max-width: 1200px; padding: 0 !important; margin-top: -10px !important; }
diff --git a/modules/control/run.py b/modules/control/run.py
index 52f7a2532..a08bec715 100644
--- a/modules/control/run.py
+++ b/modules/control/run.py
@@ -40,7 +40,6 @@ def control_run(units: List[unit.Unit], inputs, inits, mask, unit_type: str, is_
resize_mode_after, resize_name_after, width_after, height_after, scale_by_after, selected_scale_tab_after,
denoising_strength, batch_count, batch_size,
video_skip_frames, video_type, video_duration, video_loop, video_pad, video_interpolate,
- ip_adapter, ip_scale, ip_image,
*input_script_args # pylint: disable=unused-argument
):
global pipe, original_pipeline # pylint: disable=global-statement
@@ -463,11 +462,6 @@ def control_run(units: List[unit.Unit], inputs, inits, mask, unit_type: str, is_
if hasattr(p, 'init_images') and p.init_images is None: # delete as its set via task_args
del p.init_images
- # ip adapter apply is run in processing.process_images
- p.ip_adapter_name = ip_adapter
- p.ip_adapter_scale = ip_scale
- p.ip_adapter_image = ip_image or input_image
-
# pipeline
output = None
if pipe is not None: # run new pipeline
diff --git a/modules/control/unit.py b/modules/control/unit.py
index 1b57b3a2a..f07b70529 100644
--- a/modules/control/unit.py
+++ b/modules/control/unit.py
@@ -36,7 +36,7 @@ class Unit(): # mashup of gradio controls and mapping to actual implementation c
control_start = None,
control_end = None,
result_txt = None,
- extra_controls: list = [], # noqa B006
+ extra_controls: list = [],
):
self.enabled = enabled or False
self.type = unit_type
diff --git a/modules/errors.py b/modules/errors.py
index 0e5a0b094..c86d6baea 100644
--- a/modules/errors.py
+++ b/modules/errors.py
@@ -20,7 +20,7 @@ traceback_install(console=console, extra_lines=1, width=console.width, word_wrap
already_displayed = {}
-def install(suppress=[]): # noqa: B006
+def install(suppress=[]):
warnings.filterwarnings("ignore", category=UserWarning)
pretty_install(console=console)
traceback_install(console=console, extra_lines=1, width=console.width, word_wrap=False, indent_guides=False, suppress=suppress)
@@ -35,7 +35,7 @@ def print_error_explanation(message):
log.error(line)
-def display(e: Exception, task, suppress=[]): # noqa: B006
+def display(e: Exception, task, suppress=[]):
log.error(f"{task or 'error'}: {type(e).__name__}")
console.print_exception(show_locals=False, max_frames=10, extra_lines=1, suppress=suppress, theme="ansi_dark", word_wrap=False, width=console.width)
@@ -54,7 +54,7 @@ def run(code, task):
display(e, task)
-def exception(suppress=[]): # noqa: B006
+def exception(suppress=[]):
console.print_exception(show_locals=False, max_frames=10, extra_lines=2, suppress=suppress, theme="ansi_dark", word_wrap=False, width=min([console.width, 200]))
diff --git a/modules/face/__init__.py b/modules/face/__init__.py
index e1f4a2583..1e601a97f 100644
--- a/modules/face/__init__.py
+++ b/modules/face/__init__.py
@@ -88,6 +88,8 @@ class Script(scripts.Script):
return [mode, gallery, ip_model, ip_override, ip_cache, ip_strength, ip_structure, id_strength, id_conditioning, id_cache, pm_trigger, pm_strength, pm_start, fs_cache]
def run(self, p: processing.StableDiffusionProcessing, mode, input_images, ip_model, ip_override, ip_cache, ip_strength, ip_structure, id_strength, id_conditioning, id_cache, pm_trigger, pm_strength, pm_start, fs_cache): # pylint: disable=arguments-differ, unused-argument
+ if shared.backend != shared.Backend.DIFFUSERS:
+ return
if input_images is None or len(input_images) == 0:
shared.log.error('Face: no init images')
return None
@@ -101,11 +103,11 @@ class Script(scripts.Script):
from modules.api.api import decode_base64_to_image
input_images[i] = decode_base64_to_image(image).convert("RGB")
- processed = None
for i, image in enumerate(input_images):
if not isinstance(image, Image.Image):
input_images[i] = Image.open(image['name'])
+ processed = None
processing.process_init(p)
if mode == 'FaceID': # faceid runs as ipadapter in its own pipeline
from modules.face.insightface import get_app
diff --git a/modules/ipadapter.py b/modules/ipadapter.py
index 269fc9526..1564ca9c6 100644
--- a/modules/ipadapter.py
+++ b/modules/ipadapter.py
@@ -9,6 +9,7 @@ TODO ipadapter items:
import os
import time
+from PIL import Image
from modules import processing, shared, devices
@@ -28,6 +29,46 @@ ADAPTERS = {
'Plus Face ViT-H SXDL': 'ip-adapter-plus-face_sdxl_vit-h.safetensors',
}
+
+def get_images(input_images):
+ output_images = []
+ if input_images is None or len(input_images) == 0:
+ shared.log.error('IP adapter: no init images')
+ return None
+ if shared.sd_model_type != 'sd' and shared.sd_model_type != 'sdxl':
+ shared.log.error('IP adapter: base model not supported')
+ return None
+ if isinstance(input_images, str):
+ from modules.api.api import decode_base64_to_image
+ input_images = decode_base64_to_image(input_images).convert("RGB")
+ input_images = input_images.copy()
+ if not isinstance(input_images, list):
+ input_images = [input_images]
+ for image in input_images:
+ if isinstance(image, list):
+ output_images.append(get_images(image)) # recursive
+ elif isinstance(image, Image.Image):
+ output_images.append(image)
+ elif isinstance(image, str):
+ from modules.api.api import decode_base64_to_image
+ decoded_image = decode_base64_to_image(image).convert("RGB")
+ output_images.append(decoded_image)
+ elif hasattr(image, 'name'): # gradio gallery entry
+ pil_image = Image.open(image.name)
+ pil_image.load()
+ output_images.append(pil_image)
+ else:
+ shared.log.error(f'IP adapter: unknown input: {image}')
+ return output_images
+
+
+def get_scales(adapter_scales, adapter_images):
+ output_scales = [adapter_scales] if not isinstance(adapter_scales, list) else adapter_scales
+ while len(output_scales) < len(adapter_images):
+ output_scales.append(output_scales[-1])
+ return output_scales
+
+
def unapply(pipe): # pylint: disable=arguments-differ
try:
if hasattr(pipe, 'set_ip_adapter_scale'):
@@ -40,31 +81,39 @@ def unapply(pipe): # pylint: disable=arguments-differ
pass
-def apply(pipe, p: processing.StableDiffusionProcessing, adapter_name='None', scale=1.0, image=None):
+def apply(pipe, p: processing.StableDiffusionProcessing, adapter_names=[], adapter_scales=[1.0], adapter_images=[]):
global clip_loaded # pylint: disable=global-statement
# overrides
- if hasattr(p, 'ip_adapter_name'):
- adapter = ADAPTERS.get(p.ip_adapter_name, None)
- adapter_name = p.ip_adapter_name
+ if hasattr(p, 'ip_adapter_names'):
+ if isinstance(p.ip_adapter_names, str):
+ p.ip_adapter_names = [p.ip_adapter_names]
+ adapters = [ADAPTERS.get(adapter, None) for adapter in p.ip_adapter_names]
+ adapter_names = p.ip_adapter_names
else:
- adapter = ADAPTERS.get(adapter_name, None)
- if hasattr(p, 'ip_adapter_scale'):
- scale = p.ip_adapter_scale
- if hasattr(p, 'ip_adapter_image'):
- image = p.ip_adapter_image
- if adapter is None:
+ if isinstance(adapter_names, str):
+ adapter_names = [adapter_names]
+ adapters = [ADAPTERS.get(adapter, None) for adapter in adapter_names]
+ adapters = [adapter for adapter in adapters if adapter is not None and adapter.lower() != 'none']
+ if len(adapters) == 0:
unapply(pipe)
return False
+ if hasattr(p, 'ip_adapter_scales'):
+ adapter_scales = p.ip_adapter_scales
+ if hasattr(p, 'ip_adapter_images'):
+ adapter_images = p.ip_adapter_images
+ adapter_images = get_images(adapter_images)
+ adapter_scales = get_scales(adapter_scales, adapter_images)
+
# init code
if pipe is None:
return False
if shared.backend != shared.Backend.DIFFUSERS:
shared.log.warning('IP adapter: not in diffusers mode')
return False
- if image is None and adapter != 'none':
+ if len(adapter_images) == 0:
shared.log.error('IP adapter: no image provided')
- adapter = 'none' # unload adapter if previously loaded as it will cause runtime errors
- if adapter == 'none':
+ adapters = [] # unload adapter if previously loaded as it will cause runtime errors
+ if len(adapters) == 0:
unapply(pipe)
return False
if not hasattr(pipe, 'load_ip_adapter'):
@@ -74,49 +123,48 @@ def apply(pipe, p: processing.StableDiffusionProcessing, adapter_name='None', sc
shared.log.error(f'IP adapter: unsupported model type: {shared.sd_model_type}')
return False
- # which clip to use
- if 'ViT' not in adapter_name:
- clip_repo = base_repo
- clip_subfolder = 'models/image_encoder' if shared.sd_model_type == 'sd' else 'sdxl_models/image_encoder' # defaults per model
- elif 'ViT-H' in adapter_name:
- clip_repo = base_repo
- clip_subfolder = 'models/image_encoder' # this is vit-h
- elif 'ViT-G' in adapter_name:
- clip_repo = base_repo
- clip_subfolder = 'sdxl_models/image_encoder' # this is vit-g
- else:
- shared.log.error(f'IP adapter: unknown model type: {adapter_name}')
- return False
+ for adapter_name in adapter_names:
+ # which clip to use
+ if 'ViT' not in adapter_name:
+ clip_repo = base_repo
+ clip_subfolder = 'models/image_encoder' if shared.sd_model_type == 'sd' else 'sdxl_models/image_encoder' # defaults per model
+ elif 'ViT-H' in adapter_name:
+ clip_repo = base_repo
+ clip_subfolder = 'models/image_encoder' # this is vit-h
+ elif 'ViT-G' in adapter_name:
+ clip_repo = base_repo
+ clip_subfolder = 'sdxl_models/image_encoder' # this is vit-g
+ else:
+ shared.log.error(f'IP adapter: unknown model type: {adapter_name}')
+ return False
- # load feature extractor used by ip adapter
- if pipe.feature_extractor is None:
- from transformers import CLIPImageProcessor
- shared.log.debug('IP adapter load: feature extractor')
- pipe.feature_extractor = CLIPImageProcessor()
- # load image encoder used by ip adapter
- if pipe.image_encoder is None or clip_loaded != f'{clip_repo}/{clip_subfolder}':
- try:
- from transformers import CLIPVisionModelWithProjection
- shared.log.debug(f'IP adapter load: image encoder="{clip_repo}/{clip_subfolder}"')
- pipe.image_encoder = CLIPVisionModelWithProjection.from_pretrained(clip_repo, subfolder=clip_subfolder, torch_dtype=devices.dtype, cache_dir=shared.opts.diffusers_dir, use_safetensors=True)
- clip_loaded = f'{clip_repo}/{clip_subfolder}'
- except Exception as e:
- shared.log.error(f'IP adapter: failed to load image encoder: {e}')
- return
- pipe.image_encoder.to(devices.device)
+ # load feature extractor used by ip adapter
+ if pipe.feature_extractor is None:
+ from transformers import CLIPImageProcessor
+ shared.log.debug('IP adapter load: feature extractor')
+ pipe.feature_extractor = CLIPImageProcessor()
+ # load image encoder used by ip adapter
+ if pipe.image_encoder is None or clip_loaded != f'{clip_repo}/{clip_subfolder}':
+ try:
+ from transformers import CLIPVisionModelWithProjection
+ shared.log.debug(f'IP adapter load: image encoder="{clip_repo}/{clip_subfolder}"')
+ pipe.image_encoder = CLIPVisionModelWithProjection.from_pretrained(clip_repo, subfolder=clip_subfolder, torch_dtype=devices.dtype, cache_dir=shared.opts.diffusers_dir, use_safetensors=True)
+ clip_loaded = f'{clip_repo}/{clip_subfolder}'
+ except Exception as e:
+ shared.log.error(f'IP adapter: failed to load image encoder: {e}')
+ return
+ pipe.image_encoder.to(devices.device)
# main code
t0 = time.time()
ip_subfolder = 'models' if shared.sd_model_type == 'sd' else 'sdxl_models'
- pipe.load_ip_adapter(base_repo, subfolder=ip_subfolder, weight_name=adapter)
- pipe.set_ip_adapter_scale(scale)
- t1 = time.time()
- shared.log.info(f'IP adapter: adapter="{ip_subfolder}/{adapter}" scale={scale} image={image} time={t1-t0:.2f}')
-
- if isinstance(image, str):
- from modules.api.api import decode_base64_to_image
- image = decode_base64_to_image(image).convert("RGB")
-
- p.task_args['ip_adapter_image'] = [image]
- p.extra_generation_params["IP Adapter"] = f'{os.path.splitext(adapter)[0]}:{scale}'
+ try:
+ pipe.load_ip_adapter([base_repo], subfolder=[ip_subfolder], weight_name=adapters)
+ pipe.set_ip_adapter_scale(adapter_scales)
+ p.task_args['ip_adapter_image'] = adapter_images
+ p.extra_generation_params["IP Adapter"] = ';'.join([f'{os.path.splitext(adapter)[0]}:{scale}' for adapter, scale in zip(adapter_names, adapter_scales)])
+ t1 = time.time()
+ shared.log.info(f'IP adapter: adapters={adapter_names} scale={adapter_scales} image={adapter_images} time={t1-t0:.2f}')
+ except Exception as e:
+ shared.log.error(f'IP adapter failed to load: repo={base_repo} folder={ip_subfolder} weights={adapters} {e}')
return True
diff --git a/modules/processing_class.py b/modules/processing_class.py
index 85a6bce52..63e082091 100644
--- a/modules/processing_class.py
+++ b/modules/processing_class.py
@@ -115,9 +115,9 @@ class StableDiffusionProcessing:
self.script_args_value: list = field(default=None, init=False)
self.scripts_setup_complete: bool = field(default=False, init=False)
# ip adapter
- self.ip_adapter_name = None
- self.ip_adapter_scale = 1.0
- self.ip_adapter_image = None
+ self.ip_adapter_names = None
+ self.ip_adapter_scales = 0.0
+ self.ip_adapter_images = None
# hdr
self.hdr_mode=hdr_mode
self.hdr_brightness=hdr_brightness
diff --git a/modules/rife/model_ifnet.py b/modules/rife/model_ifnet.py
index 76ca23e8a..843430bee 100644
--- a/modules/rife/model_ifnet.py
+++ b/modules/rife/model_ifnet.py
@@ -82,7 +82,7 @@ class IFNet(nn.Module):
# self.contextnet = Contextnet()
# self.unet = Unet()
- def forward( self, x, timestep=0.5, scale_list=[8, 4, 2, 1], training=False, fastmode=True, ensemble=False): # pylint: disable=dangerous-default-value, unused-argument # noqa: B006
+ def forward( self, x, timestep=0.5, scale_list=[8, 4, 2, 1], training=False, fastmode=True, ensemble=False): # pylint: disable=dangerous-default-value, unused-argument
if training is False:
channel = x.shape[1] // 2
img0 = x[:, :channel]
diff --git a/modules/scripts.py b/modules/scripts.py
index 90dc25e08..32ea6bf94 100644
--- a/modules/scripts.py
+++ b/modules/scripts.py
@@ -37,6 +37,7 @@ class Script:
infotext_fields = None
paste_field_names = None
section = None
+ standalone = False
def title(self):
"""this function should return the title of the script. This is what will be displayed in the dropdown menu."""
@@ -449,8 +450,31 @@ class ScriptRunner:
inputs_alwayson += [script.alwayson for _ in controls]
script.args_to = len(inputs)
- dropdown = gr.Dropdown(label="Script", elem_id=f'{parent}_script_list', choices=["None"] + self.titles, value="None", type="index")
- inputs.insert(0, dropdown)
+ with gr.Row():
+ dropdown = gr.Dropdown(label="Script", elem_id=f'{parent}_script_list', choices=["None"] + self.titles, value="None", type="index")
+ inputs.insert(0, dropdown)
+
+ with gr.Row():
+ for script in self.alwayson_scripts:
+ if not script.standalone:
+ continue
+ t0 = time.time()
+ with gr.Group(elem_id=f'{parent}_script_{script.title().lower().replace(" ", "_")}', elem_classes=['extension-script']) as group:
+ create_script_ui(script, inputs, inputs_alwayson)
+ script.group = group
+ time_setup[script.title()] = time_setup.get(script.title(), 0) + (time.time()-t0)
+
+ with gr.Row():
+ with gr.Accordion(label="Extensions", elem_id=f'{parent}_script_alwayson') if accordion else gr.Group():
+ for script in self.alwayson_scripts:
+ if script.standalone:
+ continue
+ t0 = time.time()
+ with gr.Group(elem_id=f'{parent}_script_{script.title().lower().replace(" ", "_")}', elem_classes=['extension-script']) as group:
+ create_script_ui(script, inputs, inputs_alwayson)
+ script.group = group
+ time_setup[script.title()] = time_setup.get(script.title(), 0) + (time.time()-t0)
+
for script in self.selectable_scripts:
with gr.Group(visible=False) as group:
t0 = time.time()
@@ -481,14 +505,6 @@ class ScriptRunner:
else:
return gr.update(visible=False)
- with gr.Accordion(label="Extensions", elem_id=f'{parent}_script_alwayson') if accordion else gr.Group():
- for script in self.alwayson_scripts:
- t0 = time.time()
- with gr.Group(elem_id=f'{parent}_script_{script.title().lower().replace(" ", "_")}', elem_classes=['extension-script']) as group:
- create_script_ui(script, inputs, inputs_alwayson)
- script.group = group
- time_setup[script.title()] = time_setup.get(script.title(), 0) + (time.time()-t0)
-
self.infotext_fields.append( (dropdown, lambda x: gr.update(value=x.get('Script', 'None'))) )
self.infotext_fields.extend( [(script.group, onload_script_visibility) for script in self.selectable_scripts] )
return inputs
diff --git a/modules/sd_models.py b/modules/sd_models.py
index 724dca68e..44c20d3cf 100644
--- a/modules/sd_models.py
+++ b/modules/sd_models.py
@@ -1023,7 +1023,7 @@ def get_diffusers_task(pipe: diffusers.DiffusionPipeline) -> DiffusersTaskType:
return DiffusersTaskType.TEXT_2_IMAGE
-def switch_pipe(cls: diffusers.DiffusionPipeline, pipeline: diffusers.DiffusionPipeline = None, args = {}): # noqa:B006
+def switch_pipe(cls: diffusers.DiffusionPipeline, pipeline: diffusers.DiffusionPipeline = None, args = {}):
"""
args:
- cls: can be pipeline class or a string from custom pipelines
diff --git a/modules/ui_control.py b/modules/ui_control.py
index afa3e1e93..7adaf0815 100644
--- a/modules/ui_control.py
+++ b/modules/ui_control.py
@@ -9,7 +9,7 @@ from modules.control.units import xs # vislearn ControlNet-XS
from modules.control.units import lite # vislearn ControlNet-XS
from modules.control.units import t2iadapter # TencentARC T2I-Adapter
from modules.control.units import reference # reference pipeline
-from modules import errors, shared, progress, sd_samplers, ui_components, ui_symbols, ui_common, ui_sections, generation_parameters_copypaste, call_queue, scripts, masking, ipadapter, images # pylint: disable=ungrouped-imports
+from modules import errors, shared, progress, sd_samplers, ui_components, ui_symbols, ui_common, ui_sections, generation_parameters_copypaste, call_queue, scripts, masking, images # pylint: disable=ungrouped-imports
from modules import ui_control_helpers as helpers
@@ -118,10 +118,6 @@ def create_ui(_blocks: gr.Blocks=None):
video_interpolate = gr.Slider(label='Interpolate frames', minimum=0, maximum=24, step=1, value=0, visible=False)
video_type.change(fn=helpers.video_type_change, inputs=[video_type], outputs=[video_duration, video_loop, video_pad, video_interpolate])
- with gr.Accordion(open=False, label="Extensions", elem_id="control_extensions", elem_classes=["small-accordion"]):
- with gr.Group(elem_id="control_script_container"):
- input_script_args = scripts.scripts_current.setup_ui(parent='control', accordion=False)
-
with gr.Row():
override_settings = ui_common.create_override_inputs('control')
@@ -177,413 +173,409 @@ def create_ui(_blocks: gr.Blocks=None):
with gr.Tab('Preview', id='preview-image') as tab_image:
preview_process = gr.Image(label="Preview", show_label=False, type="pil", source="upload", interactive=False, height=gr_height, visible=True, elem_id='control_preview', elem_classes=['control-image'])
- with gr.Tabs(elem_id='control-tabs') as _tabs_control_type:
+ with gr.Accordion('Control elements'):
+ with gr.Tabs(elem_id='control-tabs') as _tabs_control_type:
- with gr.Tab('ControlNet') as _tab_controlnet:
- gr.HTML('ControlNet')
- with gr.Row():
- extra_controls = [
- gr.Checkbox(label="Guess mode", value=False, scale=3),
- ]
- num_controlnet_units = gr.Slider(label="Units", minimum=1, maximum=max_units, step=1, value=1, scale=1)
- controlnet_ui_units = [] # list of hidable accordions
- for i in range(max_units):
- enabled = True if i==0 else False
- with gr.Accordion(f'ControlNet unit {i+1}', visible= i < num_controlnet_units.value, elem_classes='control-unit') as unit_ui:
- with gr.Row():
- enabled_cb = gr.Checkbox(enabled, label='', container=False, show_label=False)
- process_id = gr.Dropdown(label="Processor", choices=processors.list_models(), value='None')
- model_id = gr.Dropdown(label="ControlNet", choices=controlnet.list_models(), value='None')
- ui_common.create_refresh_button(model_id, controlnet.list_models, lambda: {"choices": controlnet.list_models(refresh=True)}, f'refresh_controlnet_models_{i}')
- model_strength = gr.Slider(label="Strength", minimum=0.01, maximum=2.0, step=0.01, value=1.0-i/10)
- control_start = gr.Slider(label="Start", minimum=0.0, maximum=1.0, step=0.05, value=0)
- control_end = gr.Slider(label="End", minimum=0.0, maximum=1.0, step=0.05, value=1.0)
- reset_btn = ui_components.ToolButton(value=ui_symbols.reset)
- image_upload = gr.UploadButton(label=ui_symbols.upload, file_types=['image'], elem_classes=['form', 'gradio-button', 'tool'])
- image_reuse= ui_components.ToolButton(value=ui_symbols.reuse)
- process_btn= ui_components.ToolButton(value=ui_symbols.preview)
- image_preview = gr.Image(label="Input", type="pil", source="upload", height=128, width=128, visible=False, interactive=True, show_label=False, show_download_button=False, container=False)
- controlnet_ui_units.append(unit_ui)
- units.append(unit.Unit(
- unit_type = 'controlnet',
- enabled = enabled,
- result_txt = result_txt,
- enabled_cb = enabled_cb,
- reset_btn = reset_btn,
- process_id = process_id,
- model_id = model_id,
- model_strength = model_strength,
- preview_process = preview_process,
- preview_btn = process_btn,
- image_upload = image_upload,
- image_reuse = image_reuse,
- image_preview = image_preview,
- control_start = control_start,
- control_end = control_end,
- extra_controls = extra_controls,
+ with gr.Tab('ControlNet') as _tab_controlnet:
+ gr.HTML('ControlNet')
+ with gr.Row():
+ extra_controls = [
+ gr.Checkbox(label="Guess mode", value=False, scale=3),
+ ]
+ num_controlnet_units = gr.Slider(label="Units", minimum=1, maximum=max_units, step=1, value=1, scale=1)
+ controlnet_ui_units = [] # list of hidable accordions
+ for i in range(max_units):
+ enabled = True if i==0 else False
+ with gr.Accordion(f'ControlNet unit {i+1}', visible= i < num_controlnet_units.value, elem_classes='control-unit') as unit_ui:
+ with gr.Row():
+ enabled_cb = gr.Checkbox(enabled, label='', container=False, show_label=False)
+ process_id = gr.Dropdown(label="Processor", choices=processors.list_models(), value='None')
+ model_id = gr.Dropdown(label="ControlNet", choices=controlnet.list_models(), value='None')
+ ui_common.create_refresh_button(model_id, controlnet.list_models, lambda: {"choices": controlnet.list_models(refresh=True)}, f'refresh_controlnet_models_{i}')
+ model_strength = gr.Slider(label="Strength", minimum=0.01, maximum=2.0, step=0.01, value=1.0-i/10)
+ control_start = gr.Slider(label="Start", minimum=0.0, maximum=1.0, step=0.05, value=0)
+ control_end = gr.Slider(label="End", minimum=0.0, maximum=1.0, step=0.05, value=1.0)
+ reset_btn = ui_components.ToolButton(value=ui_symbols.reset)
+ image_upload = gr.UploadButton(label=ui_symbols.upload, file_types=['image'], elem_classes=['form', 'gradio-button', 'tool'])
+ image_reuse= ui_components.ToolButton(value=ui_symbols.reuse)
+ process_btn= ui_components.ToolButton(value=ui_symbols.preview)
+ image_preview = gr.Image(label="Input", type="pil", source="upload", height=128, width=128, visible=False, interactive=True, show_label=False, show_download_button=False, container=False)
+ controlnet_ui_units.append(unit_ui)
+ units.append(unit.Unit(
+ unit_type = 'controlnet',
+ enabled = enabled,
+ result_txt = result_txt,
+ enabled_cb = enabled_cb,
+ reset_btn = reset_btn,
+ process_id = process_id,
+ model_id = model_id,
+ model_strength = model_strength,
+ preview_process = preview_process,
+ preview_btn = process_btn,
+ image_upload = image_upload,
+ image_reuse = image_reuse,
+ image_preview = image_preview,
+ control_start = control_start,
+ control_end = control_end,
+ extra_controls = extra_controls,
+ )
)
- )
- if i == 0:
- units[-1].enabled = True # enable first unit in group
- num_controlnet_units.change(fn=helpers.display_units, inputs=[num_controlnet_units], outputs=controlnet_ui_units)
+ if i == 0:
+ units[-1].enabled = True # enable first unit in group
+ num_controlnet_units.change(fn=helpers.display_units, inputs=[num_controlnet_units], outputs=controlnet_ui_units)
- with gr.Tab('IP Adapter') as _tab_ipadapter:
- with gr.Row():
- with gr.Column():
- gr.HTML('IP-Adapter')
- ip_adapter_name = gr.Dropdown(label='Adapter', choices=ipadapter.ADAPTERS, value='None')
- ip_scale = gr.Slider(label='Scale', minimum=0.0, maximum=1.0, step=0.01, value=0.5)
- with gr.Column():
- ip_image = gr.Image(label="Input", show_label=False, type="pil", source="upload", interactive=True, tool="editor", height=256, width=256)
-
- with gr.Tab('T2I Adapter') as _tab_t2iadapter:
- gr.HTML('T2I-Adapter')
- with gr.Row():
- extra_controls = [
- gr.Slider(label="Control factor", minimum=0.0, maximum=1.0, step=0.05, value=1.0, scale=3),
- ]
- num_adapter_units = gr.Slider(label="Units", minimum=1, maximum=max_units, step=1, value=1, scale=1)
- adapter_ui_units = [] # list of hidable accordions
- for i in range(max_units):
- enabled = True if i==0 else False
- with gr.Accordion(f'T2I-Adapter unit {i+1}', visible= i < num_adapter_units.value, elem_classes='control-unit') as unit_ui:
- with gr.Row():
- enabled_cb = gr.Checkbox(enabled, label='', container=False, show_label=False)
- process_id = gr.Dropdown(label="Processor", choices=processors.list_models(), value='None')
- model_id = gr.Dropdown(label="Adapter", choices=t2iadapter.list_models(), value='None')
- ui_common.create_refresh_button(model_id, t2iadapter.list_models, lambda: {"choices": t2iadapter.list_models(refresh=True)}, f'refresh_adapter_models_{i}')
- model_strength = gr.Slider(label="Strength", minimum=0.01, maximum=1.0, step=0.01, value=1.0-i/10)
- reset_btn = ui_components.ToolButton(value=ui_symbols.reset)
- image_upload = gr.UploadButton(label=ui_symbols.upload, file_types=['image'], elem_classes=['form', 'gradio-button', 'tool'])
- image_reuse= ui_components.ToolButton(value=ui_symbols.reuse)
- process_btn= ui_components.ToolButton(value=ui_symbols.preview)
- image_preview = gr.Image(label="Input", show_label=False, type="pil", source="upload", interactive=False, height=128, width=128, visible=False)
- adapter_ui_units.append(unit_ui)
- units.append(unit.Unit(
- unit_type = 't2i adapter',
- enabled = enabled,
- result_txt = result_txt,
- enabled_cb = enabled_cb,
- reset_btn = reset_btn,
- process_id = process_id,
- model_id = model_id,
- model_strength = model_strength,
- preview_process = preview_process,
- preview_btn = process_btn,
- image_upload = image_upload,
- image_reuse = image_reuse,
- image_preview = image_preview,
- extra_controls = extra_controls,
+ with gr.Tab('T2I Adapter') as _tab_t2iadapter:
+ gr.HTML('T2I-Adapter')
+ with gr.Row():
+ extra_controls = [
+ gr.Slider(label="Control factor", minimum=0.0, maximum=1.0, step=0.05, value=1.0, scale=3),
+ ]
+ num_adapter_units = gr.Slider(label="Units", minimum=1, maximum=max_units, step=1, value=1, scale=1)
+ adapter_ui_units = [] # list of hidable accordions
+ for i in range(max_units):
+ enabled = True if i==0 else False
+ with gr.Accordion(f'T2I-Adapter unit {i+1}', visible= i < num_adapter_units.value, elem_classes='control-unit') as unit_ui:
+ with gr.Row():
+ enabled_cb = gr.Checkbox(enabled, label='', container=False, show_label=False)
+ process_id = gr.Dropdown(label="Processor", choices=processors.list_models(), value='None')
+ model_id = gr.Dropdown(label="Adapter", choices=t2iadapter.list_models(), value='None')
+ ui_common.create_refresh_button(model_id, t2iadapter.list_models, lambda: {"choices": t2iadapter.list_models(refresh=True)}, f'refresh_adapter_models_{i}')
+ model_strength = gr.Slider(label="Strength", minimum=0.01, maximum=1.0, step=0.01, value=1.0-i/10)
+ reset_btn = ui_components.ToolButton(value=ui_symbols.reset)
+ image_upload = gr.UploadButton(label=ui_symbols.upload, file_types=['image'], elem_classes=['form', 'gradio-button', 'tool'])
+ image_reuse= ui_components.ToolButton(value=ui_symbols.reuse)
+ process_btn= ui_components.ToolButton(value=ui_symbols.preview)
+ image_preview = gr.Image(label="Input", show_label=False, type="pil", source="upload", interactive=False, height=128, width=128, visible=False)
+ adapter_ui_units.append(unit_ui)
+ units.append(unit.Unit(
+ unit_type = 't2i adapter',
+ enabled = enabled,
+ result_txt = result_txt,
+ enabled_cb = enabled_cb,
+ reset_btn = reset_btn,
+ process_id = process_id,
+ model_id = model_id,
+ model_strength = model_strength,
+ preview_process = preview_process,
+ preview_btn = process_btn,
+ image_upload = image_upload,
+ image_reuse = image_reuse,
+ image_preview = image_preview,
+ extra_controls = extra_controls,
+ )
)
- )
- if i == 0:
- units[-1].enabled = True # enable first unit in group
- num_adapter_units.change(fn=helpers.display_units, inputs=[num_adapter_units], outputs=adapter_ui_units)
+ if i == 0:
+ units[-1].enabled = True # enable first unit in group
+ num_adapter_units.change(fn=helpers.display_units, inputs=[num_adapter_units], outputs=adapter_ui_units)
- with gr.Tab('XS') as _tab_controlnetxs:
- gr.HTML('ControlNet XS')
- with gr.Row():
- extra_controls = [
- gr.Slider(label="Time embedding mix", minimum=0.0, maximum=1.0, step=0.05, value=0.0, scale=3)
- ]
- num_controlnet_units = gr.Slider(label="Units", minimum=1, maximum=max_units, step=1, value=1, scale=1)
- controlnetxs_ui_units = [] # list of hidable accordions
- for i in range(max_units):
- enabled = True if i==0 else False
- with gr.Accordion(f'ControlNet-XS unit {i+1}', visible= i < num_controlnet_units.value, elem_classes='control-unit') as unit_ui:
- with gr.Row():
- enabled_cb = gr.Checkbox(enabled, label='', container=False, show_label=False)
- process_id = gr.Dropdown(label="Processor", choices=processors.list_models(), value='None')
- model_id = gr.Dropdown(label="ControlNet-XS", choices=xs.list_models(), value='None')
- ui_common.create_refresh_button(model_id, xs.list_models, lambda: {"choices": xs.list_models(refresh=True)}, f'refresh_xs_models_{i}')
- model_strength = gr.Slider(label="Strength", minimum=0.01, maximum=1.0, step=0.01, value=1.0-i/10)
- control_start = gr.Slider(label="Start", minimum=0.0, maximum=1.0, step=0.05, value=0)
- control_end = gr.Slider(label="End", minimum=0.0, maximum=1.0, step=0.05, value=1.0)
- reset_btn = ui_components.ToolButton(value=ui_symbols.reset)
- image_upload = gr.UploadButton(label=ui_symbols.upload, file_types=['image'], elem_classes=['form', 'gradio-button', 'tool'])
- image_reuse= ui_components.ToolButton(value=ui_symbols.reuse)
- process_btn= ui_components.ToolButton(value=ui_symbols.preview)
- image_preview = gr.Image(label="Input", show_label=False, type="pil", source="upload", interactive=False, height=128, width=128, visible=False)
- controlnetxs_ui_units.append(unit_ui)
- units.append(unit.Unit(
- unit_type = 'xs',
- enabled = enabled,
- result_txt = result_txt,
- enabled_cb = enabled_cb,
- reset_btn = reset_btn,
- process_id = process_id,
- model_id = model_id,
- model_strength = model_strength,
- preview_process = preview_process,
- preview_btn = process_btn,
- image_upload = image_upload,
- image_reuse = image_reuse,
- image_preview = image_preview,
- control_start = control_start,
- control_end = control_end,
- extra_controls = extra_controls,
+ with gr.Tab('XS') as _tab_controlnetxs:
+ gr.HTML('ControlNet XS')
+ with gr.Row():
+ extra_controls = [
+ gr.Slider(label="Time embedding mix", minimum=0.0, maximum=1.0, step=0.05, value=0.0, scale=3)
+ ]
+ num_controlnet_units = gr.Slider(label="Units", minimum=1, maximum=max_units, step=1, value=1, scale=1)
+ controlnetxs_ui_units = [] # list of hidable accordions
+ for i in range(max_units):
+ enabled = True if i==0 else False
+ with gr.Accordion(f'ControlNet-XS unit {i+1}', visible= i < num_controlnet_units.value, elem_classes='control-unit') as unit_ui:
+ with gr.Row():
+ enabled_cb = gr.Checkbox(enabled, label='', container=False, show_label=False)
+ process_id = gr.Dropdown(label="Processor", choices=processors.list_models(), value='None')
+ model_id = gr.Dropdown(label="ControlNet-XS", choices=xs.list_models(), value='None')
+ ui_common.create_refresh_button(model_id, xs.list_models, lambda: {"choices": xs.list_models(refresh=True)}, f'refresh_xs_models_{i}')
+ model_strength = gr.Slider(label="Strength", minimum=0.01, maximum=1.0, step=0.01, value=1.0-i/10)
+ control_start = gr.Slider(label="Start", minimum=0.0, maximum=1.0, step=0.05, value=0)
+ control_end = gr.Slider(label="End", minimum=0.0, maximum=1.0, step=0.05, value=1.0)
+ reset_btn = ui_components.ToolButton(value=ui_symbols.reset)
+ image_upload = gr.UploadButton(label=ui_symbols.upload, file_types=['image'], elem_classes=['form', 'gradio-button', 'tool'])
+ image_reuse= ui_components.ToolButton(value=ui_symbols.reuse)
+ process_btn= ui_components.ToolButton(value=ui_symbols.preview)
+ image_preview = gr.Image(label="Input", show_label=False, type="pil", source="upload", interactive=False, height=128, width=128, visible=False)
+ controlnetxs_ui_units.append(unit_ui)
+ units.append(unit.Unit(
+ unit_type = 'xs',
+ enabled = enabled,
+ result_txt = result_txt,
+ enabled_cb = enabled_cb,
+ reset_btn = reset_btn,
+ process_id = process_id,
+ model_id = model_id,
+ model_strength = model_strength,
+ preview_process = preview_process,
+ preview_btn = process_btn,
+ image_upload = image_upload,
+ image_reuse = image_reuse,
+ image_preview = image_preview,
+ control_start = control_start,
+ control_end = control_end,
+ extra_controls = extra_controls,
+ )
)
- )
- if i == 0:
- units[-1].enabled = True # enable first unit in group
- num_controlnet_units.change(fn=helpers.display_units, inputs=[num_controlnet_units], outputs=controlnetxs_ui_units)
+ if i == 0:
+ units[-1].enabled = True # enable first unit in group
+ num_controlnet_units.change(fn=helpers.display_units, inputs=[num_controlnet_units], outputs=controlnetxs_ui_units)
- with gr.Tab('Lite') as _tab_lite:
- gr.HTML('Control LLLite')
- with gr.Row():
- extra_controls = [
- ]
- num_lite_units = gr.Slider(label="Units", minimum=1, maximum=max_units, step=1, value=1, scale=1)
- lite_ui_units = [] # list of hidable accordions
- for i in range(max_units):
- enabled = True if i==0 else False
- with gr.Accordion(f'Control-LLLite unit {i+1}', visible= i < num_lite_units.value, elem_classes='control-unit') as unit_ui:
- with gr.Row():
- enabled_cb = gr.Checkbox(enabled, label='', container=False, show_label=False)
- process_id = gr.Dropdown(label="Processor", choices=processors.list_models(), value='None')
- model_id = gr.Dropdown(label="Model", choices=lite.list_models(), value='None')
- ui_common.create_refresh_button(model_id, lite.list_models, lambda: {"choices": lite.list_models(refresh=True)}, f'refresh_lite_models_{i}')
- model_strength = gr.Slider(label="Strength", minimum=0.01, maximum=1.0, step=0.01, value=1.0-i/10)
- reset_btn = ui_components.ToolButton(value=ui_symbols.reset)
- image_upload = gr.UploadButton(label=ui_symbols.upload, file_types=['image'], elem_classes=['form', 'gradio-button', 'tool'])
- image_reuse= ui_components.ToolButton(value=ui_symbols.reuse)
- image_preview = gr.Image(label="Input", show_label=False, type="pil", source="upload", interactive=False, height=128, width=128, visible=False)
- process_btn= ui_components.ToolButton(value=ui_symbols.preview)
- lite_ui_units.append(unit_ui)
- units.append(unit.Unit(
- unit_type = 'lite',
- enabled = enabled,
- result_txt = result_txt,
- enabled_cb = enabled_cb,
- reset_btn = reset_btn,
- process_id = process_id,
- model_id = model_id,
- model_strength = model_strength,
- preview_process = preview_process,
- preview_btn = process_btn,
- image_upload = image_upload,
- image_reuse = image_reuse,
- image_preview = image_preview,
- extra_controls = extra_controls,
+ with gr.Tab('Lite') as _tab_lite:
+ gr.HTML('Control LLLite')
+ with gr.Row():
+ extra_controls = [
+ ]
+ num_lite_units = gr.Slider(label="Units", minimum=1, maximum=max_units, step=1, value=1, scale=1)
+ lite_ui_units = [] # list of hidable accordions
+ for i in range(max_units):
+ enabled = True if i==0 else False
+ with gr.Accordion(f'Control-LLLite unit {i+1}', visible= i < num_lite_units.value, elem_classes='control-unit') as unit_ui:
+ with gr.Row():
+ enabled_cb = gr.Checkbox(enabled, label='', container=False, show_label=False)
+ process_id = gr.Dropdown(label="Processor", choices=processors.list_models(), value='None')
+ model_id = gr.Dropdown(label="Model", choices=lite.list_models(), value='None')
+ ui_common.create_refresh_button(model_id, lite.list_models, lambda: {"choices": lite.list_models(refresh=True)}, f'refresh_lite_models_{i}')
+ model_strength = gr.Slider(label="Strength", minimum=0.01, maximum=1.0, step=0.01, value=1.0-i/10)
+ reset_btn = ui_components.ToolButton(value=ui_symbols.reset)
+ image_upload = gr.UploadButton(label=ui_symbols.upload, file_types=['image'], elem_classes=['form', 'gradio-button', 'tool'])
+ image_reuse= ui_components.ToolButton(value=ui_symbols.reuse)
+ image_preview = gr.Image(label="Input", show_label=False, type="pil", source="upload", interactive=False, height=128, width=128, visible=False)
+ process_btn= ui_components.ToolButton(value=ui_symbols.preview)
+ lite_ui_units.append(unit_ui)
+ units.append(unit.Unit(
+ unit_type = 'lite',
+ enabled = enabled,
+ result_txt = result_txt,
+ enabled_cb = enabled_cb,
+ reset_btn = reset_btn,
+ process_id = process_id,
+ model_id = model_id,
+ model_strength = model_strength,
+ preview_process = preview_process,
+ preview_btn = process_btn,
+ image_upload = image_upload,
+ image_reuse = image_reuse,
+ image_preview = image_preview,
+ extra_controls = extra_controls,
+ )
)
- )
- if i == 0:
- units[-1].enabled = True # enable first unit in group
- num_lite_units.change(fn=helpers.display_units, inputs=[num_lite_units], outputs=lite_ui_units)
+ if i == 0:
+ units[-1].enabled = True # enable first unit in group
+ num_lite_units.change(fn=helpers.display_units, inputs=[num_lite_units], outputs=lite_ui_units)
- with gr.Tab('Reference') as _tab_reference:
- gr.HTML('ControlNet reference-only control')
- with gr.Row():
- extra_controls = [
- gr.Radio(label="Reference context", choices=['Attention', 'Adain', 'Attention Adain'], value='Attention', interactive=True),
- gr.Slider(label="Style fidelity", minimum=0.0, maximum=1.0, step=0.05, value=0.5, interactive=True), # prompt vs control importance
- gr.Slider(label="Reference query weight", minimum=0.0, maximum=1.0, step=0.05, value=1.0, interactive=True),
- gr.Slider(label="Reference adain weight", minimum=0.0, maximum=2.0, step=0.05, value=1.0, interactive=True),
- ]
- for i in range(1): # can only have one reference unit
- enabled = True if i==0 else False
- with gr.Accordion(f'Reference unit {i+1}', visible=True, elem_classes='control-unit') as unit_ui:
- with gr.Row():
- enabled_cb = gr.Checkbox(enabled, label='', container=False, show_label=False)
- model_id = gr.Dropdown(label="Reference", choices=reference.list_models(), value='Reference', visible=False)
- model_strength = gr.Slider(label="Strength", minimum=0.01, maximum=1.0, step=0.01, value=1.0, visible=False)
- reset_btn = ui_components.ToolButton(value=ui_symbols.reset)
- image_upload = gr.UploadButton(label=ui_symbols.upload, file_types=['image'], elem_classes=['form', 'gradio-button', 'tool'])
- image_reuse= ui_components.ToolButton(value=ui_symbols.reuse)
- image_preview = gr.Image(label="Input", show_label=False, type="pil", source="upload", interactive=False, height=128, width=128, visible=False)
- process_btn= ui_components.ToolButton(value=ui_symbols.preview)
- units.append(unit.Unit(
- unit_type = 'reference',
- enabled = enabled,
- result_txt = result_txt,
- enabled_cb = enabled_cb,
- reset_btn = reset_btn,
- process_id = process_id,
- model_id = model_id,
- model_strength = model_strength,
- preview_process = preview_process,
- preview_btn = process_btn,
- image_upload = image_upload,
- image_reuse = image_reuse,
- image_preview = image_preview,
- extra_controls = extra_controls,
+ with gr.Tab('Reference') as _tab_reference:
+ gr.HTML('ControlNet reference-only control')
+ with gr.Row():
+ extra_controls = [
+ gr.Radio(label="Reference context", choices=['Attention', 'Adain', 'Attention Adain'], value='Attention', interactive=True),
+ gr.Slider(label="Style fidelity", minimum=0.0, maximum=1.0, step=0.05, value=0.5, interactive=True), # prompt vs control importance
+ gr.Slider(label="Reference query weight", minimum=0.0, maximum=1.0, step=0.05, value=1.0, interactive=True),
+ gr.Slider(label="Reference adain weight", minimum=0.0, maximum=2.0, step=0.05, value=1.0, interactive=True),
+ ]
+ for i in range(1): # can only have one reference unit
+ enabled = True if i==0 else False
+ with gr.Accordion(f'Reference unit {i+1}', visible=True, elem_classes='control-unit') as unit_ui:
+ with gr.Row():
+ enabled_cb = gr.Checkbox(enabled, label='', container=False, show_label=False)
+ model_id = gr.Dropdown(label="Reference", choices=reference.list_models(), value='Reference', visible=False)
+ model_strength = gr.Slider(label="Strength", minimum=0.01, maximum=1.0, step=0.01, value=1.0, visible=False)
+ reset_btn = ui_components.ToolButton(value=ui_symbols.reset)
+ image_upload = gr.UploadButton(label=ui_symbols.upload, file_types=['image'], elem_classes=['form', 'gradio-button', 'tool'])
+ image_reuse= ui_components.ToolButton(value=ui_symbols.reuse)
+ image_preview = gr.Image(label="Input", show_label=False, type="pil", source="upload", interactive=False, height=128, width=128, visible=False)
+ process_btn= ui_components.ToolButton(value=ui_symbols.preview)
+ units.append(unit.Unit(
+ unit_type = 'reference',
+ enabled = enabled,
+ result_txt = result_txt,
+ enabled_cb = enabled_cb,
+ reset_btn = reset_btn,
+ process_id = process_id,
+ model_id = model_id,
+ model_strength = model_strength,
+ preview_process = preview_process,
+ preview_btn = process_btn,
+ image_upload = image_upload,
+ image_reuse = image_reuse,
+ image_preview = image_preview,
+ extra_controls = extra_controls,
+ )
)
- )
- if i == 0:
- units[-1].enabled = True # enable first unit in group
+ if i == 0:
+ units[-1].enabled = True # enable first unit in group
- with gr.Tab('Processor settings') as _tab_settings:
- with gr.Group(elem_classes=['processor-group']):
- settings = []
- with gr.Accordion('HED', open=True, elem_classes=['processor-settings']):
- settings.append(gr.Checkbox(label="Scribble", value=False))
- with gr.Accordion('Midas depth', open=True, elem_classes=['processor-settings']):
- settings.append(gr.Slider(label="Background threshold", minimum=0.0, maximum=1.0, step=0.01, value=0.1))
- settings.append(gr.Checkbox(label="Depth and normal", value=False))
- with gr.Accordion('MLSD', open=True, elem_classes=['processor-settings']):
- settings.append(gr.Slider(label="Score threshold", minimum=0.0, maximum=1.0, step=0.01, value=0.1))
- settings.append(gr.Slider(label="Distance threshold", minimum=0.0, maximum=1.0, step=0.01, value=0.1))
- with gr.Accordion('OpenBody', open=True, elem_classes=['processor-settings']):
- settings.append(gr.Checkbox(label="Body", value=True))
- settings.append(gr.Checkbox(label="Hands", value=False))
- settings.append(gr.Checkbox(label="Face", value=False))
- with gr.Accordion('PidiNet', open=True, elem_classes=['processor-settings']):
- settings.append(gr.Checkbox(label="Scribble", value=False))
- settings.append(gr.Checkbox(label="Apply filter", value=False))
- with gr.Accordion('LineArt', open=True, elem_classes=['processor-settings']):
- settings.append(gr.Checkbox(label="Coarse", value=False))
- with gr.Accordion('Leres Depth', open=True, elem_classes=['processor-settings']):
- settings.append(gr.Checkbox(label="Boost", value=False))
- settings.append(gr.Slider(label="Near threshold", minimum=0.0, maximum=1.0, step=0.01, value=0.0))
- settings.append(gr.Slider(label="Background threshold", minimum=0.0, maximum=1.0, step=0.01, value=0.0))
- with gr.Accordion('MediaPipe Face', open=True, elem_classes=['processor-settings']):
- settings.append(gr.Slider(label="Max faces", minimum=1, maximum=10, step=1, value=1))
- settings.append(gr.Slider(label="Min confidence", minimum=0.0, maximum=1.0, step=0.01, value=0.5))
- with gr.Accordion('Canny', open=True, elem_classes=['processor-settings']):
- settings.append(gr.Slider(label="Low threshold", minimum=0, maximum=1000, step=1, value=100))
- settings.append(gr.Slider(label="High threshold", minimum=0, maximum=1000, step=1, value=200))
- with gr.Accordion('DWPose', open=True, elem_classes=['processor-settings']):
- settings.append(gr.Radio(label="Model", choices=['Tiny', 'Medium', 'Large'], value='Tiny'))
- settings.append(gr.Slider(label="Min confidence", minimum=0.0, maximum=1.0, step=0.01, value=0.3))
- with gr.Accordion('SegmentAnything', open=True, elem_classes=['processor-settings']):
- settings.append(gr.Radio(label="Model", choices=['Base', 'Large'], value='Base'))
- with gr.Accordion('Edge', open=True, elem_classes=['processor-settings']):
- settings.append(gr.Checkbox(label="Parameter free", value=True))
- settings.append(gr.Radio(label="Mode", choices=['edge', 'gradient'], value='edge'))
- with gr.Accordion('Zoe Depth', open=True, elem_classes=['processor-settings']):
- settings.append(gr.Checkbox(label="Gamma corrected", value=False))
- with gr.Accordion('Marigold Depth', open=True, elem_classes=['processor-settings']):
- settings.append(gr.Dropdown(label="Color map", choices=['None'] + plt.colormaps(), value='None'))
- settings.append(gr.Slider(label="Denoising steps", minimum=1, maximum=99, step=1, value=10))
- settings.append(gr.Slider(label="Ensemble size", minimum=1, maximum=99, step=1, value=10))
- with gr.Accordion('Depth Anything', open=True, elem_classes=['processor-settings']):
- settings.append(gr.Dropdown(label="Color map", choices=['none'] + masking.COLORMAP, value='inferno'))
- for setting in settings:
- setting.change(fn=processors.update_settings, inputs=settings, outputs=[])
+ with gr.Tab('Processor settings') as _tab_settings:
+ with gr.Group(elem_classes=['processor-group']):
+ settings = []
+ with gr.Accordion('HED', open=True, elem_classes=['processor-settings']):
+ settings.append(gr.Checkbox(label="Scribble", value=False))
+ with gr.Accordion('Midas depth', open=True, elem_classes=['processor-settings']):
+ settings.append(gr.Slider(label="Background threshold", minimum=0.0, maximum=1.0, step=0.01, value=0.1))
+ settings.append(gr.Checkbox(label="Depth and normal", value=False))
+ with gr.Accordion('MLSD', open=True, elem_classes=['processor-settings']):
+ settings.append(gr.Slider(label="Score threshold", minimum=0.0, maximum=1.0, step=0.01, value=0.1))
+ settings.append(gr.Slider(label="Distance threshold", minimum=0.0, maximum=1.0, step=0.01, value=0.1))
+ with gr.Accordion('OpenBody', open=True, elem_classes=['processor-settings']):
+ settings.append(gr.Checkbox(label="Body", value=True))
+ settings.append(gr.Checkbox(label="Hands", value=False))
+ settings.append(gr.Checkbox(label="Face", value=False))
+ with gr.Accordion('PidiNet', open=True, elem_classes=['processor-settings']):
+ settings.append(gr.Checkbox(label="Scribble", value=False))
+ settings.append(gr.Checkbox(label="Apply filter", value=False))
+ with gr.Accordion('LineArt', open=True, elem_classes=['processor-settings']):
+ settings.append(gr.Checkbox(label="Coarse", value=False))
+ with gr.Accordion('Leres Depth', open=True, elem_classes=['processor-settings']):
+ settings.append(gr.Checkbox(label="Boost", value=False))
+ settings.append(gr.Slider(label="Near threshold", minimum=0.0, maximum=1.0, step=0.01, value=0.0))
+ settings.append(gr.Slider(label="Background threshold", minimum=0.0, maximum=1.0, step=0.01, value=0.0))
+ with gr.Accordion('MediaPipe Face', open=True, elem_classes=['processor-settings']):
+ settings.append(gr.Slider(label="Max faces", minimum=1, maximum=10, step=1, value=1))
+ settings.append(gr.Slider(label="Min confidence", minimum=0.0, maximum=1.0, step=0.01, value=0.5))
+ with gr.Accordion('Canny', open=True, elem_classes=['processor-settings']):
+ settings.append(gr.Slider(label="Low threshold", minimum=0, maximum=1000, step=1, value=100))
+ settings.append(gr.Slider(label="High threshold", minimum=0, maximum=1000, step=1, value=200))
+ with gr.Accordion('DWPose', open=True, elem_classes=['processor-settings']):
+ settings.append(gr.Radio(label="Model", choices=['Tiny', 'Medium', 'Large'], value='Tiny'))
+ settings.append(gr.Slider(label="Min confidence", minimum=0.0, maximum=1.0, step=0.01, value=0.3))
+ with gr.Accordion('SegmentAnything', open=True, elem_classes=['processor-settings']):
+ settings.append(gr.Radio(label="Model", choices=['Base', 'Large'], value='Base'))
+ with gr.Accordion('Edge', open=True, elem_classes=['processor-settings']):
+ settings.append(gr.Checkbox(label="Parameter free", value=True))
+ settings.append(gr.Radio(label="Mode", choices=['edge', 'gradient'], value='edge'))
+ with gr.Accordion('Zoe Depth', open=True, elem_classes=['processor-settings']):
+ settings.append(gr.Checkbox(label="Gamma corrected", value=False))
+ with gr.Accordion('Marigold Depth', open=True, elem_classes=['processor-settings']):
+ settings.append(gr.Dropdown(label="Color map", choices=['None'] + plt.colormaps(), value='None'))
+ settings.append(gr.Slider(label="Denoising steps", minimum=1, maximum=99, step=1, value=10))
+ settings.append(gr.Slider(label="Ensemble size", minimum=1, maximum=99, step=1, value=10))
+ with gr.Accordion('Depth Anything', open=True, elem_classes=['processor-settings']):
+ settings.append(gr.Dropdown(label="Color map", choices=['none'] + masking.COLORMAP, value='inferno'))
+ for setting in settings:
+ setting.change(fn=processors.update_settings, inputs=settings, outputs=[])
- for btn in input_buttons:
- btn.click(fn=helpers.copy_input, inputs=[input_mode, btn, input_image, input_resize, input_inpaint], outputs=[input_image, input_resize, input_inpaint], _js='controlInputMode')
- btn.click(fn=helpers.transfer_input, inputs=[btn], outputs=[input_image, input_resize, input_inpaint] + input_buttons)
+ with gr.Row(elem_id="control_script_container"):
+ input_script_args = scripts.scripts_current.setup_ui(parent='control', accordion=True)
- show_preview.change(fn=lambda x: gr.update(visible=x), inputs=[show_preview], outputs=[column_preview])
- input_type.change(fn=lambda x: gr.update(visible=x == 2), inputs=[input_type], outputs=[column_init])
- btn_prompt_counter.click(fn=call_queue.wrap_queued_call(ui_common.update_token_counter), inputs=[prompt, steps], outputs=[prompt_counter])
- btn_negative_counter.click(fn=call_queue.wrap_queued_call(ui_common.update_token_counter), inputs=[negative, steps], outputs=[negative_counter])
- btn_interrogate_clip.click(fn=helpers.interrogate_clip, inputs=[], outputs=[prompt])
- btn_interrogate_booru.click(fn=helpers.interrogate_booru, inputs=[], outputs=[prompt])
+ # handlers
- select_fields = [input_mode, input_image, init_image, input_type, input_resize, input_inpaint, input_video, input_batch, input_folder]
- select_output = [output_tabs, result_txt]
- select_dict = dict(
- fn=helpers.select_input,
- _js="controlInputMode",
- inputs=select_fields,
- outputs=select_output,
- show_progress=True,
- queue=False,
- )
- prompt.submit(**select_dict)
- btn_generate.click(**select_dict)
- for ctrl in [input_image, input_resize, input_video, input_batch, input_folder, init_image, init_video, init_batch, init_folder, tab_image, tab_video, tab_batch, tab_folder, tab_image_init, tab_video_init, tab_batch_init, tab_folder_init]:
- if hasattr(ctrl, 'change'):
- ctrl.change(**select_dict)
- if hasattr(ctrl, 'clear'):
- ctrl.clear(**select_dict)
- for ctrl in [input_inpaint]: # gradio image mode inpaint triggeres endless loop on change event
- if hasattr(ctrl, 'upload'):
- ctrl.upload(**select_dict)
+ for btn in input_buttons:
+ btn.click(fn=helpers.copy_input, inputs=[input_mode, btn, input_image, input_resize, input_inpaint], outputs=[input_image, input_resize, input_inpaint], _js='controlInputMode')
+ btn.click(fn=helpers.transfer_input, inputs=[btn], outputs=[input_image, input_resize, input_inpaint] + input_buttons)
- tabs_state = gr.Text(value='none', visible=False)
- input_fields = [
- input_type,
- prompt, negative, styles,
- steps, sampler_index,
- seed, subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w,
- cfg_scale, clip_skip, image_cfg_scale, diffusers_guidance_rescale, sag_scale, cfg_end, full_quality, restore_faces, tiling,
- hdr_mode, hdr_brightness, hdr_color, hdr_sharpen, hdr_clamp, hdr_boundary, hdr_threshold, hdr_maximize, hdr_max_center, hdr_max_boundry, hdr_color_picker, hdr_tint_ratio,
- resize_mode_before, resize_name_before, width_before, height_before, scale_by_before, selected_scale_tab_before,
- resize_mode_after, resize_name_after, width_after, height_after, scale_by_after, selected_scale_tab_after,
- denoising_strength, batch_count, batch_size,
- video_skip_frames, video_type, video_duration, video_loop, video_pad, video_interpolate,
- ip_adapter_name, ip_scale, ip_image,
- ]
- output_fields = [
- preview_process,
- output_image,
- output_video,
- output_gallery,
- result_txt,
- ]
- control_dict = dict(
- fn=generate_click,
- _js="submit_control",
- inputs=[tabs_state, tabs_state] + input_fields + input_script_args,
- outputs=output_fields,
- show_progress=True,
- )
- prompt.submit(**control_dict)
- btn_generate.click(**control_dict)
+ show_preview.change(fn=lambda x: gr.update(visible=x), inputs=[show_preview], outputs=[column_preview])
+ input_type.change(fn=lambda x: gr.update(visible=x == 2), inputs=[input_type], outputs=[column_init])
+ btn_prompt_counter.click(fn=call_queue.wrap_queued_call(ui_common.update_token_counter), inputs=[prompt, steps], outputs=[prompt_counter])
+ btn_negative_counter.click(fn=call_queue.wrap_queued_call(ui_common.update_token_counter), inputs=[negative, steps], outputs=[negative_counter])
+ btn_interrogate_clip.click(fn=helpers.interrogate_clip, inputs=[], outputs=[prompt])
+ btn_interrogate_booru.click(fn=helpers.interrogate_booru, inputs=[], outputs=[prompt])
- paste_fields = [
- # prompt
- (prompt, "Prompt"),
- (negative, "Negative prompt"),
- # input
- (denoising_strength, "Denoising strength"),
- # resize # TODO resize params
- (width_before, "Size-1"),
- (height_before, "Size-2"),
- (resize_mode_before, "Resize mode"),
- (scale_by_before, "Resize scale"),
- # sampler
- (sampler_index, "Sampler"),
- (steps, "Steps"),
- # batch
- (batch_count, "Batch-1"),
- (batch_size, "Batch-2"),
- # seed
- (seed, "Seed"),
- # mask
- (mask_controls[1], "Mask only"),
- (mask_controls[2], "Mask invert"),
- (mask_controls[3], "Mask blur"),
- (mask_controls[4], "Mask erode"),
- (mask_controls[5], "Mask dilate"),
- (mask_controls[6], "Mask auto"),
- # advanced
- (cfg_scale, "CFG scale"),
- (clip_skip, "Clip skip"),
- (image_cfg_scale, "Image CFG scale"),
- (diffusers_guidance_rescale, "CFG rescale"),
- (full_quality, "Full quality"),
- (restore_faces, "Face restoration"),
- (tiling, "Tiling"),
- # second pass # TODO second pass params
- # hidden
- (seed_resize_from_w, "Seed resize from-1"),
- (seed_resize_from_h, "Seed resize from-2"),
- *scripts.scripts_control.infotext_fields
- ]
- generation_parameters_copypaste.add_paste_fields("control", input_image, paste_fields, override_settings)
- bindings = generation_parameters_copypaste.ParamBinding(paste_button=btn_paste, tabname="control", source_text_component=prompt, source_image_component=output_gallery)
- generation_parameters_copypaste.register_paste_params_button(bindings)
- masking.bind_controls([input_image, input_inpaint, input_resize], preview_process, output_image)
+ select_fields = [input_mode, input_image, init_image, input_type, input_resize, input_inpaint, input_video, input_batch, input_folder]
+ select_output = [output_tabs, result_txt]
+ select_dict = dict(
+ fn=helpers.select_input,
+ _js="controlInputMode",
+ inputs=select_fields,
+ outputs=select_output,
+ show_progress=True,
+ queue=False,
+ )
+ prompt.submit(**select_dict)
+ btn_generate.click(**select_dict)
+ for ctrl in [input_image, input_resize, input_video, input_batch, input_folder, init_image, init_video, init_batch, init_folder, tab_image, tab_video, tab_batch, tab_folder, tab_image_init, tab_video_init, tab_batch_init, tab_folder_init]:
+ if hasattr(ctrl, 'change'):
+ ctrl.change(**select_dict)
+ if hasattr(ctrl, 'clear'):
+ ctrl.clear(**select_dict)
+ for ctrl in [input_inpaint]: # gradio image mode inpaint triggeres endless loop on change event
+ if hasattr(ctrl, 'upload'):
+ ctrl.upload(**select_dict)
+
+ tabs_state = gr.Text(value='none', visible=False)
+ input_fields = [
+ input_type,
+ prompt, negative, styles,
+ steps, sampler_index,
+ seed, subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w,
+ cfg_scale, clip_skip, image_cfg_scale, diffusers_guidance_rescale, sag_scale, cfg_end, full_quality, restore_faces, tiling,
+ hdr_mode, hdr_brightness, hdr_color, hdr_sharpen, hdr_clamp, hdr_boundary, hdr_threshold, hdr_maximize, hdr_max_center, hdr_max_boundry, hdr_color_picker, hdr_tint_ratio,
+ resize_mode_before, resize_name_before, width_before, height_before, scale_by_before, selected_scale_tab_before,
+ resize_mode_after, resize_name_after, width_after, height_after, scale_by_after, selected_scale_tab_after,
+ denoising_strength, batch_count, batch_size,
+ video_skip_frames, video_type, video_duration, video_loop, video_pad, video_interpolate,
+ ]
+ output_fields = [
+ preview_process,
+ output_image,
+ output_video,
+ output_gallery,
+ result_txt,
+ ]
+ control_dict = dict(
+ fn=generate_click,
+ _js="submit_control",
+ inputs=[tabs_state, tabs_state] + input_fields + input_script_args,
+ outputs=output_fields,
+ show_progress=True,
+ )
+ prompt.submit(**control_dict)
+ btn_generate.click(**control_dict)
+
+ paste_fields = [
+ # prompt
+ (prompt, "Prompt"),
+ (negative, "Negative prompt"),
+ # input
+ (denoising_strength, "Denoising strength"),
+ # resize # TODO resize params
+ (width_before, "Size-1"),
+ (height_before, "Size-2"),
+ (resize_mode_before, "Resize mode"),
+ (scale_by_before, "Resize scale"),
+ # sampler
+ (sampler_index, "Sampler"),
+ (steps, "Steps"),
+ # batch
+ (batch_count, "Batch-1"),
+ (batch_size, "Batch-2"),
+ # seed
+ (seed, "Seed"),
+ # mask
+ (mask_controls[1], "Mask only"),
+ (mask_controls[2], "Mask invert"),
+ (mask_controls[3], "Mask blur"),
+ (mask_controls[4], "Mask erode"),
+ (mask_controls[5], "Mask dilate"),
+ (mask_controls[6], "Mask auto"),
+ # advanced
+ (cfg_scale, "CFG scale"),
+ (clip_skip, "Clip skip"),
+ (image_cfg_scale, "Image CFG scale"),
+ (diffusers_guidance_rescale, "CFG rescale"),
+ (full_quality, "Full quality"),
+ (restore_faces, "Face restoration"),
+ (tiling, "Tiling"),
+ # second pass # TODO second pass params
+ # hidden
+ (seed_resize_from_w, "Seed resize from-1"),
+ (seed_resize_from_h, "Seed resize from-2"),
+ *scripts.scripts_control.infotext_fields
+ ]
+ generation_parameters_copypaste.add_paste_fields("control", input_image, paste_fields, override_settings)
+ bindings = generation_parameters_copypaste.ParamBinding(paste_button=btn_paste, tabname="control", source_text_component=prompt, source_image_component=output_gallery)
+ generation_parameters_copypaste.register_paste_params_button(bindings)
+ masking.bind_controls([input_image, input_inpaint, input_resize], preview_process, output_image)
- if os.environ.get('SD_CONTROL_DEBUG', None) is not None: # debug only
- from modules.control.test import test_processors, test_controlnets, test_adapters, test_xs, test_lite
- gr.HTML('