Upload folder using huggingface_hub
Browse files- requirements.txt +1 -1
- ui/events.py +0 -1513
- ui/events/__init__.py +10 -0
- ui/events/chain_handlers.py +680 -0
- ui/events/change_handlers.py +333 -0
- ui/events/config_loaders.py +131 -0
- ui/events/main.py +240 -0
- ui/events/run_handlers.py +100 -0
- yaml/file_list.yaml +2 -2
- yaml/model_list.yaml +2 -2
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
comfyui-frontend-package==1.44.19
|
| 2 |
comfyui-workflow-templates==0.9.82
|
| 3 |
-
comfyui-embedded-docs==0.5.
|
| 4 |
torch
|
| 5 |
torchsde
|
| 6 |
torchvision
|
|
|
|
| 1 |
comfyui-frontend-package==1.44.19
|
| 2 |
comfyui-workflow-templates==0.9.82
|
| 3 |
+
comfyui-embedded-docs==0.5.1
|
| 4 |
torch
|
| 5 |
torchsde
|
| 6 |
torchvision
|
ui/events.py
DELETED
|
@@ -1,1513 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import yaml
|
| 3 |
-
import os
|
| 4 |
-
import shutil
|
| 5 |
-
from functools import lru_cache
|
| 6 |
-
from core.settings import *
|
| 7 |
-
from utils.app_utils import *
|
| 8 |
-
from core.generation_logic import *
|
| 9 |
-
from comfy_integration.nodes import SAMPLER_CHOICES, SCHEDULER_CHOICES
|
| 10 |
-
|
| 11 |
-
from utils.app_utils import save_uploaded_file_with_hash
|
| 12 |
-
from ui.shared.ui_components import RESOLUTION_MAP, MAX_CONTROLNETS, MAX_IPADAPTERS, MAX_EMBEDDINGS, MAX_CONDITIONINGS, MAX_LORAS
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
@lru_cache(maxsize=1)
|
| 16 |
-
def load_controlnet_config():
|
| 17 |
-
_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 18 |
-
_CN_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'controlnet_models.yaml')
|
| 19 |
-
try:
|
| 20 |
-
print("--- Loading controlnet_models.yaml ---")
|
| 21 |
-
with open(_CN_MODEL_LIST_PATH, 'r', encoding='utf-8') as f:
|
| 22 |
-
config = yaml.safe_load(f)
|
| 23 |
-
print("--- ✅ controlnet_models.yaml loaded successfully ---")
|
| 24 |
-
return config.get("ControlNet", {})
|
| 25 |
-
except Exception as e:
|
| 26 |
-
print(f"Error loading controlnet_models.yaml: {e}")
|
| 27 |
-
return {}
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
def get_cn_defaults(arch_val):
|
| 31 |
-
cn_full_config = load_controlnet_config()
|
| 32 |
-
cn_config = cn_full_config.get(arch_val, [])
|
| 33 |
-
|
| 34 |
-
if not cn_config:
|
| 35 |
-
return [], None, [], None, "None"
|
| 36 |
-
|
| 37 |
-
all_types = sorted(list(set(t for model in cn_config for t in model.get("Type", []))))
|
| 38 |
-
default_type = all_types[0] if all_types else None
|
| 39 |
-
|
| 40 |
-
series_choices = []
|
| 41 |
-
if default_type:
|
| 42 |
-
series_choices = sorted(list(set(model.get("Series", "Default") for model in cn_config if default_type in model.get("Type", []))))
|
| 43 |
-
default_series = series_choices[0] if series_choices else None
|
| 44 |
-
|
| 45 |
-
filepath = "None"
|
| 46 |
-
if default_series and default_type:
|
| 47 |
-
for model in cn_config:
|
| 48 |
-
if model.get("Series") == default_series and default_type in model.get("Type", []):
|
| 49 |
-
filepath = model.get("Filepath")
|
| 50 |
-
break
|
| 51 |
-
|
| 52 |
-
return all_types, default_type, series_choices, default_series, filepath
|
| 53 |
-
|
| 54 |
-
@lru_cache(maxsize=1)
|
| 55 |
-
def load_anima_controlnet_lllite_config():
|
| 56 |
-
_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 57 |
-
_CN_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'anima_controlnet_lllite_models.yaml')
|
| 58 |
-
try:
|
| 59 |
-
print("--- Loading anima_controlnet_lllite_models.yaml ---")
|
| 60 |
-
with open(_CN_MODEL_LIST_PATH, 'r', encoding='utf-8') as f:
|
| 61 |
-
config = yaml.safe_load(f)
|
| 62 |
-
print("--- ✅ anima_controlnet_lllite_models.yaml loaded successfully ---")
|
| 63 |
-
return config.get("Anima_ControlNet_Lllite", [])
|
| 64 |
-
except Exception as e:
|
| 65 |
-
print(f"Error loading anima_controlnet_lllite_models.yaml: {e}")
|
| 66 |
-
return []
|
| 67 |
-
|
| 68 |
-
def get_anima_cn_defaults():
|
| 69 |
-
cn_config = load_anima_controlnet_lllite_config()
|
| 70 |
-
if not cn_config:
|
| 71 |
-
return [], None, [], None, "None"
|
| 72 |
-
all_types = sorted(list(set(t for model in cn_config for t in model.get("Type", []))))
|
| 73 |
-
default_type = all_types[0] if all_types else None
|
| 74 |
-
series_choices = []
|
| 75 |
-
if default_type:
|
| 76 |
-
series_choices = sorted(list(set(model.get("Series", "Default") for model in cn_config if default_type in model.get("Type", []))))
|
| 77 |
-
default_series = series_choices[0] if series_choices else None
|
| 78 |
-
filepath = "None"
|
| 79 |
-
if default_series and default_type:
|
| 80 |
-
for model in cn_config:
|
| 81 |
-
if model.get("Series") == default_series and default_type in model.get("Type", []):
|
| 82 |
-
filepath = model.get("Filepath")
|
| 83 |
-
break
|
| 84 |
-
return all_types, default_type, series_choices, default_series, filepath
|
| 85 |
-
|
| 86 |
-
@lru_cache(maxsize=1)
|
| 87 |
-
def load_diffsynth_controlnet_config():
|
| 88 |
-
_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 89 |
-
_CN_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'diffsynth_controlnet_models.yaml')
|
| 90 |
-
try:
|
| 91 |
-
print("--- Loading diffsynth_controlnet_models.yaml ---")
|
| 92 |
-
with open(_CN_MODEL_LIST_PATH, 'r', encoding='utf-8') as f:
|
| 93 |
-
config = yaml.safe_load(f)
|
| 94 |
-
print("--- ✅ diffsynth_controlnet_models.yaml loaded successfully ---")
|
| 95 |
-
return config.get("DiffSynth_ControlNet", {})
|
| 96 |
-
except Exception as e:
|
| 97 |
-
print(f"Error loading diffsynth_controlnet_models.yaml: {e}")
|
| 98 |
-
return {}
|
| 99 |
-
|
| 100 |
-
def get_diffsynth_cn_defaults(arch_val):
|
| 101 |
-
cn_full_config = load_diffsynth_controlnet_config()
|
| 102 |
-
cn_config = cn_full_config.get(arch_val, [])
|
| 103 |
-
|
| 104 |
-
if not cn_config:
|
| 105 |
-
return [], None, [], None, "None"
|
| 106 |
-
|
| 107 |
-
all_types = sorted(list(set(t for model in cn_config for t in model.get("Type", []))))
|
| 108 |
-
default_type = all_types[0] if all_types else None
|
| 109 |
-
|
| 110 |
-
series_choices = []
|
| 111 |
-
if default_type:
|
| 112 |
-
series_choices = sorted(list(set(model.get("Series", "Default") for model in cn_config if default_type in model.get("Type", []))))
|
| 113 |
-
default_series = series_choices[0] if series_choices else None
|
| 114 |
-
|
| 115 |
-
filepath = "None"
|
| 116 |
-
if default_series and default_type:
|
| 117 |
-
for model in cn_config:
|
| 118 |
-
if model.get("Series") == default_series and default_type in model.get("Type", []):
|
| 119 |
-
filepath = model.get("Filepath")
|
| 120 |
-
break
|
| 121 |
-
|
| 122 |
-
return all_types, default_type, series_choices, default_series, filepath
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
@lru_cache(maxsize=1)
|
| 126 |
-
def load_ipadapter_config():
|
| 127 |
-
_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 128 |
-
_IPA_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'ipadapter.yaml')
|
| 129 |
-
try:
|
| 130 |
-
print("--- Loading ipadapter.yaml ---")
|
| 131 |
-
with open(_IPA_MODEL_LIST_PATH, 'r', encoding='utf-8') as f:
|
| 132 |
-
config = yaml.safe_load(f)
|
| 133 |
-
print("--- ✅ ipadapter.yaml loaded successfully ---")
|
| 134 |
-
return config
|
| 135 |
-
except Exception as e:
|
| 136 |
-
print(f"Error loading ipadapter.yaml: {e}")
|
| 137 |
-
return {}
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
def apply_data_to_ui(data, prefix, ui_components):
|
| 141 |
-
final_sampler = data.get('sampler') if data.get('sampler') in SAMPLER_CHOICES else SAMPLER_CHOICES[0]
|
| 142 |
-
default_scheduler = 'normal' if 'normal' in SCHEDULER_CHOICES else SCHEDULER_CHOICES[0]
|
| 143 |
-
final_scheduler = data.get('scheduler') if data.get('scheduler') in SCHEDULER_CHOICES else default_scheduler
|
| 144 |
-
|
| 145 |
-
updates = {}
|
| 146 |
-
base_model_name = data.get('base_model')
|
| 147 |
-
|
| 148 |
-
model_map = MODEL_MAP_CHECKPOINT
|
| 149 |
-
|
| 150 |
-
if f'base_model_{prefix}' in ui_components:
|
| 151 |
-
model_dropdown_component = ui_components[f'base_model_{prefix}']
|
| 152 |
-
if base_model_name and base_model_name in model_map:
|
| 153 |
-
updates[model_dropdown_component] = base_model_name
|
| 154 |
-
if f'model_arch_{prefix}' in ui_components:
|
| 155 |
-
m_type = MODEL_TYPE_MAP.get(base_model_name, "SDXL")
|
| 156 |
-
updates[ui_components[f'model_arch_{prefix}']] = m_type
|
| 157 |
-
if f'model_cat_{prefix}' in ui_components:
|
| 158 |
-
m_info = model_map.get(base_model_name)
|
| 159 |
-
m_cat = m_info[4] if m_info and len(m_info) > 4 else None
|
| 160 |
-
updates[ui_components[f'model_cat_{prefix}']] = m_cat if m_cat else "ALL"
|
| 161 |
-
else:
|
| 162 |
-
updates[model_dropdown_component] = gr.update()
|
| 163 |
-
|
| 164 |
-
common_params = {
|
| 165 |
-
f'prompt_{prefix}': data.get('prompt', ''),
|
| 166 |
-
f'neg_prompt_{prefix}': data.get('negative_prompt', ''),
|
| 167 |
-
f'seed_{prefix}': data.get('seed', -1),
|
| 168 |
-
f'cfg_{prefix}': data.get('cfg_scale', 7.5),
|
| 169 |
-
f'steps_{prefix}': data.get('steps', 28),
|
| 170 |
-
f'sampler_{prefix}': final_sampler,
|
| 171 |
-
f'scheduler_{prefix}': final_scheduler,
|
| 172 |
-
}
|
| 173 |
-
|
| 174 |
-
for comp_name, value in common_params.items():
|
| 175 |
-
if comp_name in ui_components:
|
| 176 |
-
updates[ui_components[comp_name]] = value
|
| 177 |
-
|
| 178 |
-
if prefix == 'txt2img':
|
| 179 |
-
if f'width_{prefix}' in ui_components:
|
| 180 |
-
updates[ui_components[f'width_{prefix}']] = data.get('width', 1024)
|
| 181 |
-
if f'height_{prefix}' in ui_components:
|
| 182 |
-
updates[ui_components[f'height_{prefix}']] = data.get('height', 1024)
|
| 183 |
-
|
| 184 |
-
tab_indices = {"txt2img": 0, "img2img": 1, "inpaint": 2, "outpaint": 3, "hires_fix": 4}
|
| 185 |
-
tab_index = tab_indices.get(prefix, 0)
|
| 186 |
-
|
| 187 |
-
updates[ui_components['tabs']] = gr.Tabs(selected=tab_index)
|
| 188 |
-
|
| 189 |
-
return updates
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
def send_info_to_tab(image, prefix, ui_components):
|
| 193 |
-
if not image or not image.info.get('parameters', ''):
|
| 194 |
-
all_comps = [comp for comp_or_list in ui_components.values() for comp in (comp_or_list if isinstance(comp_or_list, list) else [comp_or_list])]
|
| 195 |
-
return {comp: gr.update() for comp in all_comps}
|
| 196 |
-
|
| 197 |
-
data = parse_parameters(image.info['parameters'])
|
| 198 |
-
|
| 199 |
-
image_input_map = {
|
| 200 |
-
"img2img": 'input_image_img2img',
|
| 201 |
-
"inpaint": 'input_image_dict_inpaint',
|
| 202 |
-
"outpaint": 'input_image_outpaint',
|
| 203 |
-
"hires_fix": 'input_image_hires_fix'
|
| 204 |
-
}
|
| 205 |
-
|
| 206 |
-
updates = apply_data_to_ui(data, prefix, ui_components)
|
| 207 |
-
|
| 208 |
-
if prefix in image_input_map and image_input_map[prefix] in ui_components:
|
| 209 |
-
component_key = image_input_map[prefix]
|
| 210 |
-
updates[ui_components[component_key]] = gr.update(value=image)
|
| 211 |
-
|
| 212 |
-
return updates
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
def send_info_by_hash(image, ui_components):
|
| 216 |
-
if not image or not image.info.get('parameters', ''):
|
| 217 |
-
all_comps = [comp for comp_or_list in ui_components.values() for comp in (comp_or_list if isinstance(comp_or_list, list) else [comp_or_list])]
|
| 218 |
-
return {comp: gr.update() for comp in all_comps}
|
| 219 |
-
|
| 220 |
-
data = parse_parameters(image.info['parameters'])
|
| 221 |
-
|
| 222 |
-
return apply_data_to_ui(data, "txt2img", ui_components)
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
def attach_event_handlers(ui_components, demo):
|
| 226 |
-
|
| 227 |
-
def create_lora_event_handlers(prefix):
|
| 228 |
-
lora_rows = ui_components.get(f'lora_rows_{prefix}')
|
| 229 |
-
if not lora_rows: return
|
| 230 |
-
lora_ids = ui_components[f'lora_ids_{prefix}']
|
| 231 |
-
lora_scales = ui_components[f'lora_scales_{prefix}']
|
| 232 |
-
lora_uploads = ui_components[f'lora_uploads_{prefix}']
|
| 233 |
-
count_state = ui_components[f'lora_count_state_{prefix}']
|
| 234 |
-
add_button = ui_components[f'add_lora_button_{prefix}']
|
| 235 |
-
del_button = ui_components[f'delete_lora_button_{prefix}']
|
| 236 |
-
|
| 237 |
-
def add_lora_row(c):
|
| 238 |
-
updates = {}
|
| 239 |
-
if c < MAX_LORAS:
|
| 240 |
-
c += 1
|
| 241 |
-
updates[lora_rows[c - 1]] = gr.update(visible=True)
|
| 242 |
-
|
| 243 |
-
updates[count_state] = c
|
| 244 |
-
updates[add_button] = gr.update(visible=c < MAX_LORAS)
|
| 245 |
-
updates[del_button] = gr.update(visible=c > 1)
|
| 246 |
-
return updates
|
| 247 |
-
|
| 248 |
-
def del_lora_row(c):
|
| 249 |
-
updates = {}
|
| 250 |
-
if c > 1:
|
| 251 |
-
updates[lora_rows[c - 1]] = gr.update(visible=False)
|
| 252 |
-
updates[lora_ids[c - 1]] = ""
|
| 253 |
-
updates[lora_scales[c - 1]] = 0.0
|
| 254 |
-
updates[lora_uploads[c - 1]] = None
|
| 255 |
-
c -= 1
|
| 256 |
-
|
| 257 |
-
updates[count_state] = c
|
| 258 |
-
updates[add_button] = gr.update(visible=True)
|
| 259 |
-
updates[del_button] = gr.update(visible=c > 1)
|
| 260 |
-
return updates
|
| 261 |
-
|
| 262 |
-
add_outputs = [count_state, add_button, del_button] + lora_rows
|
| 263 |
-
del_outputs = [count_state, add_button, del_button] + lora_rows + lora_ids + lora_scales + lora_uploads
|
| 264 |
-
|
| 265 |
-
add_button.click(add_lora_row, [count_state], add_outputs, show_progress=False)
|
| 266 |
-
del_button.click(del_lora_row, [count_state], del_outputs, show_progress=False)
|
| 267 |
-
|
| 268 |
-
def create_controlnet_event_handlers(prefix):
|
| 269 |
-
cn_rows = ui_components.get(f'controlnet_rows_{prefix}')
|
| 270 |
-
if not cn_rows: return
|
| 271 |
-
cn_types = ui_components[f'controlnet_types_{prefix}']
|
| 272 |
-
cn_series = ui_components[f'controlnet_series_{prefix}']
|
| 273 |
-
cn_filepaths = ui_components[f'controlnet_filepaths_{prefix}']
|
| 274 |
-
cn_images = ui_components[f'controlnet_images_{prefix}']
|
| 275 |
-
cn_strengths = ui_components[f'controlnet_strengths_{prefix}']
|
| 276 |
-
|
| 277 |
-
count_state = ui_components[f'controlnet_count_state_{prefix}']
|
| 278 |
-
add_button = ui_components[f'add_controlnet_button_{prefix}']
|
| 279 |
-
del_button = ui_components[f'delete_controlnet_button_{prefix}']
|
| 280 |
-
accordion = ui_components[f'controlnet_accordion_{prefix}']
|
| 281 |
-
|
| 282 |
-
base_model_comp = ui_components.get(f'base_model_{prefix}')
|
| 283 |
-
actual_arch_comp = base_model_comp if base_model_comp else gr.State("SDXL")
|
| 284 |
-
|
| 285 |
-
def add_cn_row(c):
|
| 286 |
-
c += 1
|
| 287 |
-
updates = {
|
| 288 |
-
count_state: c,
|
| 289 |
-
cn_rows[c-1]: gr.update(visible=True),
|
| 290 |
-
add_button: gr.update(visible=c < MAX_CONTROLNETS),
|
| 291 |
-
del_button: gr.update(visible=True)
|
| 292 |
-
}
|
| 293 |
-
return updates
|
| 294 |
-
|
| 295 |
-
def del_cn_row(c):
|
| 296 |
-
c -= 1
|
| 297 |
-
updates = {
|
| 298 |
-
count_state: c,
|
| 299 |
-
cn_rows[c]: gr.update(visible=False),
|
| 300 |
-
cn_images[c]: None,
|
| 301 |
-
cn_strengths[c]: 1.0,
|
| 302 |
-
add_button: gr.update(visible=True),
|
| 303 |
-
del_button: gr.update(visible=c > 0)
|
| 304 |
-
}
|
| 305 |
-
return updates
|
| 306 |
-
|
| 307 |
-
add_outputs = [count_state, add_button, del_button] + cn_rows
|
| 308 |
-
del_outputs = [count_state, add_button, del_button] + cn_rows + cn_images + cn_strengths
|
| 309 |
-
add_button.click(fn=add_cn_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 310 |
-
del_button.click(fn=del_cn_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 311 |
-
|
| 312 |
-
def on_cn_type_change(selected_type, model_name):
|
| 313 |
-
from core.settings import MODEL_TYPE_MAP
|
| 314 |
-
m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL"
|
| 315 |
-
cn_full_config = load_controlnet_config()
|
| 316 |
-
|
| 317 |
-
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 318 |
-
controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
|
| 319 |
-
|
| 320 |
-
cn_config = cn_full_config.get(controlnet_key, [])
|
| 321 |
-
series_choices = []
|
| 322 |
-
if selected_type:
|
| 323 |
-
series_choices = sorted(list(set(
|
| 324 |
-
model.get("Series", "Default") for model in cn_config
|
| 325 |
-
if selected_type in model.get("Type", [])
|
| 326 |
-
)))
|
| 327 |
-
default_series = series_choices[0] if series_choices else None
|
| 328 |
-
filepath = "None"
|
| 329 |
-
if default_series:
|
| 330 |
-
for model in cn_config:
|
| 331 |
-
if model.get("Series") == default_series and selected_type in model.get("Type", []):
|
| 332 |
-
filepath = model.get("Filepath")
|
| 333 |
-
break
|
| 334 |
-
return gr.update(choices=series_choices, value=default_series), filepath
|
| 335 |
-
|
| 336 |
-
def on_cn_series_change(selected_series, selected_type, model_name):
|
| 337 |
-
from core.settings import MODEL_TYPE_MAP
|
| 338 |
-
m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL"
|
| 339 |
-
cn_full_config = load_controlnet_config()
|
| 340 |
-
|
| 341 |
-
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 342 |
-
controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
|
| 343 |
-
|
| 344 |
-
cn_config = cn_full_config.get(controlnet_key, [])
|
| 345 |
-
filepath = "None"
|
| 346 |
-
if selected_series and selected_type:
|
| 347 |
-
for model in cn_config:
|
| 348 |
-
if model.get("Series") == selected_series and selected_type in model.get("Type", []):
|
| 349 |
-
filepath = model.get("Filepath")
|
| 350 |
-
break
|
| 351 |
-
return filepath
|
| 352 |
-
|
| 353 |
-
for i in range(MAX_CONTROLNETS):
|
| 354 |
-
cn_types[i].change(
|
| 355 |
-
fn=on_cn_type_change,
|
| 356 |
-
inputs=[cn_types[i], actual_arch_comp],
|
| 357 |
-
outputs=[cn_series[i], cn_filepaths[i]],
|
| 358 |
-
show_progress=False
|
| 359 |
-
)
|
| 360 |
-
cn_series[i].change(
|
| 361 |
-
fn=on_cn_series_change,
|
| 362 |
-
inputs=[cn_series[i], cn_types[i], actual_arch_comp],
|
| 363 |
-
outputs=[cn_filepaths[i]],
|
| 364 |
-
show_progress=False
|
| 365 |
-
)
|
| 366 |
-
|
| 367 |
-
def on_accordion_expand(*images):
|
| 368 |
-
return [gr.update() for _ in images]
|
| 369 |
-
|
| 370 |
-
accordion.expand(
|
| 371 |
-
fn=on_accordion_expand,
|
| 372 |
-
inputs=cn_images,
|
| 373 |
-
outputs=cn_images,
|
| 374 |
-
show_progress=False
|
| 375 |
-
)
|
| 376 |
-
|
| 377 |
-
def create_anima_controlnet_lllite_event_handlers(prefix):
|
| 378 |
-
cn_rows = ui_components.get(f'anima_controlnet_lllite_rows_{prefix}')
|
| 379 |
-
if not cn_rows: return
|
| 380 |
-
cn_types = ui_components[f'anima_controlnet_lllite_types_{prefix}']
|
| 381 |
-
cn_series = ui_components[f'anima_controlnet_lllite_series_{prefix}']
|
| 382 |
-
cn_filepaths = ui_components[f'anima_controlnet_lllite_filepaths_{prefix}']
|
| 383 |
-
cn_images = ui_components[f'anima_controlnet_lllite_images_{prefix}']
|
| 384 |
-
cn_strengths = ui_components[f'anima_controlnet_lllite_strengths_{prefix}']
|
| 385 |
-
|
| 386 |
-
count_state = ui_components[f'anima_controlnet_lllite_count_state_{prefix}']
|
| 387 |
-
add_button = ui_components[f'add_anima_controlnet_lllite_button_{prefix}']
|
| 388 |
-
del_button = ui_components[f'delete_anima_controlnet_lllite_button_{prefix}']
|
| 389 |
-
accordion = ui_components[f'anima_controlnet_lllite_accordion_{prefix}']
|
| 390 |
-
|
| 391 |
-
def add_cn_row(c):
|
| 392 |
-
c += 1
|
| 393 |
-
updates = {
|
| 394 |
-
count_state: c,
|
| 395 |
-
cn_rows[c-1]: gr.update(visible=True),
|
| 396 |
-
add_button: gr.update(visible=c < MAX_CONTROLNETS),
|
| 397 |
-
del_button: gr.update(visible=True)
|
| 398 |
-
}
|
| 399 |
-
return updates
|
| 400 |
-
|
| 401 |
-
def del_cn_row(c):
|
| 402 |
-
c -= 1
|
| 403 |
-
updates = {
|
| 404 |
-
count_state: c,
|
| 405 |
-
cn_rows[c]: gr.update(visible=False),
|
| 406 |
-
cn_images[c]: None,
|
| 407 |
-
cn_strengths[c]: 1.0,
|
| 408 |
-
add_button: gr.update(visible=True),
|
| 409 |
-
del_button: gr.update(visible=c > 0)
|
| 410 |
-
}
|
| 411 |
-
return updates
|
| 412 |
-
|
| 413 |
-
add_outputs = [count_state, add_button, del_button] + cn_rows
|
| 414 |
-
del_outputs = [count_state, add_button, del_button] + cn_rows + cn_images + cn_strengths
|
| 415 |
-
add_button.click(fn=add_cn_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 416 |
-
del_button.click(fn=del_cn_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 417 |
-
|
| 418 |
-
def on_cn_type_change(selected_type):
|
| 419 |
-
cn_config = load_anima_controlnet_lllite_config()
|
| 420 |
-
series_choices = []
|
| 421 |
-
if selected_type:
|
| 422 |
-
series_choices = sorted(list(set(
|
| 423 |
-
model.get("Series", "Default") for model in cn_config
|
| 424 |
-
if selected_type in model.get("Type", [])
|
| 425 |
-
)))
|
| 426 |
-
default_series = series_choices[0] if series_choices else None
|
| 427 |
-
filepath = "None"
|
| 428 |
-
if default_series:
|
| 429 |
-
for model in cn_config:
|
| 430 |
-
if model.get("Series") == default_series and selected_type in model.get("Type", []):
|
| 431 |
-
filepath = model.get("Filepath")
|
| 432 |
-
break
|
| 433 |
-
return gr.update(choices=series_choices, value=default_series), filepath
|
| 434 |
-
|
| 435 |
-
def on_cn_series_change(selected_series, selected_type):
|
| 436 |
-
cn_config = load_anima_controlnet_lllite_config()
|
| 437 |
-
filepath = "None"
|
| 438 |
-
if selected_series and selected_type:
|
| 439 |
-
for model in cn_config:
|
| 440 |
-
if model.get("Series") == selected_series and selected_type in model.get("Type", []):
|
| 441 |
-
filepath = model.get("Filepath")
|
| 442 |
-
break
|
| 443 |
-
return filepath
|
| 444 |
-
|
| 445 |
-
for i in range(MAX_CONTROLNETS):
|
| 446 |
-
cn_types[i].change(
|
| 447 |
-
fn=on_cn_type_change,
|
| 448 |
-
inputs=[cn_types[i]],
|
| 449 |
-
outputs=[cn_series[i], cn_filepaths[i]],
|
| 450 |
-
show_progress=False
|
| 451 |
-
)
|
| 452 |
-
cn_series[i].change(
|
| 453 |
-
fn=on_cn_series_change,
|
| 454 |
-
inputs=[cn_series[i], cn_types[i]],
|
| 455 |
-
outputs=[cn_filepaths[i]],
|
| 456 |
-
show_progress=False
|
| 457 |
-
)
|
| 458 |
-
|
| 459 |
-
def on_accordion_expand(*images):
|
| 460 |
-
return [gr.update() for _ in images]
|
| 461 |
-
|
| 462 |
-
accordion.expand(
|
| 463 |
-
fn=on_accordion_expand,
|
| 464 |
-
inputs=cn_images,
|
| 465 |
-
outputs=cn_images,
|
| 466 |
-
show_progress=False
|
| 467 |
-
)
|
| 468 |
-
|
| 469 |
-
def create_diffsynth_controlnet_event_handlers(prefix):
|
| 470 |
-
cn_rows = ui_components.get(f'diffsynth_controlnet_rows_{prefix}')
|
| 471 |
-
if not cn_rows: return
|
| 472 |
-
cn_types = ui_components[f'diffsynth_controlnet_types_{prefix}']
|
| 473 |
-
cn_series = ui_components[f'diffsynth_controlnet_series_{prefix}']
|
| 474 |
-
cn_filepaths = ui_components[f'diffsynth_controlnet_filepaths_{prefix}']
|
| 475 |
-
cn_images = ui_components[f'diffsynth_controlnet_images_{prefix}']
|
| 476 |
-
cn_strengths = ui_components[f'diffsynth_controlnet_strengths_{prefix}']
|
| 477 |
-
|
| 478 |
-
count_state = ui_components[f'diffsynth_controlnet_count_state_{prefix}']
|
| 479 |
-
add_button = ui_components[f'add_diffsynth_controlnet_button_{prefix}']
|
| 480 |
-
del_button = ui_components[f'delete_diffsynth_controlnet_button_{prefix}']
|
| 481 |
-
accordion = ui_components[f'diffsynth_controlnet_accordion_{prefix}']
|
| 482 |
-
|
| 483 |
-
base_model_comp = ui_components.get(f'base_model_{prefix}')
|
| 484 |
-
actual_arch_comp = base_model_comp if base_model_comp else gr.State("SDXL")
|
| 485 |
-
|
| 486 |
-
def add_cn_row(c):
|
| 487 |
-
c += 1
|
| 488 |
-
updates = {
|
| 489 |
-
count_state: c,
|
| 490 |
-
cn_rows[c-1]: gr.update(visible=True),
|
| 491 |
-
add_button: gr.update(visible=c < MAX_CONTROLNETS),
|
| 492 |
-
del_button: gr.update(visible=True)
|
| 493 |
-
}
|
| 494 |
-
return updates
|
| 495 |
-
|
| 496 |
-
def del_cn_row(c):
|
| 497 |
-
c -= 1
|
| 498 |
-
updates = {
|
| 499 |
-
count_state: c,
|
| 500 |
-
cn_rows[c]: gr.update(visible=False),
|
| 501 |
-
cn_images[c]: None,
|
| 502 |
-
cn_strengths[c]: 1.0,
|
| 503 |
-
add_button: gr.update(visible=True),
|
| 504 |
-
del_button: gr.update(visible=c > 0)
|
| 505 |
-
}
|
| 506 |
-
return updates
|
| 507 |
-
|
| 508 |
-
add_outputs = [count_state, add_button, del_button] + cn_rows
|
| 509 |
-
del_outputs = [count_state, add_button, del_button] + cn_rows + cn_images + cn_strengths
|
| 510 |
-
add_button.click(fn=add_cn_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 511 |
-
del_button.click(fn=del_cn_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 512 |
-
|
| 513 |
-
def on_cn_type_change(selected_type, model_name):
|
| 514 |
-
from core.settings import MODEL_TYPE_MAP
|
| 515 |
-
m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL"
|
| 516 |
-
cn_full_config = load_diffsynth_controlnet_config()
|
| 517 |
-
|
| 518 |
-
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 519 |
-
controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
|
| 520 |
-
|
| 521 |
-
cn_config = cn_full_config.get(controlnet_key, [])
|
| 522 |
-
series_choices = []
|
| 523 |
-
if selected_type:
|
| 524 |
-
series_choices = sorted(list(set(
|
| 525 |
-
model.get("Series", "Default") for model in cn_config
|
| 526 |
-
if selected_type in model.get("Type", [])
|
| 527 |
-
)))
|
| 528 |
-
default_series = series_choices[0] if series_choices else None
|
| 529 |
-
filepath = "None"
|
| 530 |
-
if default_series:
|
| 531 |
-
for model in cn_config:
|
| 532 |
-
if model.get("Series") == default_series and selected_type in model.get("Type", []):
|
| 533 |
-
filepath = model.get("Filepath")
|
| 534 |
-
break
|
| 535 |
-
return gr.update(choices=series_choices, value=default_series), filepath
|
| 536 |
-
|
| 537 |
-
def on_cn_series_change(selected_series, selected_type, model_name):
|
| 538 |
-
from core.settings import MODEL_TYPE_MAP
|
| 539 |
-
m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL"
|
| 540 |
-
cn_full_config = load_diffsynth_controlnet_config()
|
| 541 |
-
|
| 542 |
-
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 543 |
-
controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
|
| 544 |
-
|
| 545 |
-
cn_config = cn_full_config.get(controlnet_key, [])
|
| 546 |
-
filepath = "None"
|
| 547 |
-
if selected_series and selected_type:
|
| 548 |
-
for model in cn_config:
|
| 549 |
-
if model.get("Series") == selected_series and selected_type in model.get("Type", []):
|
| 550 |
-
filepath = model.get("Filepath")
|
| 551 |
-
break
|
| 552 |
-
return filepath
|
| 553 |
-
|
| 554 |
-
for i in range(MAX_CONTROLNETS):
|
| 555 |
-
cn_types[i].change(
|
| 556 |
-
fn=on_cn_type_change,
|
| 557 |
-
inputs=[cn_types[i], actual_arch_comp],
|
| 558 |
-
outputs=[cn_series[i], cn_filepaths[i]],
|
| 559 |
-
show_progress=False
|
| 560 |
-
)
|
| 561 |
-
cn_series[i].change(
|
| 562 |
-
fn=on_cn_series_change,
|
| 563 |
-
inputs=[cn_series[i], cn_types[i], actual_arch_comp],
|
| 564 |
-
outputs=[cn_filepaths[i]],
|
| 565 |
-
show_progress=False
|
| 566 |
-
)
|
| 567 |
-
|
| 568 |
-
def on_accordion_expand(*images):
|
| 569 |
-
return [gr.update() for _ in images]
|
| 570 |
-
|
| 571 |
-
accordion.expand(
|
| 572 |
-
fn=on_accordion_expand,
|
| 573 |
-
inputs=cn_images,
|
| 574 |
-
outputs=cn_images,
|
| 575 |
-
show_progress=False
|
| 576 |
-
)
|
| 577 |
-
|
| 578 |
-
def create_flux1_ipadapter_event_handlers(prefix):
|
| 579 |
-
fipa_rows = ui_components.get(f'flux1_ipadapter_rows_{prefix}')
|
| 580 |
-
if not fipa_rows: return
|
| 581 |
-
count_state = ui_components[f'flux1_ipadapter_count_state_{prefix}']
|
| 582 |
-
add_button = ui_components[f'add_flux1_ipadapter_button_{prefix}']
|
| 583 |
-
del_button = ui_components[f'delete_flux1_ipadapter_button_{prefix}']
|
| 584 |
-
|
| 585 |
-
def add_fipa_row(c):
|
| 586 |
-
c += 1
|
| 587 |
-
return {
|
| 588 |
-
count_state: c,
|
| 589 |
-
fipa_rows[c - 1]: gr.update(visible=True),
|
| 590 |
-
add_button: gr.update(visible=c < MAX_IPADAPTERS),
|
| 591 |
-
del_button: gr.update(visible=True),
|
| 592 |
-
}
|
| 593 |
-
|
| 594 |
-
def del_fipa_row(c):
|
| 595 |
-
c -= 1
|
| 596 |
-
return {
|
| 597 |
-
count_state: c,
|
| 598 |
-
fipa_rows[c]: gr.update(visible=False),
|
| 599 |
-
add_button: gr.update(visible=True),
|
| 600 |
-
del_button: gr.update(visible=c > 0),
|
| 601 |
-
}
|
| 602 |
-
|
| 603 |
-
add_outputs = [count_state, add_button, del_button] + fipa_rows
|
| 604 |
-
del_outputs = [count_state, add_button, del_button] + fipa_rows
|
| 605 |
-
add_button.click(fn=add_fipa_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 606 |
-
del_button.click(fn=del_fipa_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 607 |
-
|
| 608 |
-
def create_sd3_ipadapter_event_handlers(prefix):
|
| 609 |
-
ipa_rows = ui_components.get(f'sd3_ipadapter_rows_{prefix}')
|
| 610 |
-
if not ipa_rows: return
|
| 611 |
-
count_state = ui_components[f'sd3_ipadapter_count_state_{prefix}']
|
| 612 |
-
add_button = ui_components[f'add_sd3_ipadapter_button_{prefix}']
|
| 613 |
-
del_button = ui_components[f'delete_sd3_ipadapter_button_{prefix}']
|
| 614 |
-
images = ui_components[f'sd3_ipadapter_images_{prefix}']
|
| 615 |
-
weights = ui_components[f'sd3_ipadapter_weights_{prefix}']
|
| 616 |
-
start_percents = ui_components[f'sd3_ipadapter_start_percents_{prefix}']
|
| 617 |
-
end_percents = ui_components[f'sd3_ipadapter_end_percents_{prefix}']
|
| 618 |
-
|
| 619 |
-
def add_ipa_row(c):
|
| 620 |
-
c += 1
|
| 621 |
-
return {
|
| 622 |
-
count_state: c,
|
| 623 |
-
ipa_rows[c - 1]: gr.update(visible=True),
|
| 624 |
-
add_button: gr.update(visible=c < MAX_IPADAPTERS),
|
| 625 |
-
del_button: gr.update(visible=True),
|
| 626 |
-
}
|
| 627 |
-
|
| 628 |
-
def del_ipa_row(c):
|
| 629 |
-
c -= 1
|
| 630 |
-
return {
|
| 631 |
-
count_state: c,
|
| 632 |
-
ipa_rows[c]: gr.update(visible=False),
|
| 633 |
-
images[c]: None,
|
| 634 |
-
weights[c]: 0.5,
|
| 635 |
-
start_percents[c]: 0.0,
|
| 636 |
-
end_percents[c]: 1.0,
|
| 637 |
-
add_button: gr.update(visible=True),
|
| 638 |
-
del_button: gr.update(visible=c > 0),
|
| 639 |
-
}
|
| 640 |
-
|
| 641 |
-
add_outputs = [count_state, add_button, del_button] + ipa_rows
|
| 642 |
-
del_outputs = [count_state, add_button, del_button] + ipa_rows + images + weights + start_percents + end_percents
|
| 643 |
-
add_button.click(fn=add_ipa_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 644 |
-
del_button.click(fn=del_ipa_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 645 |
-
|
| 646 |
-
def create_style_event_handlers(prefix):
|
| 647 |
-
style_rows = ui_components.get(f'style_rows_{prefix}')
|
| 648 |
-
if not style_rows: return
|
| 649 |
-
count_state = ui_components[f'style_count_state_{prefix}']
|
| 650 |
-
add_button = ui_components[f'add_style_button_{prefix}']
|
| 651 |
-
del_button = ui_components[f'delete_style_button_{prefix}']
|
| 652 |
-
|
| 653 |
-
def add_style_row(c):
|
| 654 |
-
c += 1
|
| 655 |
-
return {
|
| 656 |
-
count_state: c,
|
| 657 |
-
style_rows[c - 1]: gr.update(visible=True),
|
| 658 |
-
add_button: gr.update(visible=c < 5),
|
| 659 |
-
del_button: gr.update(visible=True),
|
| 660 |
-
}
|
| 661 |
-
|
| 662 |
-
def del_style_row(c):
|
| 663 |
-
c -= 1
|
| 664 |
-
return {
|
| 665 |
-
count_state: c,
|
| 666 |
-
style_rows[c]: gr.update(visible=False),
|
| 667 |
-
add_button: gr.update(visible=True),
|
| 668 |
-
del_button: gr.update(visible=c > 0),
|
| 669 |
-
}
|
| 670 |
-
|
| 671 |
-
add_outputs = [count_state, add_button, del_button] + style_rows
|
| 672 |
-
del_outputs = [count_state, add_button, del_button] + style_rows
|
| 673 |
-
add_button.click(fn=add_style_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 674 |
-
del_button.click(fn=del_style_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 675 |
-
|
| 676 |
-
def create_ipadapter_event_handlers(prefix):
|
| 677 |
-
ipa_rows = ui_components.get(f'ipadapter_rows_{prefix}')
|
| 678 |
-
if not ipa_rows: return
|
| 679 |
-
ipa_lora_strengths = ui_components[f'ipadapter_lora_strengths_{prefix}']
|
| 680 |
-
ipa_final_preset = ui_components[f'ipadapter_final_preset_{prefix}']
|
| 681 |
-
ipa_final_lora_strength = ui_components[f'ipadapter_final_lora_strength_{prefix}']
|
| 682 |
-
count_state = ui_components[f'ipadapter_count_state_{prefix}']
|
| 683 |
-
add_button = ui_components[f'add_ipadapter_button_{prefix}']
|
| 684 |
-
del_button = ui_components[f'delete_ipadapter_button_{prefix}']
|
| 685 |
-
accordion = ui_components[f'ipadapter_accordion_{prefix}']
|
| 686 |
-
|
| 687 |
-
def add_ipa_row(c):
|
| 688 |
-
c += 1
|
| 689 |
-
return {
|
| 690 |
-
count_state: c,
|
| 691 |
-
ipa_rows[c - 1]: gr.update(visible=True),
|
| 692 |
-
add_button: gr.update(visible=c < MAX_IPADAPTERS),
|
| 693 |
-
del_button: gr.update(visible=True),
|
| 694 |
-
}
|
| 695 |
-
|
| 696 |
-
def del_ipa_row(c):
|
| 697 |
-
c -= 1
|
| 698 |
-
return {
|
| 699 |
-
count_state: c,
|
| 700 |
-
ipa_rows[c]: gr.update(visible=False),
|
| 701 |
-
add_button: gr.update(visible=True),
|
| 702 |
-
del_button: gr.update(visible=c > 0),
|
| 703 |
-
}
|
| 704 |
-
|
| 705 |
-
add_outputs = [count_state, add_button, del_button] + ipa_rows
|
| 706 |
-
del_outputs = [count_state, add_button, del_button] + ipa_rows
|
| 707 |
-
add_button.click(fn=add_ipa_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 708 |
-
del_button.click(fn=del_ipa_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 709 |
-
|
| 710 |
-
def on_preset_change(preset_value):
|
| 711 |
-
config = load_ipadapter_config()
|
| 712 |
-
faceid_presets = []
|
| 713 |
-
if config:
|
| 714 |
-
faceid_presets.extend(config.get("IPAdapter_FaceID_presets", {}).get("SDXL", []))
|
| 715 |
-
faceid_presets.extend(config.get("IPAdapter_FaceID_presets", {}).get("SD1.5", []))
|
| 716 |
-
|
| 717 |
-
is_visible = preset_value in faceid_presets
|
| 718 |
-
updates = [gr.update(visible=is_visible)] * (MAX_IPADAPTERS + 1)
|
| 719 |
-
return updates
|
| 720 |
-
|
| 721 |
-
all_lora_strength_sliders = [ipa_final_lora_strength] + ipa_lora_strengths
|
| 722 |
-
ipa_final_preset.change(fn=on_preset_change, inputs=[ipa_final_preset], outputs=all_lora_strength_sliders, show_progress=False)
|
| 723 |
-
|
| 724 |
-
accordion.expand(fn=lambda *imgs: [gr.update() for _ in imgs], inputs=ui_components[f'ipadapter_images_{prefix}'], outputs=ui_components[f'ipadapter_images_{prefix}'], show_progress=False)
|
| 725 |
-
|
| 726 |
-
def create_reference_latent_event_handlers(prefix):
|
| 727 |
-
ref_rows = ui_components.get(f'reference_latent_rows_{prefix}')
|
| 728 |
-
if not ref_rows: return
|
| 729 |
-
count_state = ui_components[f'reference_latent_count_state_{prefix}']
|
| 730 |
-
add_button = ui_components[f'add_reference_latent_button_{prefix}']
|
| 731 |
-
del_button = ui_components[f'delete_reference_latent_button_{prefix}']
|
| 732 |
-
images = ui_components[f'reference_latent_images_{prefix}']
|
| 733 |
-
|
| 734 |
-
def add_ref_row(c):
|
| 735 |
-
c += 1
|
| 736 |
-
return {
|
| 737 |
-
count_state: c,
|
| 738 |
-
ref_rows[c - 1]: gr.update(visible=True),
|
| 739 |
-
add_button: gr.update(visible=c < 10),
|
| 740 |
-
del_button: gr.update(visible=True),
|
| 741 |
-
}
|
| 742 |
-
|
| 743 |
-
def del_ref_row(c):
|
| 744 |
-
c -= 1
|
| 745 |
-
return {
|
| 746 |
-
count_state: c,
|
| 747 |
-
ref_rows[c]: gr.update(visible=False),
|
| 748 |
-
images[c]: None,
|
| 749 |
-
add_button: gr.update(visible=True),
|
| 750 |
-
del_button: gr.update(visible=c > 0),
|
| 751 |
-
}
|
| 752 |
-
|
| 753 |
-
add_outputs = [count_state, add_button, del_button] + ref_rows
|
| 754 |
-
del_outputs = [count_state, add_button, del_button] + ref_rows + images
|
| 755 |
-
add_button.click(fn=add_ref_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 756 |
-
del_button.click(fn=del_ref_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 757 |
-
|
| 758 |
-
def create_hidream_o1_reference_event_handlers(prefix):
|
| 759 |
-
ref_rows = ui_components.get(f'hidream_o1_reference_rows_{prefix}')
|
| 760 |
-
if not ref_rows: return
|
| 761 |
-
count_state = ui_components[f'hidream_o1_reference_count_state_{prefix}']
|
| 762 |
-
add_button = ui_components[f'add_hidream_o1_reference_button_{prefix}']
|
| 763 |
-
del_button = ui_components[f'delete_hidream_o1_reference_button_{prefix}']
|
| 764 |
-
images = ui_components[f'hidream_o1_reference_images_{prefix}']
|
| 765 |
-
|
| 766 |
-
def add_ref_row(c):
|
| 767 |
-
c += 1
|
| 768 |
-
return {
|
| 769 |
-
count_state: c,
|
| 770 |
-
ref_rows[c - 1]: gr.update(visible=True),
|
| 771 |
-
add_button: gr.update(visible=c < 10),
|
| 772 |
-
del_button: gr.update(visible=True),
|
| 773 |
-
}
|
| 774 |
-
|
| 775 |
-
def del_ref_row(c):
|
| 776 |
-
c -= 1
|
| 777 |
-
return {
|
| 778 |
-
count_state: c,
|
| 779 |
-
ref_rows[c]: gr.update(visible=False),
|
| 780 |
-
images[c]: None,
|
| 781 |
-
add_button: gr.update(visible=True),
|
| 782 |
-
del_button: gr.update(visible=c > 0),
|
| 783 |
-
}
|
| 784 |
-
|
| 785 |
-
add_outputs = [count_state, add_button, del_button] + ref_rows
|
| 786 |
-
del_outputs = [count_state, add_button, del_button] + ref_rows + images
|
| 787 |
-
add_button.click(fn=add_ref_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 788 |
-
del_button.click(fn=del_ref_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 789 |
-
|
| 790 |
-
def create_embedding_event_handlers(prefix):
|
| 791 |
-
rows = ui_components.get(f'embedding_rows_{prefix}')
|
| 792 |
-
if not rows: return
|
| 793 |
-
ids = ui_components[f'embeddings_ids_{prefix}']
|
| 794 |
-
files = ui_components[f'embeddings_files_{prefix}']
|
| 795 |
-
count_state = ui_components[f'embedding_count_state_{prefix}']
|
| 796 |
-
add_button = ui_components[f'add_embedding_button_{prefix}']
|
| 797 |
-
del_button = ui_components[f'delete_embedding_button_{prefix}']
|
| 798 |
-
|
| 799 |
-
def add_row(c):
|
| 800 |
-
c += 1
|
| 801 |
-
return {
|
| 802 |
-
count_state: c,
|
| 803 |
-
rows[c - 1]: gr.update(visible=True),
|
| 804 |
-
add_button: gr.update(visible=c < MAX_EMBEDDINGS),
|
| 805 |
-
del_button: gr.update(visible=True)
|
| 806 |
-
}
|
| 807 |
-
|
| 808 |
-
def del_row(c):
|
| 809 |
-
c -= 1
|
| 810 |
-
return {
|
| 811 |
-
count_state: c,
|
| 812 |
-
rows[c]: gr.update(visible=False),
|
| 813 |
-
ids[c]: "",
|
| 814 |
-
files[c]: None,
|
| 815 |
-
add_button: gr.update(visible=True),
|
| 816 |
-
del_button: gr.update(visible=c > 0)
|
| 817 |
-
}
|
| 818 |
-
|
| 819 |
-
add_outputs = [count_state, add_button, del_button] + rows
|
| 820 |
-
del_outputs = [count_state, add_button, del_button] + rows + ids + files
|
| 821 |
-
add_button.click(fn=add_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 822 |
-
del_button.click(fn=del_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 823 |
-
|
| 824 |
-
def create_conditioning_event_handlers(prefix):
|
| 825 |
-
rows = ui_components.get(f'conditioning_rows_{prefix}')
|
| 826 |
-
if not rows: return
|
| 827 |
-
prompts = ui_components[f'conditioning_prompts_{prefix}']
|
| 828 |
-
count_state = ui_components[f'conditioning_count_state_{prefix}']
|
| 829 |
-
add_button = ui_components[f'add_conditioning_button_{prefix}']
|
| 830 |
-
del_button = ui_components[f'delete_conditioning_button_{prefix}']
|
| 831 |
-
|
| 832 |
-
def add_row(c):
|
| 833 |
-
c += 1
|
| 834 |
-
return {
|
| 835 |
-
count_state: c,
|
| 836 |
-
rows[c - 1]: gr.update(visible=True),
|
| 837 |
-
add_button: gr.update(visible=c < MAX_CONDITIONINGS),
|
| 838 |
-
del_button: gr.update(visible=True),
|
| 839 |
-
}
|
| 840 |
-
|
| 841 |
-
def del_row(c):
|
| 842 |
-
c -= 1
|
| 843 |
-
return {
|
| 844 |
-
count_state: c,
|
| 845 |
-
rows[c]: gr.update(visible=False),
|
| 846 |
-
prompts[c]: "",
|
| 847 |
-
add_button: gr.update(visible=True),
|
| 848 |
-
del_button: gr.update(visible=c > 0),
|
| 849 |
-
}
|
| 850 |
-
|
| 851 |
-
add_outputs = [count_state, add_button, del_button] + rows
|
| 852 |
-
del_outputs = [count_state, add_button, del_button] + rows + prompts
|
| 853 |
-
add_button.click(fn=add_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 854 |
-
del_button.click(fn=del_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 855 |
-
|
| 856 |
-
def on_vae_upload(file_obj):
|
| 857 |
-
if not file_obj:
|
| 858 |
-
return gr.update(), gr.update(), None
|
| 859 |
-
|
| 860 |
-
hashed_filename = save_uploaded_file_with_hash(file_obj, VAE_DIR)
|
| 861 |
-
return hashed_filename, "File", file_obj
|
| 862 |
-
|
| 863 |
-
def on_lora_upload(file_obj):
|
| 864 |
-
if not file_obj:
|
| 865 |
-
return gr.update(), gr.update()
|
| 866 |
-
|
| 867 |
-
hashed_filename = save_uploaded_file_with_hash(file_obj, LORA_DIR)
|
| 868 |
-
return hashed_filename, "File"
|
| 869 |
-
|
| 870 |
-
def on_embedding_upload(file_obj):
|
| 871 |
-
if not file_obj:
|
| 872 |
-
return gr.update(), gr.update(), None
|
| 873 |
-
|
| 874 |
-
hashed_filename = save_uploaded_file_with_hash(file_obj, EMBEDDING_DIR)
|
| 875 |
-
return hashed_filename, "File", file_obj
|
| 876 |
-
|
| 877 |
-
|
| 878 |
-
def create_run_event(prefix: str, task_type: str):
|
| 879 |
-
run_inputs_map = {
|
| 880 |
-
'model_display_name': ui_components[f'base_model_{prefix}'],
|
| 881 |
-
'positive_prompt': ui_components.get(f'prompt_{prefix}') or ui_components.get(f'{prefix}_positive_prompt'),
|
| 882 |
-
'negative_prompt': ui_components.get(f'neg_prompt_{prefix}') or ui_components.get(f'{prefix}_negative_prompt'),
|
| 883 |
-
'seed': ui_components.get(f'seed_{prefix}') or ui_components.get(f'{prefix}_seed'),
|
| 884 |
-
'batch_size': ui_components.get(f'batch_size_{prefix}') or ui_components.get(f'{prefix}_batch_size'),
|
| 885 |
-
'guidance_scale': ui_components.get(f'cfg_{prefix}') or ui_components.get(f'{prefix}_cfg'),
|
| 886 |
-
'num_inference_steps': ui_components.get(f'steps_{prefix}') or ui_components.get(f'{prefix}_steps'),
|
| 887 |
-
'sampler': ui_components.get(f'sampler_{prefix}') or ui_components.get(f'{prefix}_sampler_name'),
|
| 888 |
-
'scheduler': ui_components.get(f'scheduler_{prefix}') or ui_components.get(f'{prefix}_scheduler'),
|
| 889 |
-
'zero_gpu_duration': ui_components.get(f'zero_gpu_{prefix}'),
|
| 890 |
-
|
| 891 |
-
'clip_skip': ui_components.get(f'clip_skip_{prefix}'),
|
| 892 |
-
'guidance': ui_components.get(f'guidance_{prefix}'),
|
| 893 |
-
'task_type': gr.State(task_type)
|
| 894 |
-
}
|
| 895 |
-
|
| 896 |
-
if task_type not in ['img2img', 'inpaint']:
|
| 897 |
-
run_inputs_map.update({
|
| 898 |
-
'width': ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width'),
|
| 899 |
-
'height': ui_components.get(f'height_{prefix}') or ui_components.get(f'{prefix}_height')
|
| 900 |
-
})
|
| 901 |
-
|
| 902 |
-
task_specific_map = {
|
| 903 |
-
'img2img': {'img2img_image': f'input_image_{prefix}', 'img2img_denoise': f'denoise_{prefix}'},
|
| 904 |
-
'inpaint': {'inpaint_image_dict': f'input_image_dict_{prefix}', 'grow_mask_by': f'grow_mask_by_{prefix}'},
|
| 905 |
-
'outpaint': {'outpaint_image': f'input_image_{prefix}', 'left': f'left_{prefix}', 'top': f'top_{prefix}', 'right': f'right_{prefix}', 'bottom': f'bottom_{prefix}', 'feathering': f'feathering_{prefix}'},
|
| 906 |
-
'hires_fix': {'hires_image': f'input_image_{prefix}', 'hires_upscaler': f'hires_upscaler_{prefix}', 'hires_scale_by': f'hires_scale_by_{prefix}', 'hires_denoise': f'denoise_{prefix}'}
|
| 907 |
-
}
|
| 908 |
-
if task_type in task_specific_map:
|
| 909 |
-
for key, comp_name in task_specific_map[task_type].items():
|
| 910 |
-
if comp_name in ui_components:
|
| 911 |
-
run_inputs_map[key] = ui_components[comp_name]
|
| 912 |
-
|
| 913 |
-
lora_data_components = ui_components.get(f'all_lora_components_flat_{prefix}', [])
|
| 914 |
-
controlnet_data_components = ui_components.get(f'all_controlnet_components_flat_{prefix}', [])
|
| 915 |
-
anima_controlnet_lllite_data_components = ui_components.get(f'all_anima_controlnet_lllite_components_flat_{prefix}', [])
|
| 916 |
-
diffsynth_controlnet_data_components = ui_components.get(f'all_diffsynth_controlnet_components_flat_{prefix}', [])
|
| 917 |
-
ipadapter_data_components = ui_components.get(f'all_ipadapter_components_flat_{prefix}', [])
|
| 918 |
-
sd3_ipadapter_data_components = ui_components.get(f'all_sd3_ipadapter_components_flat_{prefix}', [])
|
| 919 |
-
flux1_ipadapter_data_components = ui_components.get(f'all_flux1_ipadapter_components_flat_{prefix}', [])
|
| 920 |
-
style_data_components = ui_components.get(f'all_style_components_flat_{prefix}', [])
|
| 921 |
-
embedding_data_components = ui_components.get(f'all_embedding_components_flat_{prefix}', [])
|
| 922 |
-
conditioning_data_components = ui_components.get(f'all_conditioning_components_flat_{prefix}', [])
|
| 923 |
-
reference_latent_data_components = ui_components.get(f'all_reference_latent_components_flat_{prefix}', [])
|
| 924 |
-
hidream_o1_reference_data_components = ui_components.get(f'all_hidream_o1_reference_components_flat_{prefix}', [])
|
| 925 |
-
|
| 926 |
-
run_inputs_map['vae_source'] = ui_components.get(f'vae_source_{prefix}')
|
| 927 |
-
run_inputs_map['vae_id'] = ui_components.get(f'vae_id_{prefix}')
|
| 928 |
-
run_inputs_map['vae_file'] = ui_components.get(f'vae_file_{prefix}')
|
| 929 |
-
|
| 930 |
-
input_keys = list(run_inputs_map.keys())
|
| 931 |
-
input_list_flat = [v for v in run_inputs_map.values() if v is not None]
|
| 932 |
-
all_chains = [
|
| 933 |
-
lora_data_components, controlnet_data_components, anima_controlnet_lllite_data_components, diffsynth_controlnet_data_components, ipadapter_data_components,
|
| 934 |
-
sd3_ipadapter_data_components, flux1_ipadapter_data_components, style_data_components,
|
| 935 |
-
embedding_data_components, conditioning_data_components, reference_latent_data_components, hidream_o1_reference_data_components
|
| 936 |
-
]
|
| 937 |
-
for chain in all_chains:
|
| 938 |
-
if chain:
|
| 939 |
-
input_list_flat.extend(chain)
|
| 940 |
-
|
| 941 |
-
def create_ui_inputs_dict(*args):
|
| 942 |
-
valid_keys = [k for k in input_keys if run_inputs_map[k] is not None]
|
| 943 |
-
ui_dict = dict(zip(valid_keys, args[:len(valid_keys)]))
|
| 944 |
-
arg_idx = len(valid_keys)
|
| 945 |
-
|
| 946 |
-
def assign_chain_data(chain_key, components_list):
|
| 947 |
-
nonlocal arg_idx
|
| 948 |
-
if components_list:
|
| 949 |
-
ui_dict[chain_key] = list(args[arg_idx : arg_idx + len(components_list)])
|
| 950 |
-
arg_idx += len(components_list)
|
| 951 |
-
|
| 952 |
-
assign_chain_data('lora_data', lora_data_components)
|
| 953 |
-
assign_chain_data('controlnet_data', controlnet_data_components)
|
| 954 |
-
assign_chain_data('anima_controlnet_lllite_data', anima_controlnet_lllite_data_components)
|
| 955 |
-
assign_chain_data('diffsynth_controlnet_data', diffsynth_controlnet_data_components)
|
| 956 |
-
assign_chain_data('ipadapter_data', ipadapter_data_components)
|
| 957 |
-
assign_chain_data('sd3_ipadapter_chain', sd3_ipadapter_data_components)
|
| 958 |
-
assign_chain_data('flux1_ipadapter_data', flux1_ipadapter_data_components)
|
| 959 |
-
assign_chain_data('style_data', style_data_components)
|
| 960 |
-
assign_chain_data('embedding_data', embedding_data_components)
|
| 961 |
-
assign_chain_data('conditioning_data', conditioning_data_components)
|
| 962 |
-
assign_chain_data('reference_latent_data', reference_latent_data_components)
|
| 963 |
-
assign_chain_data('hidream_o1_reference_data', hidream_o1_reference_data_components)
|
| 964 |
-
|
| 965 |
-
return ui_dict
|
| 966 |
-
|
| 967 |
-
run_btn = ui_components.get(f'run_{prefix}') or ui_components.get(f'{prefix}_run_button')
|
| 968 |
-
res_gal = ui_components.get(f'result_{prefix}') or ui_components.get(f'{prefix}_output_gallery')
|
| 969 |
-
if run_btn and res_gal:
|
| 970 |
-
run_btn.click(
|
| 971 |
-
fn=lambda *args, progress=gr.Progress(track_tqdm=True): generate_image_wrapper(create_ui_inputs_dict(*args), progress),
|
| 972 |
-
inputs=input_list_flat,
|
| 973 |
-
outputs=[res_gal]
|
| 974 |
-
)
|
| 975 |
-
|
| 976 |
-
def make_update_fn(m_comp, cat_comp, cs_comp, ar_comp, width_comp, height_comp, cn_types, cn_series, cn_filepaths, anima_cn_types, anima_cn_series, anima_cn_filepaths, diffsynth_cn_types, diffsynth_cn_series, diffsynth_cn_filepaths, ipa_preset, lora_acc, cn_acc, anima_cn_acc, diffsynth_cn_acc, ipa_acc, sd3_ipa_acc, flux1_ipa_acc, style_acc, embed_acc, cond_acc, ref_latent_acc, hidream_o1_ref_acc, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp):
|
| 977 |
-
def update_fn(*args):
|
| 978 |
-
arch = args[0]
|
| 979 |
-
category = args[1]
|
| 980 |
-
current_ar = args[2] if len(args) > 2 else None
|
| 981 |
-
from core.settings import MODEL_TYPE_MAP, MODEL_MAP_CHECKPOINT, FEATURES_CONFIG, ARCHITECTURES_CONFIG, MODEL_DEFAULTS_CONFIG, ARCH_CATEGORIES_MAP
|
| 982 |
-
from utils.app_utils import get_model_generation_defaults
|
| 983 |
-
|
| 984 |
-
if arch == "ALL":
|
| 985 |
-
valid_cats = list(set(cat for cats in ARCH_CATEGORIES_MAP.values() for cat in cats))
|
| 986 |
-
else:
|
| 987 |
-
valid_cats = ARCH_CATEGORIES_MAP.get(arch, [])
|
| 988 |
-
|
| 989 |
-
cat_choices = ["ALL"] + sorted(valid_cats)
|
| 990 |
-
new_category = category if category in cat_choices else "ALL"
|
| 991 |
-
|
| 992 |
-
choices = []
|
| 993 |
-
for name, info in MODEL_MAP_CHECKPOINT.items():
|
| 994 |
-
m_arch = info[2]
|
| 995 |
-
m_cat = info[4] if len(info) > 4 else None
|
| 996 |
-
arch_match = (arch == "ALL" or m_arch == arch)
|
| 997 |
-
cat_match = (new_category == "ALL" or m_cat == new_category)
|
| 998 |
-
if arch_match and cat_match:
|
| 999 |
-
choices.append(name)
|
| 1000 |
-
|
| 1001 |
-
val = choices[0] if choices else None
|
| 1002 |
-
|
| 1003 |
-
updates = {
|
| 1004 |
-
m_comp: gr.update(choices=choices, value=val),
|
| 1005 |
-
cat_comp: gr.update(choices=cat_choices, value=new_category)
|
| 1006 |
-
}
|
| 1007 |
-
|
| 1008 |
-
m_type = MODEL_TYPE_MAP.get(val, "SDXL") if val else "SDXL"
|
| 1009 |
-
|
| 1010 |
-
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 1011 |
-
arch_model_type = architectures_dict.get(m_type, {}).get("model_type", m_type.lower().replace(" ", "").replace(".", ""))
|
| 1012 |
-
|
| 1013 |
-
arch_features = FEATURES_CONFIG.get(arch_model_type, FEATURES_CONFIG.get('default', {}))
|
| 1014 |
-
enabled_chains = arch_features.get('enabled_chains', [])
|
| 1015 |
-
|
| 1016 |
-
if lora_acc: updates[lora_acc] = gr.update(visible=('lora' in enabled_chains))
|
| 1017 |
-
if cn_acc: updates[cn_acc] = gr.update(visible=('controlnet' in enabled_chains))
|
| 1018 |
-
if anima_cn_acc: updates[anima_cn_acc] = gr.update(visible=('anima_controlnet_lllite' in enabled_chains))
|
| 1019 |
-
if diffsynth_cn_acc: updates[diffsynth_cn_acc] = gr.update(visible=('controlnet_model_patch' in enabled_chains))
|
| 1020 |
-
if ipa_acc: updates[ipa_acc] = gr.update(visible=('ipadapter' in enabled_chains))
|
| 1021 |
-
if flux1_ipa_acc: updates[flux1_ipa_acc] = gr.update(visible=('flux1_ipadapter' in enabled_chains))
|
| 1022 |
-
if sd3_ipa_acc: updates[sd3_ipa_acc] = gr.update(visible=('sd3_ipadapter' in enabled_chains))
|
| 1023 |
-
if style_acc: updates[style_acc] = gr.update(visible=('style' in enabled_chains))
|
| 1024 |
-
if embed_acc: updates[embed_acc] = gr.update(visible=('embedding' in enabled_chains))
|
| 1025 |
-
if cond_acc: updates[cond_acc] = gr.update(visible=('conditioning' in enabled_chains))
|
| 1026 |
-
if ref_latent_acc: updates[ref_latent_acc] = gr.update(visible=('reference_latent' in enabled_chains))
|
| 1027 |
-
if hidream_o1_ref_acc: updates[hidream_o1_ref_acc] = gr.update(visible=('hidream_o1_reference' in enabled_chains))
|
| 1028 |
-
|
| 1029 |
-
if cs_comp:
|
| 1030 |
-
updates[cs_comp] = gr.update(visible=(arch_model_type == "sd15"))
|
| 1031 |
-
if guidance_comp:
|
| 1032 |
-
updates[guidance_comp] = gr.update(visible=(arch_model_type == "flux1"))
|
| 1033 |
-
|
| 1034 |
-
if ar_comp:
|
| 1035 |
-
res_key = arch_model_type
|
| 1036 |
-
if res_key not in RESOLUTION_MAP:
|
| 1037 |
-
res_key = 'sdxl'
|
| 1038 |
-
res_map = RESOLUTION_MAP.get(res_key, {})
|
| 1039 |
-
target_ar = current_ar if current_ar in res_map else (list(res_map.keys())[0] if res_map else "1:1 (Square)")
|
| 1040 |
-
updates[ar_comp] = gr.update(choices=list(res_map.keys()), value=target_ar)
|
| 1041 |
-
if width_comp and height_comp and target_ar in res_map:
|
| 1042 |
-
updates[width_comp] = gr.update(value=res_map[target_ar][0])
|
| 1043 |
-
updates[height_comp] = gr.update(value=res_map[target_ar][1])
|
| 1044 |
-
|
| 1045 |
-
controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
|
| 1046 |
-
|
| 1047 |
-
all_types, default_type, series_choices, default_series, filepath = get_cn_defaults(controlnet_key)
|
| 1048 |
-
for t_comp in cn_types:
|
| 1049 |
-
updates[t_comp] = gr.update(choices=all_types, value=default_type)
|
| 1050 |
-
for s_comp in cn_series:
|
| 1051 |
-
updates[s_comp] = gr.update(choices=series_choices, value=default_series)
|
| 1052 |
-
for f_comp in cn_filepaths:
|
| 1053 |
-
updates[f_comp] = filepath
|
| 1054 |
-
|
| 1055 |
-
anima_all_types, anima_default_type, anima_series_choices, anima_default_series, anima_filepath = get_anima_cn_defaults()
|
| 1056 |
-
for t_comp in anima_cn_types:
|
| 1057 |
-
updates[t_comp] = gr.update(choices=anima_all_types, value=anima_default_type)
|
| 1058 |
-
for s_comp in anima_cn_series:
|
| 1059 |
-
updates[s_comp] = gr.update(choices=anima_series_choices, value=anima_default_series)
|
| 1060 |
-
for f_comp in anima_cn_filepaths:
|
| 1061 |
-
updates[f_comp] = anima_filepath
|
| 1062 |
-
|
| 1063 |
-
diffsynth_all_types, diffsynth_default_type, diffsynth_series_choices, diffsynth_default_series, diffsynth_filepath = get_diffsynth_cn_defaults(controlnet_key)
|
| 1064 |
-
for t_comp in diffsynth_cn_types:
|
| 1065 |
-
updates[t_comp] = gr.update(choices=diffsynth_all_types, value=diffsynth_default_type)
|
| 1066 |
-
for s_comp in diffsynth_cn_series:
|
| 1067 |
-
updates[s_comp] = gr.update(choices=diffsynth_series_choices, value=diffsynth_default_series)
|
| 1068 |
-
for f_comp in diffsynth_cn_filepaths:
|
| 1069 |
-
updates[f_comp] = diffsynth_filepath
|
| 1070 |
-
|
| 1071 |
-
if ipa_preset and (arch_model_type in ["sdxl", "sd15", "sd35"]):
|
| 1072 |
-
config = load_ipadapter_config()
|
| 1073 |
-
ipa_arch_key = "SDXL" if arch_model_type in ["sdxl", "sd35"] else "SD1.5"
|
| 1074 |
-
std_presets = config.get("IPAdapter_presets", {}).get(ipa_arch_key, [])
|
| 1075 |
-
face_presets = config.get("IPAdapter_FaceID_presets", {}).get(ipa_arch_key, [])
|
| 1076 |
-
all_ipa_presets = std_presets + face_presets
|
| 1077 |
-
default_ipa = all_ipa_presets[0] if all_ipa_presets else None
|
| 1078 |
-
updates[ipa_preset] = gr.update(choices=all_ipa_presets, value=default_ipa)
|
| 1079 |
-
|
| 1080 |
-
defaults = get_model_generation_defaults(val, arch_model_type, MODEL_DEFAULTS_CONFIG)
|
| 1081 |
-
if steps_comp: updates[steps_comp] = gr.update(value=defaults.get('steps'))
|
| 1082 |
-
if cfg_comp: updates[cfg_comp] = gr.update(value=defaults.get('cfg'))
|
| 1083 |
-
if sampler_comp: updates[sampler_comp] = gr.update(value=defaults.get('sampler_name'))
|
| 1084 |
-
if scheduler_comp: updates[scheduler_comp] = gr.update(value=defaults.get('scheduler'))
|
| 1085 |
-
if prompt_comp: updates[prompt_comp] = gr.update(value=defaults.get('positive_prompt'))
|
| 1086 |
-
if neg_prompt_comp: updates[neg_prompt_comp] = gr.update(value=defaults.get('negative_prompt'))
|
| 1087 |
-
|
| 1088 |
-
return updates
|
| 1089 |
-
return update_fn
|
| 1090 |
-
|
| 1091 |
-
def make_model_change_fn(cat_comp_ref, cs_comp, ar_comp, width_comp, height_comp, cn_types, cn_series, cn_filepaths, anima_cn_types, anima_cn_series, anima_cn_filepaths, diffsynth_cn_types, diffsynth_cn_series, diffsynth_cn_filepaths, arch_comp_ref, ipa_preset, lora_acc, cn_acc, anima_cn_acc, diffsynth_cn_acc, ipa_acc, sd3_ipa_acc, flux1_ipa_acc, style_acc, embed_acc, cond_acc, ref_latent_acc, hidream_o1_ref_acc, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp):
|
| 1092 |
-
def change_fn(*args):
|
| 1093 |
-
model_name = args[0]
|
| 1094 |
-
idx = 1
|
| 1095 |
-
current_arch = args[idx] if arch_comp_ref and idx < len(args) else None
|
| 1096 |
-
if arch_comp_ref: idx += 1
|
| 1097 |
-
current_cat = args[idx] if cat_comp_ref and idx < len(args) else None
|
| 1098 |
-
if cat_comp_ref: idx += 1
|
| 1099 |
-
current_ar = args[idx] if idx < len(args) else None
|
| 1100 |
-
from core.settings import MODEL_TYPE_MAP, FEATURES_CONFIG, ARCHITECTURES_CONFIG, MODEL_DEFAULTS_CONFIG, ARCH_CATEGORIES_MAP, MODEL_MAP_CHECKPOINT
|
| 1101 |
-
from utils.app_utils import get_model_generation_defaults
|
| 1102 |
-
m_type = MODEL_TYPE_MAP.get(model_name, "SDXL")
|
| 1103 |
-
|
| 1104 |
-
m_info = MODEL_MAP_CHECKPOINT.get(model_name)
|
| 1105 |
-
m_cat = m_info[4] if m_info and len(m_info) > 4 else None
|
| 1106 |
-
if not m_cat: m_cat = "ALL"
|
| 1107 |
-
|
| 1108 |
-
updates = {}
|
| 1109 |
-
target_arch = m_type
|
| 1110 |
-
if arch_comp_ref:
|
| 1111 |
-
if current_arch == "ALL":
|
| 1112 |
-
updates[arch_comp_ref] = gr.update()
|
| 1113 |
-
target_arch = "ALL"
|
| 1114 |
-
else:
|
| 1115 |
-
updates[arch_comp_ref] = m_type
|
| 1116 |
-
|
| 1117 |
-
if cat_comp_ref:
|
| 1118 |
-
if target_arch == "ALL":
|
| 1119 |
-
valid_cats = list(set(cat for cats in ARCH_CATEGORIES_MAP.values() for cat in cats))
|
| 1120 |
-
else:
|
| 1121 |
-
valid_cats = ARCH_CATEGORIES_MAP.get(target_arch, [])
|
| 1122 |
-
cat_choices = ["ALL"] + sorted(valid_cats)
|
| 1123 |
-
|
| 1124 |
-
if current_cat == "ALL":
|
| 1125 |
-
updates[cat_comp_ref] = gr.update(choices=cat_choices)
|
| 1126 |
-
else:
|
| 1127 |
-
updates[cat_comp_ref] = gr.update(choices=cat_choices, value=m_cat)
|
| 1128 |
-
|
| 1129 |
-
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 1130 |
-
arch_model_type = architectures_dict.get(m_type, {}).get("model_type", m_type.lower().replace(" ", "").replace(".", ""))
|
| 1131 |
-
|
| 1132 |
-
arch_features = FEATURES_CONFIG.get(arch_model_type, FEATURES_CONFIG.get('default', {}))
|
| 1133 |
-
enabled_chains = arch_features.get('enabled_chains', [])
|
| 1134 |
-
|
| 1135 |
-
if lora_acc: updates[lora_acc] = gr.update(visible=('lora' in enabled_chains))
|
| 1136 |
-
if cn_acc: updates[cn_acc] = gr.update(visible=('controlnet' in enabled_chains))
|
| 1137 |
-
if anima_cn_acc: updates[anima_cn_acc] = gr.update(visible=('anima_controlnet_lllite' in enabled_chains))
|
| 1138 |
-
if diffsynth_cn_acc: updates[diffsynth_cn_acc] = gr.update(visible=('controlnet_model_patch' in enabled_chains))
|
| 1139 |
-
if ipa_acc: updates[ipa_acc] = gr.update(visible=('ipadapter' in enabled_chains))
|
| 1140 |
-
if flux1_ipa_acc: updates[flux1_ipa_acc] = gr.update(visible=('flux1_ipadapter' in enabled_chains))
|
| 1141 |
-
if sd3_ipa_acc: updates[sd3_ipa_acc] = gr.update(visible=('sd3_ipadapter' in enabled_chains))
|
| 1142 |
-
if style_acc: updates[style_acc] = gr.update(visible=('style' in enabled_chains))
|
| 1143 |
-
if embed_acc: updates[embed_acc] = gr.update(visible=('embedding' in enabled_chains))
|
| 1144 |
-
if cond_acc: updates[cond_acc] = gr.update(visible=('conditioning' in enabled_chains))
|
| 1145 |
-
if ref_latent_acc: updates[ref_latent_acc] = gr.update(visible=('reference_latent' in enabled_chains))
|
| 1146 |
-
if hidream_o1_ref_acc: updates[hidream_o1_ref_acc] = gr.update(visible=('hidream_o1_reference' in enabled_chains))
|
| 1147 |
-
|
| 1148 |
-
if cs_comp:
|
| 1149 |
-
updates[cs_comp] = gr.update(visible=(arch_model_type == "sd15"))
|
| 1150 |
-
if guidance_comp:
|
| 1151 |
-
updates[guidance_comp] = gr.update(visible=(arch_model_type == "flux1"))
|
| 1152 |
-
|
| 1153 |
-
if ar_comp:
|
| 1154 |
-
res_key = arch_model_type
|
| 1155 |
-
if res_key not in RESOLUTION_MAP:
|
| 1156 |
-
res_key = 'sdxl'
|
| 1157 |
-
res_map = RESOLUTION_MAP.get(res_key, {})
|
| 1158 |
-
target_ar = current_ar if current_ar in res_map else (list(res_map.keys())[0] if res_map else "1:1 (Square)")
|
| 1159 |
-
updates[ar_comp] = gr.update(choices=list(res_map.keys()), value=target_ar)
|
| 1160 |
-
if width_comp and height_comp and target_ar in res_map:
|
| 1161 |
-
updates[width_comp] = gr.update(value=res_map[target_ar][0])
|
| 1162 |
-
updates[height_comp] = gr.update(value=res_map[target_ar][1])
|
| 1163 |
-
|
| 1164 |
-
controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
|
| 1165 |
-
|
| 1166 |
-
all_types, default_type, series_choices, default_series, filepath = get_cn_defaults(controlnet_key)
|
| 1167 |
-
for t_comp in cn_types:
|
| 1168 |
-
updates[t_comp] = gr.update(choices=all_types, value=default_type)
|
| 1169 |
-
for s_comp in cn_series:
|
| 1170 |
-
updates[s_comp] = gr.update(choices=series_choices, value=default_series)
|
| 1171 |
-
for f_comp in cn_filepaths:
|
| 1172 |
-
updates[f_comp] = filepath
|
| 1173 |
-
|
| 1174 |
-
anima_all_types, anima_default_type, anima_series_choices, anima_default_series, anima_filepath = get_anima_cn_defaults()
|
| 1175 |
-
for t_comp in anima_cn_types:
|
| 1176 |
-
updates[t_comp] = gr.update(choices=anima_all_types, value=anima_default_type)
|
| 1177 |
-
for s_comp in anima_cn_series:
|
| 1178 |
-
updates[s_comp] = gr.update(choices=anima_series_choices, value=anima_default_series)
|
| 1179 |
-
for f_comp in anima_cn_filepaths:
|
| 1180 |
-
updates[f_comp] = anima_filepath
|
| 1181 |
-
|
| 1182 |
-
diffsynth_all_types, diffsynth_default_type, diffsynth_series_choices, diffsynth_default_series, diffsynth_filepath = get_diffsynth_cn_defaults(controlnet_key)
|
| 1183 |
-
for t_comp in diffsynth_cn_types:
|
| 1184 |
-
updates[t_comp] = gr.update(choices=diffsynth_all_types, value=diffsynth_default_type)
|
| 1185 |
-
for s_comp in diffsynth_cn_series:
|
| 1186 |
-
updates[s_comp] = gr.update(choices=diffsynth_series_choices, value=diffsynth_default_series)
|
| 1187 |
-
for f_comp in diffsynth_cn_filepaths:
|
| 1188 |
-
updates[f_comp] = diffsynth_filepath
|
| 1189 |
-
|
| 1190 |
-
if ipa_preset and (arch_model_type in ["sdxl", "sd15", "sd35"]):
|
| 1191 |
-
config = load_ipadapter_config()
|
| 1192 |
-
ipa_arch_key = "SDXL" if arch_model_type in ["sdxl", "sd35"] else "SD1.5"
|
| 1193 |
-
std_presets = config.get("IPAdapter_presets", {}).get(ipa_arch_key, [])
|
| 1194 |
-
face_presets = config.get("IPAdapter_FaceID_presets", {}).get(ipa_arch_key, [])
|
| 1195 |
-
all_ipa_presets = std_presets + face_presets
|
| 1196 |
-
default_ipa = all_ipa_presets[0] if all_ipa_presets else None
|
| 1197 |
-
updates[ipa_preset] = gr.update(choices=all_ipa_presets, value=default_ipa)
|
| 1198 |
-
|
| 1199 |
-
defaults = get_model_generation_defaults(model_name, arch_model_type, MODEL_DEFAULTS_CONFIG)
|
| 1200 |
-
if steps_comp: updates[steps_comp] = gr.update(value=defaults.get('steps'))
|
| 1201 |
-
if cfg_comp: updates[cfg_comp] = gr.update(value=defaults.get('cfg'))
|
| 1202 |
-
if sampler_comp: updates[sampler_comp] = gr.update(value=defaults.get('sampler_name'))
|
| 1203 |
-
if scheduler_comp: updates[scheduler_comp] = gr.update(value=defaults.get('scheduler'))
|
| 1204 |
-
if prompt_comp: updates[prompt_comp] = gr.update(value=defaults.get('positive_prompt'))
|
| 1205 |
-
if neg_prompt_comp: updates[neg_prompt_comp] = gr.update(value=defaults.get('negative_prompt'))
|
| 1206 |
-
|
| 1207 |
-
return updates
|
| 1208 |
-
return change_fn
|
| 1209 |
-
|
| 1210 |
-
|
| 1211 |
-
for prefix, task_type in [
|
| 1212 |
-
("txt2img", "txt2img"), ("img2img", "img2img"), ("inpaint", "inpaint"),
|
| 1213 |
-
("outpaint", "outpaint"), ("hires_fix", "hires_fix"),
|
| 1214 |
-
]:
|
| 1215 |
-
|
| 1216 |
-
arch_comp = ui_components.get(f'model_arch_{prefix}')
|
| 1217 |
-
cat_comp = ui_components.get(f'model_cat_{prefix}')
|
| 1218 |
-
model_comp = ui_components.get(f'base_model_{prefix}')
|
| 1219 |
-
clip_skip_comp = ui_components.get(f'clip_skip_{prefix}') or ui_components.get(f'{prefix}_clip_skip')
|
| 1220 |
-
guidance_comp = ui_components.get(f'guidance_{prefix}') or ui_components.get(f'{prefix}_guidance')
|
| 1221 |
-
aspect_ratio_comp = ui_components.get(f'aspect_ratio_{prefix}') or ui_components.get(f'{prefix}_aspect_ratio_dropdown')
|
| 1222 |
-
width_comp = ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width')
|
| 1223 |
-
height_comp = ui_components.get(f'height_{prefix}') or ui_components.get(f'{prefix}_height')
|
| 1224 |
-
|
| 1225 |
-
cn_types_list = ui_components.get(f'controlnet_types_{prefix}', [])
|
| 1226 |
-
cn_series_list = ui_components.get(f'controlnet_series_{prefix}', [])
|
| 1227 |
-
cn_filepaths_list = ui_components.get(f'controlnet_filepaths_{prefix}', [])
|
| 1228 |
-
|
| 1229 |
-
anima_cn_types_list = ui_components.get(f'anima_controlnet_lllite_types_{prefix}', [])
|
| 1230 |
-
anima_cn_series_list = ui_components.get(f'anima_controlnet_lllite_series_{prefix}', [])
|
| 1231 |
-
anima_cn_filepaths_list = ui_components.get(f'anima_controlnet_lllite_filepaths_{prefix}', [])
|
| 1232 |
-
|
| 1233 |
-
diffsynth_cn_types_list = ui_components.get(f'diffsynth_controlnet_types_{prefix}', [])
|
| 1234 |
-
diffsynth_cn_series_list = ui_components.get(f'diffsynth_controlnet_series_{prefix}', [])
|
| 1235 |
-
diffsynth_cn_filepaths_list = ui_components.get(f'diffsynth_controlnet_filepaths_{prefix}', [])
|
| 1236 |
-
|
| 1237 |
-
lora_accordion = ui_components.get(f'lora_accordion_{prefix}')
|
| 1238 |
-
cn_accordion = ui_components.get(f'controlnet_accordion_{prefix}')
|
| 1239 |
-
anima_cn_accordion = ui_components.get(f'anima_controlnet_lllite_accordion_{prefix}')
|
| 1240 |
-
diffsynth_cn_accordion = ui_components.get(f'diffsynth_controlnet_accordion_{prefix}')
|
| 1241 |
-
ipa_accordion = ui_components.get(f'ipadapter_accordion_{prefix}')
|
| 1242 |
-
sd3_ipa_accordion = ui_components.get(f'sd3_ipadapter_accordion_{prefix}')
|
| 1243 |
-
flux1_ipa_accordion = ui_components.get(f'flux1_ipadapter_accordion_{prefix}')
|
| 1244 |
-
style_accordion = ui_components.get(f'style_accordion_{prefix}')
|
| 1245 |
-
embedding_accordion = ui_components.get(f'embedding_accordion_{prefix}')
|
| 1246 |
-
conditioning_accordion = ui_components.get(f'conditioning_accordion_{prefix}')
|
| 1247 |
-
ref_latent_accordion = ui_components.get(f'reference_latent_accordion_{prefix}')
|
| 1248 |
-
hidream_o1_ref_accordion = ui_components.get(f'hidream_o1_reference_accordion_{prefix}')
|
| 1249 |
-
|
| 1250 |
-
ipa_preset_list = ui_components.get(f'ipadapter_final_preset_{prefix}')
|
| 1251 |
-
|
| 1252 |
-
prompt_comp = ui_components.get(f'prompt_{prefix}') or ui_components.get(f'{prefix}_positive_prompt')
|
| 1253 |
-
neg_prompt_comp = ui_components.get(f'neg_prompt_{prefix}') or ui_components.get(f'{prefix}_negative_prompt')
|
| 1254 |
-
steps_comp = ui_components.get(f'steps_{prefix}') or ui_components.get(f'{prefix}_steps')
|
| 1255 |
-
cfg_comp = ui_components.get(f'cfg_{prefix}') or ui_components.get(f'{prefix}_cfg')
|
| 1256 |
-
sampler_comp = ui_components.get(f'sampler_{prefix}') or ui_components.get(f'{prefix}_sampler_name')
|
| 1257 |
-
scheduler_comp = ui_components.get(f'scheduler_{prefix}') or ui_components.get(f'{prefix}_scheduler')
|
| 1258 |
-
|
| 1259 |
-
extra_comps = [prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp, width_comp, height_comp]
|
| 1260 |
-
valid_extra_comps = [c for c in extra_comps if c is not None]
|
| 1261 |
-
|
| 1262 |
-
if arch_comp and cat_comp and model_comp:
|
| 1263 |
-
outputs = [model_comp, cat_comp]
|
| 1264 |
-
if clip_skip_comp: outputs.append(clip_skip_comp)
|
| 1265 |
-
if guidance_comp: outputs.append(guidance_comp)
|
| 1266 |
-
if aspect_ratio_comp: outputs.append(aspect_ratio_comp)
|
| 1267 |
-
outputs.extend(cn_types_list + cn_series_list + cn_filepaths_list)
|
| 1268 |
-
outputs.extend(anima_cn_types_list + anima_cn_series_list + anima_cn_filepaths_list)
|
| 1269 |
-
outputs.extend(diffsynth_cn_types_list + diffsynth_cn_series_list + diffsynth_cn_filepaths_list)
|
| 1270 |
-
if lora_accordion: outputs.append(lora_accordion)
|
| 1271 |
-
if cn_accordion: outputs.append(cn_accordion)
|
| 1272 |
-
if anima_cn_accordion: outputs.append(anima_cn_accordion)
|
| 1273 |
-
if diffsynth_cn_accordion: outputs.append(diffsynth_cn_accordion)
|
| 1274 |
-
if ipa_accordion: outputs.append(ipa_accordion)
|
| 1275 |
-
if sd3_ipa_accordion: outputs.append(sd3_ipa_accordion)
|
| 1276 |
-
if flux1_ipa_accordion: outputs.append(flux1_ipa_accordion)
|
| 1277 |
-
if style_accordion: outputs.append(style_accordion)
|
| 1278 |
-
if embedding_accordion: outputs.append(embedding_accordion)
|
| 1279 |
-
if conditioning_accordion: outputs.append(conditioning_accordion)
|
| 1280 |
-
if ref_latent_accordion: outputs.append(ref_latent_accordion)
|
| 1281 |
-
if hidream_o1_ref_accordion: outputs.append(hidream_o1_ref_accordion)
|
| 1282 |
-
if ipa_preset_list: outputs.append(ipa_preset_list)
|
| 1283 |
-
|
| 1284 |
-
outputs.extend(valid_extra_comps)
|
| 1285 |
-
|
| 1286 |
-
update_fn = make_update_fn(
|
| 1287 |
-
model_comp, cat_comp, clip_skip_comp, aspect_ratio_comp, width_comp, height_comp,
|
| 1288 |
-
cn_types_list, cn_series_list, cn_filepaths_list,
|
| 1289 |
-
anima_cn_types_list, anima_cn_series_list, anima_cn_filepaths_list,
|
| 1290 |
-
diffsynth_cn_types_list, diffsynth_cn_series_list, diffsynth_cn_filepaths_list,
|
| 1291 |
-
ipa_preset_list, lora_accordion, cn_accordion, anima_cn_accordion, diffsynth_cn_accordion, ipa_accordion, sd3_ipa_accordion, flux1_ipa_accordion, style_accordion, embedding_accordion, conditioning_accordion,
|
| 1292 |
-
ref_latent_accordion, hidream_o1_ref_accordion, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp
|
| 1293 |
-
)
|
| 1294 |
-
inputs = [arch_comp, cat_comp]
|
| 1295 |
-
if aspect_ratio_comp:
|
| 1296 |
-
inputs.append(aspect_ratio_comp)
|
| 1297 |
-
arch_comp.change(fn=update_fn, inputs=inputs, outputs=outputs)
|
| 1298 |
-
cat_comp.change(fn=update_fn, inputs=inputs, outputs=outputs)
|
| 1299 |
-
|
| 1300 |
-
if model_comp:
|
| 1301 |
-
outputs2 = []
|
| 1302 |
-
if arch_comp: outputs2.append(arch_comp)
|
| 1303 |
-
if cat_comp: outputs2.append(cat_comp)
|
| 1304 |
-
if clip_skip_comp: outputs2.append(clip_skip_comp)
|
| 1305 |
-
if guidance_comp: outputs2.append(guidance_comp)
|
| 1306 |
-
if aspect_ratio_comp: outputs2.append(aspect_ratio_comp)
|
| 1307 |
-
outputs2.extend(cn_types_list + cn_series_list + cn_filepaths_list)
|
| 1308 |
-
outputs2.extend(anima_cn_types_list + anima_cn_series_list + anima_cn_filepaths_list)
|
| 1309 |
-
outputs2.extend(diffsynth_cn_types_list + diffsynth_cn_series_list + diffsynth_cn_filepaths_list)
|
| 1310 |
-
if lora_accordion: outputs2.append(lora_accordion)
|
| 1311 |
-
if cn_accordion: outputs2.append(cn_accordion)
|
| 1312 |
-
if anima_cn_accordion: outputs2.append(anima_cn_accordion)
|
| 1313 |
-
if diffsynth_cn_accordion: outputs2.append(diffsynth_cn_accordion)
|
| 1314 |
-
if ipa_accordion: outputs2.append(ipa_accordion)
|
| 1315 |
-
if sd3_ipa_accordion: outputs2.append(sd3_ipa_accordion)
|
| 1316 |
-
if flux1_ipa_accordion: outputs2.append(flux1_ipa_accordion)
|
| 1317 |
-
if style_accordion: outputs2.append(style_accordion)
|
| 1318 |
-
if embedding_accordion: outputs2.append(embedding_accordion)
|
| 1319 |
-
if conditioning_accordion: outputs2.append(conditioning_accordion)
|
| 1320 |
-
if ref_latent_accordion: outputs2.append(ref_latent_accordion)
|
| 1321 |
-
if hidream_o1_ref_accordion: outputs2.append(hidream_o1_ref_accordion)
|
| 1322 |
-
if ipa_preset_list: outputs2.append(ipa_preset_list)
|
| 1323 |
-
|
| 1324 |
-
outputs2.extend(valid_extra_comps)
|
| 1325 |
-
|
| 1326 |
-
if outputs2:
|
| 1327 |
-
inputs2 = [model_comp]
|
| 1328 |
-
if arch_comp: inputs2.append(arch_comp)
|
| 1329 |
-
if cat_comp: inputs2.append(cat_comp)
|
| 1330 |
-
if aspect_ratio_comp: inputs2.append(aspect_ratio_comp)
|
| 1331 |
-
change_fn = make_model_change_fn(
|
| 1332 |
-
cat_comp, clip_skip_comp, aspect_ratio_comp, width_comp, height_comp,
|
| 1333 |
-
cn_types_list, cn_series_list, cn_filepaths_list,
|
| 1334 |
-
anima_cn_types_list, anima_cn_series_list, anima_cn_filepaths_list,
|
| 1335 |
-
diffsynth_cn_types_list, diffsynth_cn_series_list, diffsynth_cn_filepaths_list,
|
| 1336 |
-
arch_comp, ipa_preset_list, lora_accordion, cn_accordion, anima_cn_accordion, diffsynth_cn_accordion, ipa_accordion, sd3_ipa_accordion, flux1_ipa_accordion, style_accordion, embedding_accordion, conditioning_accordion,
|
| 1337 |
-
ref_latent_accordion, hidream_o1_ref_accordion, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp
|
| 1338 |
-
)
|
| 1339 |
-
model_comp.change(fn=change_fn, inputs=inputs2, outputs=outputs2)
|
| 1340 |
-
|
| 1341 |
-
create_lora_event_handlers(prefix)
|
| 1342 |
-
create_controlnet_event_handlers(prefix)
|
| 1343 |
-
create_anima_controlnet_lllite_event_handlers(prefix)
|
| 1344 |
-
create_diffsynth_controlnet_event_handlers(prefix)
|
| 1345 |
-
create_ipadapter_event_handlers(prefix)
|
| 1346 |
-
create_embedding_event_handlers(prefix)
|
| 1347 |
-
create_conditioning_event_handlers(prefix)
|
| 1348 |
-
create_flux1_ipadapter_event_handlers(prefix)
|
| 1349 |
-
create_sd3_ipadapter_event_handlers(prefix)
|
| 1350 |
-
create_style_event_handlers(prefix)
|
| 1351 |
-
create_reference_latent_event_handlers(prefix)
|
| 1352 |
-
create_hidream_o1_reference_event_handlers(prefix)
|
| 1353 |
-
create_run_event(prefix, task_type)
|
| 1354 |
-
|
| 1355 |
-
|
| 1356 |
-
if 'view_mode_inpaint' in ui_components:
|
| 1357 |
-
def toggle_inpaint_fullscreen_view(view_mode):
|
| 1358 |
-
is_fullscreen = (view_mode == "Fullscreen View")
|
| 1359 |
-
other_elements_visible = not is_fullscreen
|
| 1360 |
-
editor_height = 800 if is_fullscreen else 272
|
| 1361 |
-
|
| 1362 |
-
updates = {
|
| 1363 |
-
ui_components['prompts_column_inpaint']: gr.update(visible=other_elements_visible),
|
| 1364 |
-
ui_components['params_and_gallery_row_inpaint']: gr.update(visible=other_elements_visible),
|
| 1365 |
-
ui_components['accordion_wrapper_inpaint']: gr.update(visible=other_elements_visible),
|
| 1366 |
-
ui_components['input_image_dict_inpaint']: gr.update(height=editor_height),
|
| 1367 |
-
}
|
| 1368 |
-
|
| 1369 |
-
model_and_run_rows = ui_components.get('model_and_run_row_inpaint', [])
|
| 1370 |
-
for row in model_and_run_rows:
|
| 1371 |
-
updates[row] = gr.update(visible=other_elements_visible)
|
| 1372 |
-
|
| 1373 |
-
return updates
|
| 1374 |
-
|
| 1375 |
-
output_components = []
|
| 1376 |
-
model_and_run_rows = ui_components.get('model_and_run_row_inpaint', [])
|
| 1377 |
-
if isinstance(model_and_run_rows, list):
|
| 1378 |
-
output_components.extend(model_and_run_rows)
|
| 1379 |
-
else:
|
| 1380 |
-
output_components.append(model_and_run_rows)
|
| 1381 |
-
|
| 1382 |
-
output_components.extend([
|
| 1383 |
-
ui_components['prompts_column_inpaint'],
|
| 1384 |
-
ui_components['params_and_gallery_row_inpaint'],
|
| 1385 |
-
ui_components['accordion_wrapper_inpaint'],
|
| 1386 |
-
ui_components['input_image_dict_inpaint']
|
| 1387 |
-
])
|
| 1388 |
-
|
| 1389 |
-
ui_components['view_mode_inpaint'].change(
|
| 1390 |
-
fn=toggle_inpaint_fullscreen_view,
|
| 1391 |
-
inputs=[ui_components['view_mode_inpaint']],
|
| 1392 |
-
outputs=output_components,
|
| 1393 |
-
show_progress=False
|
| 1394 |
-
)
|
| 1395 |
-
|
| 1396 |
-
def initialize_all_cn_dropdowns():
|
| 1397 |
-
from core.settings import MODEL_TYPE_MAP, MODEL_MAP_CHECKPOINT, ARCHITECTURES_CONFIG
|
| 1398 |
-
default_model_name = list(MODEL_MAP_CHECKPOINT.keys())[0] if MODEL_MAP_CHECKPOINT else None
|
| 1399 |
-
default_m_type = MODEL_TYPE_MAP.get(default_model_name, "SDXL") if default_model_name else "SDXL"
|
| 1400 |
-
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 1401 |
-
controlnet_key = architectures_dict.get(default_m_type, {}).get("controlnet_key", default_m_type)
|
| 1402 |
-
|
| 1403 |
-
all_types, default_type, series_choices, default_series, filepath = get_cn_defaults(controlnet_key)
|
| 1404 |
-
anima_all_types, anima_default_type, anima_series_choices, anima_default_series, anima_filepath = get_anima_cn_defaults()
|
| 1405 |
-
diffsynth_all_types, diffsynth_default_type, diffsynth_series_choices, diffsynth_default_series, diffsynth_filepath = get_diffsynth_cn_defaults(controlnet_key)
|
| 1406 |
-
|
| 1407 |
-
updates = {}
|
| 1408 |
-
for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]:
|
| 1409 |
-
if f'controlnet_types_{prefix}' in ui_components:
|
| 1410 |
-
for type_dd in ui_components[f'controlnet_types_{prefix}']:
|
| 1411 |
-
updates[type_dd] = gr.update(choices=all_types, value=default_type)
|
| 1412 |
-
for series_dd in ui_components[f'controlnet_series_{prefix}']:
|
| 1413 |
-
updates[series_dd] = gr.update(choices=series_choices, value=default_series)
|
| 1414 |
-
for filepath_state in ui_components[f'controlnet_filepaths_{prefix}']:
|
| 1415 |
-
updates[filepath_state] = filepath
|
| 1416 |
-
|
| 1417 |
-
if f'anima_controlnet_lllite_types_{prefix}' in ui_components:
|
| 1418 |
-
for type_dd in ui_components[f'anima_controlnet_lllite_types_{prefix}']:
|
| 1419 |
-
updates[type_dd] = gr.update(choices=anima_all_types, value=anima_default_type)
|
| 1420 |
-
for series_dd in ui_components[f'anima_controlnet_lllite_series_{prefix}']:
|
| 1421 |
-
updates[series_dd] = gr.update(choices=anima_series_choices, value=anima_default_series)
|
| 1422 |
-
for filepath_state in ui_components[f'anima_controlnet_lllite_filepaths_{prefix}']:
|
| 1423 |
-
updates[filepath_state] = anima_filepath
|
| 1424 |
-
|
| 1425 |
-
if f'diffsynth_controlnet_types_{prefix}' in ui_components:
|
| 1426 |
-
for type_dd in ui_components[f'diffsynth_controlnet_types_{prefix}']:
|
| 1427 |
-
updates[type_dd] = gr.update(choices=diffsynth_all_types, value=diffsynth_default_type)
|
| 1428 |
-
for series_dd in ui_components[f'diffsynth_controlnet_series_{prefix}']:
|
| 1429 |
-
updates[series_dd] = gr.update(choices=diffsynth_series_choices, value=diffsynth_default_series)
|
| 1430 |
-
for filepath_state in ui_components[f'diffsynth_controlnet_filepaths_{prefix}']:
|
| 1431 |
-
updates[filepath_state] = diffsynth_filepath
|
| 1432 |
-
|
| 1433 |
-
return updates
|
| 1434 |
-
|
| 1435 |
-
def initialize_all_ipa_dropdowns():
|
| 1436 |
-
config = load_ipadapter_config()
|
| 1437 |
-
if not config: return {}
|
| 1438 |
-
|
| 1439 |
-
from core.settings import MODEL_TYPE_MAP, MODEL_MAP_CHECKPOINT, ARCHITECTURES_CONFIG
|
| 1440 |
-
default_model_name = list(MODEL_MAP_CHECKPOINT.keys())[0] if MODEL_MAP_CHECKPOINT else None
|
| 1441 |
-
default_m_type = MODEL_TYPE_MAP.get(default_model_name, "SDXL") if default_model_name else "SDXL"
|
| 1442 |
-
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 1443 |
-
arch_model_type = architectures_dict.get(default_m_type, {}).get("model_type", default_m_type.lower().replace(" ", "").replace(".", ""))
|
| 1444 |
-
ipa_arch_key = "SDXL" if arch_model_type in ["sdxl", "sd35"] else "SD1.5"
|
| 1445 |
-
|
| 1446 |
-
unified_presets = config.get("IPAdapter_presets", {}).get(ipa_arch_key, [])
|
| 1447 |
-
faceid_presets = config.get("IPAdapter_FaceID_presets", {}).get(ipa_arch_key, [])
|
| 1448 |
-
|
| 1449 |
-
all_presets = unified_presets + faceid_presets
|
| 1450 |
-
default_preset = all_presets[0] if all_presets else None
|
| 1451 |
-
is_faceid_default = default_preset in faceid_presets
|
| 1452 |
-
|
| 1453 |
-
lora_strength_update = gr.update(visible=is_faceid_default)
|
| 1454 |
-
|
| 1455 |
-
updates = {}
|
| 1456 |
-
for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]:
|
| 1457 |
-
if f'ipadapter_final_preset_{prefix}' in ui_components:
|
| 1458 |
-
for lora_strength_slider in ui_components[f'ipadapter_lora_strengths_{prefix}']:
|
| 1459 |
-
updates[lora_strength_slider] = lora_strength_update
|
| 1460 |
-
updates[ui_components[f'ipadapter_final_preset_{prefix}']] = gr.update(choices=all_presets, value=default_preset)
|
| 1461 |
-
updates[ui_components[f'ipadapter_final_lora_strength_{prefix}']] = lora_strength_update
|
| 1462 |
-
return updates
|
| 1463 |
-
|
| 1464 |
-
def run_on_load():
|
| 1465 |
-
cn_updates = initialize_all_cn_dropdowns()
|
| 1466 |
-
ipa_updates = initialize_all_ipa_dropdowns()
|
| 1467 |
-
|
| 1468 |
-
all_updates = {**cn_updates, **ipa_updates}
|
| 1469 |
-
|
| 1470 |
-
return all_updates
|
| 1471 |
-
|
| 1472 |
-
all_load_outputs = []
|
| 1473 |
-
for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]:
|
| 1474 |
-
if f'controlnet_types_{prefix}' in ui_components:
|
| 1475 |
-
all_load_outputs.extend(ui_components[f'controlnet_types_{prefix}'])
|
| 1476 |
-
all_load_outputs.extend(ui_components[f'controlnet_series_{prefix}'])
|
| 1477 |
-
all_load_outputs.extend(ui_components[f'controlnet_filepaths_{prefix}'])
|
| 1478 |
-
if f'anima_controlnet_lllite_types_{prefix}' in ui_components:
|
| 1479 |
-
all_load_outputs.extend(ui_components[f'anima_controlnet_lllite_types_{prefix}'])
|
| 1480 |
-
all_load_outputs.extend(ui_components[f'anima_controlnet_lllite_series_{prefix}'])
|
| 1481 |
-
all_load_outputs.extend(ui_components[f'anima_controlnet_lllite_filepaths_{prefix}'])
|
| 1482 |
-
if f'diffsynth_controlnet_types_{prefix}' in ui_components:
|
| 1483 |
-
all_load_outputs.extend(ui_components[f'diffsynth_controlnet_types_{prefix}'])
|
| 1484 |
-
all_load_outputs.extend(ui_components[f'diffsynth_controlnet_series_{prefix}'])
|
| 1485 |
-
all_load_outputs.extend(ui_components[f'diffsynth_controlnet_filepaths_{prefix}'])
|
| 1486 |
-
if f'ipadapter_final_preset_{prefix}' in ui_components:
|
| 1487 |
-
all_load_outputs.extend(ui_components[f'ipadapter_lora_strengths_{prefix}'])
|
| 1488 |
-
all_load_outputs.append(ui_components[f'ipadapter_final_preset_{prefix}'])
|
| 1489 |
-
all_load_outputs.append(ui_components[f'ipadapter_final_lora_strength_{prefix}'])
|
| 1490 |
-
|
| 1491 |
-
if all_load_outputs:
|
| 1492 |
-
demo.load(
|
| 1493 |
-
fn=run_on_load,
|
| 1494 |
-
outputs=all_load_outputs
|
| 1495 |
-
)
|
| 1496 |
-
|
| 1497 |
-
def on_aspect_ratio_change(ratio_key, model_display_name):
|
| 1498 |
-
from core.settings import MODEL_TYPE_MAP, ARCHITECTURES_CONFIG
|
| 1499 |
-
m_type = MODEL_TYPE_MAP.get(model_display_name, 'SDXL')
|
| 1500 |
-
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 1501 |
-
arch_model_type = architectures_dict.get(m_type, {}).get("model_type", m_type.lower().replace(" ", "").replace(".", ""))
|
| 1502 |
-
|
| 1503 |
-
res_map = RESOLUTION_MAP.get(arch_model_type, RESOLUTION_MAP.get("sdxl", {}))
|
| 1504 |
-
w, h = res_map.get(ratio_key, (1024, 1024))
|
| 1505 |
-
return w, h
|
| 1506 |
-
|
| 1507 |
-
for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]:
|
| 1508 |
-
aspect_ratio_dropdown = ui_components.get(f'aspect_ratio_{prefix}') or ui_components.get(f'{prefix}_aspect_ratio_dropdown')
|
| 1509 |
-
width_component = ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width')
|
| 1510 |
-
height_component = ui_components.get(f'height_{prefix}') or ui_components.get(f'{prefix}_height')
|
| 1511 |
-
model_dropdown = ui_components.get(f'base_model_{prefix}')
|
| 1512 |
-
if aspect_ratio_dropdown and width_component and height_component and model_dropdown:
|
| 1513 |
-
aspect_ratio_dropdown.change(fn=on_aspect_ratio_change, inputs=[aspect_ratio_dropdown, model_dropdown], outputs=[width_component, height_component], show_progress=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ui/events/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .main import attach_event_handlers
|
| 2 |
+
from .config_loaders import (
|
| 3 |
+
load_controlnet_config,
|
| 4 |
+
get_cn_defaults,
|
| 5 |
+
load_anima_controlnet_lllite_config,
|
| 6 |
+
get_anima_cn_defaults,
|
| 7 |
+
load_diffsynth_controlnet_config,
|
| 8 |
+
get_diffsynth_cn_defaults,
|
| 9 |
+
load_ipadapter_config
|
| 10 |
+
)
|
ui/events/chain_handlers.py
ADDED
|
@@ -0,0 +1,680 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from core.settings import VAE_DIR, LORA_DIR, EMBEDDING_DIR, ARCHITECTURES_CONFIG
|
| 3 |
+
from utils.app_utils import save_uploaded_file_with_hash
|
| 4 |
+
from ui.shared.ui_components import (
|
| 5 |
+
MAX_CONTROLNETS,
|
| 6 |
+
MAX_IPADAPTERS,
|
| 7 |
+
MAX_EMBEDDINGS,
|
| 8 |
+
MAX_CONDITIONINGS,
|
| 9 |
+
MAX_LORAS
|
| 10 |
+
)
|
| 11 |
+
from .config_loaders import (
|
| 12 |
+
load_controlnet_config,
|
| 13 |
+
load_anima_controlnet_lllite_config,
|
| 14 |
+
load_diffsynth_controlnet_config,
|
| 15 |
+
load_ipadapter_config
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
def on_vae_upload(file_obj):
|
| 19 |
+
if not file_obj:
|
| 20 |
+
return gr.update(), gr.update(), None
|
| 21 |
+
|
| 22 |
+
hashed_filename = save_uploaded_file_with_hash(file_obj, VAE_DIR)
|
| 23 |
+
return hashed_filename, "File", file_obj
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def on_lora_upload(file_obj):
|
| 27 |
+
if not file_obj:
|
| 28 |
+
return gr.update(), gr.update()
|
| 29 |
+
|
| 30 |
+
hashed_filename = save_uploaded_file_with_hash(file_obj, LORA_DIR)
|
| 31 |
+
return hashed_filename, "File"
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def on_embedding_upload(file_obj):
|
| 35 |
+
if not file_obj:
|
| 36 |
+
return gr.update(), gr.update(), None
|
| 37 |
+
|
| 38 |
+
hashed_filename = save_uploaded_file_with_hash(file_obj, EMBEDDING_DIR)
|
| 39 |
+
return hashed_filename, "File", file_obj
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def create_lora_event_handlers(prefix, ui_components):
|
| 43 |
+
lora_rows = ui_components.get(f'lora_rows_{prefix}')
|
| 44 |
+
if not lora_rows: return
|
| 45 |
+
lora_ids = ui_components[f'lora_ids_{prefix}']
|
| 46 |
+
lora_scales = ui_components[f'lora_scales_{prefix}']
|
| 47 |
+
lora_uploads = ui_components[f'lora_uploads_{prefix}']
|
| 48 |
+
count_state = ui_components[f'lora_count_state_{prefix}']
|
| 49 |
+
add_button = ui_components[f'add_lora_button_{prefix}']
|
| 50 |
+
del_button = ui_components[f'delete_lora_button_{prefix}']
|
| 51 |
+
|
| 52 |
+
def add_lora_row(c):
|
| 53 |
+
updates = {}
|
| 54 |
+
if c < MAX_LORAS:
|
| 55 |
+
c += 1
|
| 56 |
+
updates[lora_rows[c - 1]] = gr.update(visible=True)
|
| 57 |
+
|
| 58 |
+
updates[count_state] = c
|
| 59 |
+
updates[add_button] = gr.update(visible=c < MAX_LORAS)
|
| 60 |
+
updates[del_button] = gr.update(visible=c > 1)
|
| 61 |
+
return updates
|
| 62 |
+
|
| 63 |
+
def del_lora_row(c):
|
| 64 |
+
updates = {}
|
| 65 |
+
if c > 1:
|
| 66 |
+
updates[lora_rows[c - 1]] = gr.update(visible=False)
|
| 67 |
+
updates[lora_ids[c - 1]] = ""
|
| 68 |
+
updates[lora_scales[c - 1]] = 0.0
|
| 69 |
+
updates[lora_uploads[c - 1]] = None
|
| 70 |
+
c -= 1
|
| 71 |
+
|
| 72 |
+
updates[count_state] = c
|
| 73 |
+
updates[add_button] = gr.update(visible=True)
|
| 74 |
+
updates[del_button] = gr.update(visible=c > 1)
|
| 75 |
+
return updates
|
| 76 |
+
|
| 77 |
+
add_outputs = [count_state, add_button, del_button] + lora_rows
|
| 78 |
+
del_outputs = [count_state, add_button, del_button] + lora_rows + lora_ids + lora_scales + lora_uploads
|
| 79 |
+
|
| 80 |
+
add_button.click(add_lora_row, [count_state], add_outputs, show_progress=False)
|
| 81 |
+
del_button.click(del_lora_row, [count_state], del_outputs, show_progress=False)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def create_controlnet_event_handlers(prefix, ui_components):
|
| 85 |
+
cn_rows = ui_components.get(f'controlnet_rows_{prefix}')
|
| 86 |
+
if not cn_rows: return
|
| 87 |
+
cn_types = ui_components[f'controlnet_types_{prefix}']
|
| 88 |
+
cn_series = ui_components[f'controlnet_series_{prefix}']
|
| 89 |
+
cn_filepaths = ui_components[f'controlnet_filepaths_{prefix}']
|
| 90 |
+
cn_images = ui_components[f'controlnet_images_{prefix}']
|
| 91 |
+
cn_strengths = ui_components[f'controlnet_strengths_{prefix}']
|
| 92 |
+
|
| 93 |
+
count_state = ui_components[f'controlnet_count_state_{prefix}']
|
| 94 |
+
add_button = ui_components[f'add_controlnet_button_{prefix}']
|
| 95 |
+
del_button = ui_components[f'delete_controlnet_button_{prefix}']
|
| 96 |
+
accordion = ui_components[f'controlnet_accordion_{prefix}']
|
| 97 |
+
|
| 98 |
+
base_model_comp = ui_components.get(f'base_model_{prefix}')
|
| 99 |
+
actual_arch_comp = base_model_comp if base_model_comp else gr.State("SDXL")
|
| 100 |
+
|
| 101 |
+
def add_cn_row(c):
|
| 102 |
+
c += 1
|
| 103 |
+
updates = {
|
| 104 |
+
count_state: c,
|
| 105 |
+
cn_rows[c-1]: gr.update(visible=True),
|
| 106 |
+
add_button: gr.update(visible=c < MAX_CONTROLNETS),
|
| 107 |
+
del_button: gr.update(visible=True)
|
| 108 |
+
}
|
| 109 |
+
return updates
|
| 110 |
+
|
| 111 |
+
def del_cn_row(c):
|
| 112 |
+
c -= 1
|
| 113 |
+
updates = {
|
| 114 |
+
count_state: c,
|
| 115 |
+
cn_rows[c]: gr.update(visible=False),
|
| 116 |
+
cn_images[c]: None,
|
| 117 |
+
cn_strengths[c]: 1.0,
|
| 118 |
+
add_button: gr.update(visible=True),
|
| 119 |
+
del_button: gr.update(visible=c > 0)
|
| 120 |
+
}
|
| 121 |
+
return updates
|
| 122 |
+
|
| 123 |
+
add_outputs = [count_state, add_button, del_button] + cn_rows
|
| 124 |
+
del_outputs = [count_state, add_button, del_button] + cn_rows + cn_images + cn_strengths
|
| 125 |
+
add_button.click(fn=add_cn_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 126 |
+
del_button.click(fn=del_cn_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 127 |
+
|
| 128 |
+
def on_cn_type_change(selected_type, model_name):
|
| 129 |
+
from core.settings import MODEL_TYPE_MAP
|
| 130 |
+
m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL"
|
| 131 |
+
cn_full_config = load_controlnet_config()
|
| 132 |
+
|
| 133 |
+
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 134 |
+
controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
|
| 135 |
+
|
| 136 |
+
cn_config = cn_full_config.get(controlnet_key, [])
|
| 137 |
+
series_choices = []
|
| 138 |
+
if selected_type:
|
| 139 |
+
series_choices = sorted(list(set(
|
| 140 |
+
model.get("Series", "Default") for model in cn_config
|
| 141 |
+
if selected_type in model.get("Type", [])
|
| 142 |
+
)))
|
| 143 |
+
default_series = series_choices[0] if series_choices else None
|
| 144 |
+
filepath = "None"
|
| 145 |
+
if default_series:
|
| 146 |
+
for model in cn_config:
|
| 147 |
+
if model.get("Series") == default_series and selected_type in model.get("Type", []):
|
| 148 |
+
filepath = model.get("Filepath")
|
| 149 |
+
break
|
| 150 |
+
return gr.update(choices=series_choices, value=default_series), filepath
|
| 151 |
+
|
| 152 |
+
def on_cn_series_change(selected_series, selected_type, model_name):
|
| 153 |
+
from core.settings import MODEL_TYPE_MAP
|
| 154 |
+
m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL"
|
| 155 |
+
cn_full_config = load_controlnet_config()
|
| 156 |
+
|
| 157 |
+
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 158 |
+
controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
|
| 159 |
+
|
| 160 |
+
cn_config = cn_full_config.get(controlnet_key, [])
|
| 161 |
+
filepath = "None"
|
| 162 |
+
if selected_series and selected_type:
|
| 163 |
+
for model in cn_config:
|
| 164 |
+
if model.get("Series") == selected_series and selected_type in model.get("Type", []):
|
| 165 |
+
filepath = model.get("Filepath")
|
| 166 |
+
break
|
| 167 |
+
return filepath
|
| 168 |
+
|
| 169 |
+
for i in range(MAX_CONTROLNETS):
|
| 170 |
+
cn_types[i].change(
|
| 171 |
+
fn=on_cn_type_change,
|
| 172 |
+
inputs=[cn_types[i], actual_arch_comp],
|
| 173 |
+
outputs=[cn_series[i], cn_filepaths[i]],
|
| 174 |
+
show_progress=False
|
| 175 |
+
)
|
| 176 |
+
cn_series[i].change(
|
| 177 |
+
fn=on_cn_series_change,
|
| 178 |
+
inputs=[cn_series[i], cn_types[i], actual_arch_comp],
|
| 179 |
+
outputs=[cn_filepaths[i]],
|
| 180 |
+
show_progress=False
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
def on_accordion_expand(*images):
|
| 184 |
+
return [gr.update() for _ in images]
|
| 185 |
+
|
| 186 |
+
accordion.expand(
|
| 187 |
+
fn=on_accordion_expand,
|
| 188 |
+
inputs=cn_images,
|
| 189 |
+
outputs=cn_images,
|
| 190 |
+
show_progress=False
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def create_anima_controlnet_lllite_event_handlers(prefix, ui_components):
|
| 195 |
+
cn_rows = ui_components.get(f'anima_controlnet_lllite_rows_{prefix}')
|
| 196 |
+
if not cn_rows: return
|
| 197 |
+
cn_types = ui_components[f'anima_controlnet_lllite_types_{prefix}']
|
| 198 |
+
cn_series = ui_components[f'anima_controlnet_lllite_series_{prefix}']
|
| 199 |
+
cn_filepaths = ui_components[f'anima_controlnet_lllite_filepaths_{prefix}']
|
| 200 |
+
cn_images = ui_components[f'anima_controlnet_lllite_images_{prefix}']
|
| 201 |
+
cn_strengths = ui_components[f'anima_controlnet_lllite_strengths_{prefix}']
|
| 202 |
+
|
| 203 |
+
count_state = ui_components[f'anima_controlnet_lllite_count_state_{prefix}']
|
| 204 |
+
add_button = ui_components[f'add_anima_controlnet_lllite_button_{prefix}']
|
| 205 |
+
del_button = ui_components[f'delete_anima_controlnet_lllite_button_{prefix}']
|
| 206 |
+
accordion = ui_components[f'anima_controlnet_lllite_accordion_{prefix}']
|
| 207 |
+
|
| 208 |
+
def add_cn_row(c):
|
| 209 |
+
c += 1
|
| 210 |
+
updates = {
|
| 211 |
+
count_state: c,
|
| 212 |
+
cn_rows[c-1]: gr.update(visible=True),
|
| 213 |
+
add_button: gr.update(visible=c < MAX_CONTROLNETS),
|
| 214 |
+
del_button: gr.update(visible=True)
|
| 215 |
+
}
|
| 216 |
+
return updates
|
| 217 |
+
|
| 218 |
+
def del_cn_row(c):
|
| 219 |
+
c -= 1
|
| 220 |
+
updates = {
|
| 221 |
+
count_state: c,
|
| 222 |
+
cn_rows[c]: gr.update(visible=False),
|
| 223 |
+
cn_images[c]: None,
|
| 224 |
+
cn_strengths[c]: 1.0,
|
| 225 |
+
add_button: gr.update(visible=True),
|
| 226 |
+
del_button: gr.update(visible=c > 0)
|
| 227 |
+
}
|
| 228 |
+
return updates
|
| 229 |
+
|
| 230 |
+
add_outputs = [count_state, add_button, del_button] + cn_rows
|
| 231 |
+
del_outputs = [count_state, add_button, del_button] + cn_rows + cn_images + cn_strengths
|
| 232 |
+
add_button.click(fn=add_cn_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 233 |
+
del_button.click(fn=del_cn_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 234 |
+
|
| 235 |
+
def on_cn_type_change(selected_type):
|
| 236 |
+
cn_config = load_anima_controlnet_lllite_config()
|
| 237 |
+
series_choices = []
|
| 238 |
+
if selected_type:
|
| 239 |
+
series_choices = sorted(list(set(
|
| 240 |
+
model.get("Series", "Default") for model in cn_config
|
| 241 |
+
if selected_type in model.get("Type", [])
|
| 242 |
+
)))
|
| 243 |
+
default_series = series_choices[0] if series_choices else None
|
| 244 |
+
filepath = "None"
|
| 245 |
+
if default_series:
|
| 246 |
+
for model in cn_config:
|
| 247 |
+
if model.get("Series") == default_series and selected_type in model.get("Type", []):
|
| 248 |
+
filepath = model.get("Filepath")
|
| 249 |
+
break
|
| 250 |
+
return gr.update(choices=series_choices, value=default_series), filepath
|
| 251 |
+
|
| 252 |
+
def on_cn_series_change(selected_series, selected_type):
|
| 253 |
+
cn_config = load_anima_controlnet_lllite_config()
|
| 254 |
+
filepath = "None"
|
| 255 |
+
if selected_series and selected_type:
|
| 256 |
+
for model in cn_config:
|
| 257 |
+
if model.get("Series") == selected_series and selected_type in model.get("Type", []):
|
| 258 |
+
filepath = model.get("Filepath")
|
| 259 |
+
break
|
| 260 |
+
return filepath
|
| 261 |
+
|
| 262 |
+
for i in range(MAX_CONTROLNETS):
|
| 263 |
+
cn_types[i].change(
|
| 264 |
+
fn=on_cn_type_change,
|
| 265 |
+
inputs=[cn_types[i]],
|
| 266 |
+
outputs=[cn_series[i], cn_filepaths[i]],
|
| 267 |
+
show_progress=False
|
| 268 |
+
)
|
| 269 |
+
cn_series[i].change(
|
| 270 |
+
fn=on_cn_series_change,
|
| 271 |
+
inputs=[cn_series[i], cn_types[i]],
|
| 272 |
+
outputs=[cn_filepaths[i]],
|
| 273 |
+
show_progress=False
|
| 274 |
+
)
|
| 275 |
+
|
| 276 |
+
def on_accordion_expand(*images):
|
| 277 |
+
return [gr.update() for _ in images]
|
| 278 |
+
|
| 279 |
+
accordion.expand(
|
| 280 |
+
fn=on_accordion_expand,
|
| 281 |
+
inputs=cn_images,
|
| 282 |
+
outputs=cn_images,
|
| 283 |
+
show_progress=False
|
| 284 |
+
)
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
def create_diffsynth_controlnet_event_handlers(prefix, ui_components):
|
| 288 |
+
cn_rows = ui_components.get(f'diffsynth_controlnet_rows_{prefix}')
|
| 289 |
+
if not cn_rows: return
|
| 290 |
+
cn_types = ui_components[f'diffsynth_controlnet_types_{prefix}']
|
| 291 |
+
cn_series = ui_components[f'diffsynth_controlnet_series_{prefix}']
|
| 292 |
+
cn_filepaths = ui_components[f'diffsynth_controlnet_filepaths_{prefix}']
|
| 293 |
+
cn_images = ui_components[f'diffsynth_controlnet_images_{prefix}']
|
| 294 |
+
cn_strengths = ui_components[f'diffsynth_controlnet_strengths_{prefix}']
|
| 295 |
+
|
| 296 |
+
count_state = ui_components[f'diffsynth_controlnet_count_state_{prefix}']
|
| 297 |
+
add_button = ui_components[f'add_diffsynth_controlnet_button_{prefix}']
|
| 298 |
+
del_button = ui_components[f'delete_diffsynth_controlnet_button_{prefix}']
|
| 299 |
+
accordion = ui_components[f'diffsynth_controlnet_accordion_{prefix}']
|
| 300 |
+
|
| 301 |
+
base_model_comp = ui_components.get(f'base_model_{prefix}')
|
| 302 |
+
actual_arch_comp = base_model_comp if base_model_comp else gr.State("SDXL")
|
| 303 |
+
|
| 304 |
+
def add_cn_row(c):
|
| 305 |
+
c += 1
|
| 306 |
+
updates = {
|
| 307 |
+
count_state: c,
|
| 308 |
+
cn_rows[c-1]: gr.update(visible=True),
|
| 309 |
+
add_button: gr.update(visible=c < MAX_CONTROLNETS),
|
| 310 |
+
del_button: gr.update(visible=True)
|
| 311 |
+
}
|
| 312 |
+
return updates
|
| 313 |
+
|
| 314 |
+
def del_cn_row(c):
|
| 315 |
+
c -= 1
|
| 316 |
+
updates = {
|
| 317 |
+
count_state: c,
|
| 318 |
+
cn_rows[c]: gr.update(visible=False),
|
| 319 |
+
cn_images[c]: None,
|
| 320 |
+
cn_strengths[c]: 1.0,
|
| 321 |
+
add_button: gr.update(visible=True),
|
| 322 |
+
del_button: gr.update(visible=c > 0)
|
| 323 |
+
}
|
| 324 |
+
return updates
|
| 325 |
+
|
| 326 |
+
add_outputs = [count_state, add_button, del_button] + cn_rows
|
| 327 |
+
del_outputs = [count_state, add_button, del_button] + cn_rows + cn_images + cn_strengths
|
| 328 |
+
add_button.click(fn=add_cn_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 329 |
+
del_button.click(fn=del_cn_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 330 |
+
|
| 331 |
+
def on_cn_type_change(selected_type, model_name):
|
| 332 |
+
from core.settings import MODEL_TYPE_MAP
|
| 333 |
+
m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL"
|
| 334 |
+
cn_full_config = load_diffsynth_controlnet_config()
|
| 335 |
+
|
| 336 |
+
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 337 |
+
controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
|
| 338 |
+
|
| 339 |
+
cn_config = cn_full_config.get(controlnet_key, [])
|
| 340 |
+
series_choices = []
|
| 341 |
+
if selected_type:
|
| 342 |
+
series_choices = sorted(list(set(
|
| 343 |
+
model.get("Series", "Default") for model in cn_config
|
| 344 |
+
if selected_type in model.get("Type", [])
|
| 345 |
+
)))
|
| 346 |
+
default_series = series_choices[0] if series_choices else None
|
| 347 |
+
filepath = "None"
|
| 348 |
+
if default_series:
|
| 349 |
+
for model in cn_config:
|
| 350 |
+
if model.get("Series") == default_series and selected_type in model.get("Type", []):
|
| 351 |
+
filepath = model.get("Filepath")
|
| 352 |
+
break
|
| 353 |
+
return gr.update(choices=series_choices, value=default_series), filepath
|
| 354 |
+
|
| 355 |
+
def on_cn_series_change(selected_series, selected_type, model_name):
|
| 356 |
+
from core.settings import MODEL_TYPE_MAP
|
| 357 |
+
m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL"
|
| 358 |
+
cn_full_config = load_diffsynth_controlnet_config()
|
| 359 |
+
|
| 360 |
+
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 361 |
+
controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
|
| 362 |
+
|
| 363 |
+
cn_config = cn_full_config.get(controlnet_key, [])
|
| 364 |
+
filepath = "None"
|
| 365 |
+
if selected_series and selected_type:
|
| 366 |
+
for model in cn_config:
|
| 367 |
+
if model.get("Series") == selected_series and selected_type in model.get("Type", []):
|
| 368 |
+
filepath = model.get("Filepath")
|
| 369 |
+
break
|
| 370 |
+
return filepath
|
| 371 |
+
|
| 372 |
+
for i in range(MAX_CONTROLNETS):
|
| 373 |
+
cn_types[i].change(
|
| 374 |
+
fn=on_cn_type_change,
|
| 375 |
+
inputs=[cn_types[i], actual_arch_comp],
|
| 376 |
+
outputs=[cn_series[i], cn_filepaths[i]],
|
| 377 |
+
show_progress=False
|
| 378 |
+
)
|
| 379 |
+
cn_series[i].change(
|
| 380 |
+
fn=on_cn_series_change,
|
| 381 |
+
inputs=[cn_series[i], cn_types[i], actual_arch_comp],
|
| 382 |
+
outputs=[cn_filepaths[i]],
|
| 383 |
+
show_progress=False
|
| 384 |
+
)
|
| 385 |
+
|
| 386 |
+
def on_accordion_expand(*images):
|
| 387 |
+
return [gr.update() for _ in images]
|
| 388 |
+
|
| 389 |
+
accordion.expand(
|
| 390 |
+
fn=on_accordion_expand,
|
| 391 |
+
inputs=cn_images,
|
| 392 |
+
outputs=cn_images,
|
| 393 |
+
show_progress=False
|
| 394 |
+
)
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
def create_flux1_ipadapter_event_handlers(prefix, ui_components):
|
| 398 |
+
fipa_rows = ui_components.get(f'flux1_ipadapter_rows_{prefix}')
|
| 399 |
+
if not fipa_rows: return
|
| 400 |
+
count_state = ui_components[f'flux1_ipadapter_count_state_{prefix}']
|
| 401 |
+
add_button = ui_components[f'add_flux1_ipadapter_button_{prefix}']
|
| 402 |
+
del_button = ui_components[f'delete_flux1_ipadapter_button_{prefix}']
|
| 403 |
+
|
| 404 |
+
def add_fipa_row(c):
|
| 405 |
+
c += 1
|
| 406 |
+
return {
|
| 407 |
+
count_state: c,
|
| 408 |
+
fipa_rows[c - 1]: gr.update(visible=True),
|
| 409 |
+
add_button: gr.update(visible=c < MAX_IPADAPTERS),
|
| 410 |
+
del_button: gr.update(visible=True),
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
def del_fipa_row(c):
|
| 414 |
+
c -= 1
|
| 415 |
+
return {
|
| 416 |
+
count_state: c,
|
| 417 |
+
fipa_rows[c]: gr.update(visible=False),
|
| 418 |
+
add_button: gr.update(visible=True),
|
| 419 |
+
del_button: gr.update(visible=c > 0),
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
add_outputs = [count_state, add_button, del_button] + fipa_rows
|
| 423 |
+
del_outputs = [count_state, add_button, del_button] + fipa_rows
|
| 424 |
+
add_button.click(fn=add_fipa_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 425 |
+
del_button.click(fn=del_fipa_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 426 |
+
|
| 427 |
+
|
| 428 |
+
def create_sd3_ipadapter_event_handlers(prefix, ui_components):
|
| 429 |
+
ipa_rows = ui_components.get(f'sd3_ipadapter_rows_{prefix}')
|
| 430 |
+
if not ipa_rows: return
|
| 431 |
+
count_state = ui_components[f'sd3_ipadapter_count_state_{prefix}']
|
| 432 |
+
add_button = ui_components[f'add_sd3_ipadapter_button_{prefix}']
|
| 433 |
+
del_button = ui_components[f'delete_sd3_ipadapter_button_{prefix}']
|
| 434 |
+
images = ui_components[f'sd3_ipadapter_images_{prefix}']
|
| 435 |
+
weights = ui_components[f'sd3_ipadapter_weights_{prefix}']
|
| 436 |
+
start_percents = ui_components[f'sd3_ipadapter_start_percents_{prefix}']
|
| 437 |
+
end_percents = ui_components[f'sd3_ipadapter_end_percents_{prefix}']
|
| 438 |
+
|
| 439 |
+
def add_ipa_row(c):
|
| 440 |
+
c += 1
|
| 441 |
+
return {
|
| 442 |
+
count_state: c,
|
| 443 |
+
ipa_rows[c - 1]: gr.update(visible=True),
|
| 444 |
+
add_button: gr.update(visible=c < MAX_IPADAPTERS),
|
| 445 |
+
del_button: gr.update(visible=True),
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
def del_ipa_row(c):
|
| 449 |
+
c -= 1
|
| 450 |
+
return {
|
| 451 |
+
count_state: c,
|
| 452 |
+
ipa_rows[c]: gr.update(visible=False),
|
| 453 |
+
images[c]: None,
|
| 454 |
+
weights[c]: 0.5,
|
| 455 |
+
start_percents[c]: 0.0,
|
| 456 |
+
end_percents[c]: 1.0,
|
| 457 |
+
add_button: gr.update(visible=True),
|
| 458 |
+
del_button: gr.update(visible=c > 0),
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
add_outputs = [count_state, add_button, del_button] + ipa_rows
|
| 462 |
+
del_outputs = [count_state, add_button, del_button] + ipa_rows + images + weights + start_percents + end_percents
|
| 463 |
+
add_button.click(fn=add_ipa_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 464 |
+
del_button.click(fn=del_ipa_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
def create_style_event_handlers(prefix, ui_components):
|
| 468 |
+
style_rows = ui_components.get(f'style_rows_{prefix}')
|
| 469 |
+
if not style_rows: return
|
| 470 |
+
count_state = ui_components[f'style_count_state_{prefix}']
|
| 471 |
+
add_button = ui_components[f'add_style_button_{prefix}']
|
| 472 |
+
del_button = ui_components[f'delete_style_button_{prefix}']
|
| 473 |
+
|
| 474 |
+
def add_style_row(c):
|
| 475 |
+
c += 1
|
| 476 |
+
return {
|
| 477 |
+
count_state: c,
|
| 478 |
+
style_rows[c - 1]: gr.update(visible=True),
|
| 479 |
+
add_button: gr.update(visible=c < 5),
|
| 480 |
+
del_button: gr.update(visible=True),
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
def del_style_row(c):
|
| 484 |
+
c -= 1
|
| 485 |
+
return {
|
| 486 |
+
count_state: c,
|
| 487 |
+
style_rows[c]: gr.update(visible=False),
|
| 488 |
+
add_button: gr.update(visible=True),
|
| 489 |
+
del_button: gr.update(visible=c > 0),
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
add_outputs = [count_state, add_button, del_button] + style_rows
|
| 493 |
+
del_outputs = [count_state, add_button, del_button] + style_rows
|
| 494 |
+
add_button.click(fn=add_style_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 495 |
+
del_button.click(fn=del_style_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
def create_ipadapter_event_handlers(prefix, ui_components):
|
| 499 |
+
ipa_rows = ui_components.get(f'ipadapter_rows_{prefix}')
|
| 500 |
+
if not ipa_rows: return
|
| 501 |
+
ipa_lora_strengths = ui_components[f'ipadapter_lora_strengths_{prefix}']
|
| 502 |
+
ipa_final_preset = ui_components[f'ipadapter_final_preset_{prefix}']
|
| 503 |
+
ipa_final_lora_strength = ui_components[f'ipadapter_final_lora_strength_{prefix}']
|
| 504 |
+
count_state = ui_components[f'ipadapter_count_state_{prefix}']
|
| 505 |
+
add_button = ui_components[f'add_ipadapter_button_{prefix}']
|
| 506 |
+
del_button = ui_components[f'delete_ipadapter_button_{prefix}']
|
| 507 |
+
accordion = ui_components[f'ipadapter_accordion_{prefix}']
|
| 508 |
+
|
| 509 |
+
def add_ipa_row(c):
|
| 510 |
+
c += 1
|
| 511 |
+
return {
|
| 512 |
+
count_state: c,
|
| 513 |
+
ipa_rows[c - 1]: gr.update(visible=True),
|
| 514 |
+
add_button: gr.update(visible=c < MAX_IPADAPTERS),
|
| 515 |
+
del_button: gr.update(visible=True),
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
def del_ipa_row(c):
|
| 519 |
+
c -= 1
|
| 520 |
+
return {
|
| 521 |
+
count_state: c,
|
| 522 |
+
ipa_rows[c]: gr.update(visible=False),
|
| 523 |
+
add_button: gr.update(visible=True),
|
| 524 |
+
del_button: gr.update(visible=c > 0),
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
add_outputs = [count_state, add_button, del_button] + ipa_rows
|
| 528 |
+
del_outputs = [count_state, add_button, del_button] + ipa_rows
|
| 529 |
+
add_button.click(fn=add_ipa_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 530 |
+
del_button.click(fn=del_ipa_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 531 |
+
|
| 532 |
+
def on_preset_change(preset_value):
|
| 533 |
+
config = load_ipadapter_config()
|
| 534 |
+
faceid_presets = []
|
| 535 |
+
if config:
|
| 536 |
+
faceid_presets.extend(config.get("IPAdapter_FaceID_presets", {}).get("SDXL", []))
|
| 537 |
+
faceid_presets.extend(config.get("IPAdapter_FaceID_presets", {}).get("SD1.5", []))
|
| 538 |
+
|
| 539 |
+
is_visible = preset_value in faceid_presets
|
| 540 |
+
updates = [gr.update(visible=is_visible)] * (MAX_IPADAPTERS + 1)
|
| 541 |
+
return updates
|
| 542 |
+
|
| 543 |
+
all_lora_strength_sliders = [ipa_final_lora_strength] + ipa_lora_strengths
|
| 544 |
+
ipa_final_preset.change(fn=on_preset_change, inputs=[ipa_final_preset], outputs=all_lora_strength_sliders, show_progress=False)
|
| 545 |
+
|
| 546 |
+
accordion.expand(fn=lambda *imgs: [gr.update() for _ in imgs], inputs=ui_components[f'ipadapter_images_{prefix}'], outputs=ui_components[f'ipadapter_images_{prefix}'], show_progress=False)
|
| 547 |
+
|
| 548 |
+
|
| 549 |
+
def create_reference_latent_event_handlers(prefix, ui_components):
|
| 550 |
+
ref_rows = ui_components.get(f'reference_latent_rows_{prefix}')
|
| 551 |
+
if not ref_rows: return
|
| 552 |
+
count_state = ui_components[f'reference_latent_count_state_{prefix}']
|
| 553 |
+
add_button = ui_components[f'add_reference_latent_button_{prefix}']
|
| 554 |
+
del_button = ui_components[f'delete_reference_latent_button_{prefix}']
|
| 555 |
+
images = ui_components[f'reference_latent_images_{prefix}']
|
| 556 |
+
|
| 557 |
+
def add_ref_row(c):
|
| 558 |
+
c += 1
|
| 559 |
+
return {
|
| 560 |
+
count_state: c,
|
| 561 |
+
ref_rows[c - 1]: gr.update(visible=True),
|
| 562 |
+
add_button: gr.update(visible=c < 10),
|
| 563 |
+
del_button: gr.update(visible=True),
|
| 564 |
+
}
|
| 565 |
+
|
| 566 |
+
def del_ref_row(c):
|
| 567 |
+
c -= 1
|
| 568 |
+
return {
|
| 569 |
+
count_state: c,
|
| 570 |
+
ref_rows[c]: gr.update(visible=False),
|
| 571 |
+
images[c]: None,
|
| 572 |
+
add_button: gr.update(visible=True),
|
| 573 |
+
del_button: gr.update(visible=c > 0),
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
+
add_outputs = [count_state, add_button, del_button] + ref_rows
|
| 577 |
+
del_outputs = [count_state, add_button, del_button] + ref_rows + images
|
| 578 |
+
add_button.click(fn=add_ref_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 579 |
+
del_button.click(fn=del_ref_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
def create_hidream_o1_reference_event_handlers(prefix, ui_components):
|
| 583 |
+
ref_rows = ui_components.get(f'hidream_o1_reference_rows_{prefix}')
|
| 584 |
+
if not ref_rows: return
|
| 585 |
+
count_state = ui_components[f'hidream_o1_reference_count_state_{prefix}']
|
| 586 |
+
add_button = ui_components[f'add_hidream_o1_reference_button_{prefix}']
|
| 587 |
+
del_button = ui_components[f'delete_hidream_o1_reference_button_{prefix}']
|
| 588 |
+
images = ui_components[f'hidream_o1_reference_images_{prefix}']
|
| 589 |
+
|
| 590 |
+
def add_ref_row(c):
|
| 591 |
+
c += 1
|
| 592 |
+
return {
|
| 593 |
+
count_state: c,
|
| 594 |
+
ref_rows[c - 1]: gr.update(visible=True),
|
| 595 |
+
add_button: gr.update(visible=c < 10),
|
| 596 |
+
del_button: gr.update(visible=True),
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
def del_ref_row(c):
|
| 600 |
+
c -= 1
|
| 601 |
+
return {
|
| 602 |
+
count_state: c,
|
| 603 |
+
ref_rows[c]: gr.update(visible=False),
|
| 604 |
+
images[c]: None,
|
| 605 |
+
add_button: gr.update(visible=True),
|
| 606 |
+
del_button: gr.update(visible=c > 0),
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
add_outputs = [count_state, add_button, del_button] + ref_rows
|
| 610 |
+
del_outputs = [count_state, add_button, del_button] + ref_rows + images
|
| 611 |
+
add_button.click(fn=add_ref_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 612 |
+
del_button.click(fn=del_ref_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 613 |
+
|
| 614 |
+
|
| 615 |
+
def create_embedding_event_handlers(prefix, ui_components):
|
| 616 |
+
rows = ui_components.get(f'embedding_rows_{prefix}')
|
| 617 |
+
if not rows: return
|
| 618 |
+
ids = ui_components[f'embeddings_ids_{prefix}']
|
| 619 |
+
files = ui_components[f'embeddings_files_{prefix}']
|
| 620 |
+
count_state = ui_components[f'embedding_count_state_{prefix}']
|
| 621 |
+
add_button = ui_components[f'add_embedding_button_{prefix}']
|
| 622 |
+
del_button = ui_components[f'delete_embedding_button_{prefix}']
|
| 623 |
+
|
| 624 |
+
def add_row(c):
|
| 625 |
+
c += 1
|
| 626 |
+
return {
|
| 627 |
+
count_state: c,
|
| 628 |
+
rows[c - 1]: gr.update(visible=True),
|
| 629 |
+
add_button: gr.update(visible=c < MAX_EMBEDDINGS),
|
| 630 |
+
del_button: gr.update(visible=True)
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
def del_row(c):
|
| 634 |
+
c -= 1
|
| 635 |
+
return {
|
| 636 |
+
count_state: c,
|
| 637 |
+
rows[c]: gr.update(visible=False),
|
| 638 |
+
ids[c]: "",
|
| 639 |
+
files[c]: None,
|
| 640 |
+
add_button: gr.update(visible=True),
|
| 641 |
+
del_button: gr.update(visible=c > 0)
|
| 642 |
+
}
|
| 643 |
+
|
| 644 |
+
add_outputs = [count_state, add_button, del_button] + rows
|
| 645 |
+
del_outputs = [count_state, add_button, del_button] + rows + ids + files
|
| 646 |
+
add_button.click(fn=add_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 647 |
+
del_button.click(fn=del_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
| 648 |
+
|
| 649 |
+
|
| 650 |
+
def create_conditioning_event_handlers(prefix, ui_components):
|
| 651 |
+
rows = ui_components.get(f'conditioning_rows_{prefix}')
|
| 652 |
+
if not rows: return
|
| 653 |
+
prompts = ui_components[f'conditioning_prompts_{prefix}']
|
| 654 |
+
count_state = ui_components[f'conditioning_count_state_{prefix}']
|
| 655 |
+
add_button = ui_components[f'add_conditioning_button_{prefix}']
|
| 656 |
+
del_button = ui_components[f'delete_conditioning_button_{prefix}']
|
| 657 |
+
|
| 658 |
+
def add_row(c):
|
| 659 |
+
c += 1
|
| 660 |
+
return {
|
| 661 |
+
count_state: c,
|
| 662 |
+
rows[c - 1]: gr.update(visible=True),
|
| 663 |
+
add_button: gr.update(visible=c < MAX_CONDITIONINGS),
|
| 664 |
+
del_button: gr.update(visible=True),
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
def del_row(c):
|
| 668 |
+
c -= 1
|
| 669 |
+
return {
|
| 670 |
+
count_state: c,
|
| 671 |
+
rows[c]: gr.update(visible=False),
|
| 672 |
+
prompts[c]: "",
|
| 673 |
+
add_button: gr.update(visible=True),
|
| 674 |
+
del_button: gr.update(visible=c > 0),
|
| 675 |
+
}
|
| 676 |
+
|
| 677 |
+
add_outputs = [count_state, add_button, del_button] + rows
|
| 678 |
+
del_outputs = [count_state, add_button, del_button] + rows + prompts
|
| 679 |
+
add_button.click(fn=add_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
|
| 680 |
+
del_button.click(fn=del_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
|
ui/events/change_handlers.py
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from core.settings import (
|
| 3 |
+
MODEL_TYPE_MAP,
|
| 4 |
+
MODEL_MAP_CHECKPOINT,
|
| 5 |
+
FEATURES_CONFIG,
|
| 6 |
+
ARCHITECTURES_CONFIG,
|
| 7 |
+
MODEL_DEFAULTS_CONFIG,
|
| 8 |
+
ARCH_CATEGORIES_MAP
|
| 9 |
+
)
|
| 10 |
+
from utils.app_utils import get_model_generation_defaults
|
| 11 |
+
from ui.shared.ui_components import RESOLUTION_MAP
|
| 12 |
+
from .config_loaders import (
|
| 13 |
+
get_cn_defaults,
|
| 14 |
+
get_anima_cn_defaults,
|
| 15 |
+
get_diffsynth_cn_defaults,
|
| 16 |
+
load_ipadapter_config
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def make_update_fn(m_comp, cat_comp, cs_comp, ar_comp, width_comp, height_comp, cn_types, cn_series, cn_filepaths, anima_cn_types, anima_cn_series, anima_cn_filepaths, diffsynth_cn_types, diffsynth_cn_series, diffsynth_cn_filepaths, ipa_preset, lora_acc, cn_acc, anima_cn_acc, diffsynth_cn_acc, ipa_acc, sd3_ipa_acc, flux1_ipa_acc, style_acc, embed_acc, cond_acc, ref_latent_acc, hidream_o1_ref_acc, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp):
|
| 20 |
+
def update_fn(*args):
|
| 21 |
+
arch = args[0]
|
| 22 |
+
category = args[1]
|
| 23 |
+
current_ar = args[2] if len(args) > 2 else None
|
| 24 |
+
|
| 25 |
+
if arch == "ALL":
|
| 26 |
+
valid_cats = list(set(cat for cats in ARCH_CATEGORIES_MAP.values() for cat in cats))
|
| 27 |
+
else:
|
| 28 |
+
valid_cats = ARCH_CATEGORIES_MAP.get(arch, [])
|
| 29 |
+
|
| 30 |
+
cat_choices = ["ALL"] + sorted(valid_cats)
|
| 31 |
+
new_category = category if category in cat_choices else "ALL"
|
| 32 |
+
|
| 33 |
+
choices = []
|
| 34 |
+
for name, info in MODEL_MAP_CHECKPOINT.items():
|
| 35 |
+
m_arch = info[2]
|
| 36 |
+
m_cat = info[4] if len(info) > 4 else None
|
| 37 |
+
arch_match = (arch == "ALL" or m_arch == arch)
|
| 38 |
+
cat_match = (new_category == "ALL" or m_cat == new_category)
|
| 39 |
+
if arch_match and cat_match:
|
| 40 |
+
choices.append(name)
|
| 41 |
+
|
| 42 |
+
val = choices[0] if choices else None
|
| 43 |
+
|
| 44 |
+
updates = {
|
| 45 |
+
m_comp: gr.update(choices=choices, value=val),
|
| 46 |
+
cat_comp: gr.update(choices=cat_choices, value=new_category)
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
m_type = MODEL_TYPE_MAP.get(val, "SDXL") if val else "SDXL"
|
| 50 |
+
|
| 51 |
+
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 52 |
+
arch_model_type = architectures_dict.get(m_type, {}).get("model_type", m_type.lower().replace(" ", "").replace(".", ""))
|
| 53 |
+
|
| 54 |
+
arch_features = FEATURES_CONFIG.get(arch_model_type, FEATURES_CONFIG.get('default', {}))
|
| 55 |
+
enabled_chains = arch_features.get('enabled_chains', [])
|
| 56 |
+
|
| 57 |
+
if lora_acc: updates[lora_acc] = gr.update(visible=('lora' in enabled_chains))
|
| 58 |
+
if cn_acc: updates[cn_acc] = gr.update(visible=('controlnet' in enabled_chains))
|
| 59 |
+
if anima_cn_acc: updates[anima_cn_acc] = gr.update(visible=('anima_controlnet_lllite' in enabled_chains))
|
| 60 |
+
if diffsynth_cn_acc: updates[diffsynth_cn_acc] = gr.update(visible=('controlnet_model_patch' in enabled_chains))
|
| 61 |
+
if ipa_acc: updates[ipa_acc] = gr.update(visible=('ipadapter' in enabled_chains))
|
| 62 |
+
if flux1_ipa_acc: updates[flux1_ipa_acc] = gr.update(visible=('flux1_ipadapter' in enabled_chains))
|
| 63 |
+
if sd3_ipa_acc: updates[sd3_ipa_acc] = gr.update(visible=('sd3_ipadapter' in enabled_chains))
|
| 64 |
+
if style_acc: updates[style_acc] = gr.update(visible=('style' in enabled_chains))
|
| 65 |
+
if embed_acc: updates[embed_acc] = gr.update(visible=('embedding' in enabled_chains))
|
| 66 |
+
if cond_acc: updates[cond_acc] = gr.update(visible=('conditioning' in enabled_chains))
|
| 67 |
+
if ref_latent_acc: updates[ref_latent_acc] = gr.update(visible=('reference_latent' in enabled_chains))
|
| 68 |
+
if hidream_o1_ref_acc: updates[hidream_o1_ref_acc] = gr.update(visible=('hidream_o1_reference' in enabled_chains))
|
| 69 |
+
|
| 70 |
+
if cs_comp:
|
| 71 |
+
updates[cs_comp] = gr.update(visible=(arch_model_type == "sd15"))
|
| 72 |
+
if guidance_comp:
|
| 73 |
+
updates[guidance_comp] = gr.update(visible=(arch_model_type == "flux1"))
|
| 74 |
+
|
| 75 |
+
if ar_comp:
|
| 76 |
+
res_key = arch_model_type
|
| 77 |
+
if res_key not in RESOLUTION_MAP:
|
| 78 |
+
res_key = 'sdxl'
|
| 79 |
+
res_map = RESOLUTION_MAP.get(res_key, {})
|
| 80 |
+
target_ar = current_ar if current_ar in res_map else (list(res_map.keys())[0] if res_map else "1:1 (Square)")
|
| 81 |
+
updates[ar_comp] = gr.update(choices=list(res_map.keys()), value=target_ar)
|
| 82 |
+
if width_comp and height_comp and target_ar in res_map:
|
| 83 |
+
updates[width_comp] = gr.update(value=res_map[target_ar][0])
|
| 84 |
+
updates[height_comp] = gr.update(value=res_map[target_ar][1])
|
| 85 |
+
|
| 86 |
+
controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
|
| 87 |
+
|
| 88 |
+
all_types, default_type, series_choices, default_series, filepath = get_cn_defaults(controlnet_key)
|
| 89 |
+
for t_comp in cn_types:
|
| 90 |
+
updates[t_comp] = gr.update(choices=all_types, value=default_type)
|
| 91 |
+
for s_comp in cn_series:
|
| 92 |
+
updates[s_comp] = gr.update(choices=series_choices, value=default_series)
|
| 93 |
+
for f_comp in cn_filepaths:
|
| 94 |
+
updates[f_comp] = filepath
|
| 95 |
+
|
| 96 |
+
anima_all_types, anima_default_type, anima_series_choices, anima_default_series, anima_filepath = get_anima_cn_defaults()
|
| 97 |
+
for t_comp in anima_cn_types:
|
| 98 |
+
updates[t_comp] = gr.update(choices=anima_all_types, value=anima_default_type)
|
| 99 |
+
for s_comp in anima_cn_series:
|
| 100 |
+
updates[s_comp] = gr.update(choices=anima_series_choices, value=anima_default_series)
|
| 101 |
+
for f_comp in anima_cn_filepaths:
|
| 102 |
+
updates[f_comp] = anima_filepath
|
| 103 |
+
|
| 104 |
+
diffsynth_all_types, diffsynth_default_type, diffsynth_series_choices, diffsynth_default_series, diffsynth_filepath = get_diffsynth_cn_defaults(controlnet_key)
|
| 105 |
+
for t_comp in diffsynth_cn_types:
|
| 106 |
+
updates[t_comp] = gr.update(choices=diffsynth_all_types, value=diffsynth_default_type)
|
| 107 |
+
for s_comp in diffsynth_cn_series:
|
| 108 |
+
updates[s_comp] = gr.update(choices=diffsynth_series_choices, value=diffsynth_default_series)
|
| 109 |
+
for f_comp in diffsynth_cn_filepaths:
|
| 110 |
+
updates[f_comp] = diffsynth_filepath
|
| 111 |
+
|
| 112 |
+
if ipa_preset and (arch_model_type in ["sdxl", "sd15", "sd35"]):
|
| 113 |
+
config = load_ipadapter_config()
|
| 114 |
+
ipa_arch_key = "SDXL" if arch_model_type in ["sdxl", "sd35"] else "SD1.5"
|
| 115 |
+
std_presets = config.get("IPAdapter_presets", {}).get(ipa_arch_key, [])
|
| 116 |
+
face_presets = config.get("IPAdapter_FaceID_presets", {}).get(ipa_arch_key, [])
|
| 117 |
+
all_ipa_presets = std_presets + face_presets
|
| 118 |
+
default_ipa = all_ipa_presets[0] if all_ipa_presets else None
|
| 119 |
+
updates[ipa_preset] = gr.update(choices=all_ipa_presets, value=default_ipa)
|
| 120 |
+
|
| 121 |
+
defaults = get_model_generation_defaults(val, arch_model_type, MODEL_DEFAULTS_CONFIG)
|
| 122 |
+
if steps_comp: updates[steps_comp] = gr.update(value=defaults.get('steps'))
|
| 123 |
+
if cfg_comp: updates[cfg_comp] = gr.update(value=defaults.get('cfg'))
|
| 124 |
+
if sampler_comp: updates[sampler_comp] = gr.update(value=defaults.get('sampler_name'))
|
| 125 |
+
if scheduler_comp: updates[scheduler_comp] = gr.update(value=defaults.get('scheduler'))
|
| 126 |
+
if prompt_comp: updates[prompt_comp] = gr.update(value=defaults.get('positive_prompt'))
|
| 127 |
+
if neg_prompt_comp: updates[neg_prompt_comp] = gr.update(value=defaults.get('negative_prompt'))
|
| 128 |
+
|
| 129 |
+
return updates
|
| 130 |
+
return update_fn
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def make_model_change_fn(cat_comp_ref, cs_comp, ar_comp, width_comp, height_comp, cn_types, cn_series, cn_filepaths, anima_cn_types, anima_cn_series, anima_cn_filepaths, diffsynth_cn_types, diffsynth_cn_series, diffsynth_cn_filepaths, arch_comp_ref, ipa_preset, lora_acc, cn_acc, anima_cn_acc, diffsynth_cn_acc, ipa_acc, sd3_ipa_acc, flux1_ipa_acc, style_acc, embed_acc, cond_acc, ref_latent_acc, hidream_o1_ref_acc, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp):
|
| 134 |
+
def change_fn(*args):
|
| 135 |
+
model_name = args[0]
|
| 136 |
+
idx = 1
|
| 137 |
+
current_arch = args[idx] if arch_comp_ref and idx < len(args) else None
|
| 138 |
+
if arch_comp_ref: idx += 1
|
| 139 |
+
current_cat = args[idx] if cat_comp_ref and idx < len(args) else None
|
| 140 |
+
if cat_comp_ref: idx += 1
|
| 141 |
+
current_ar = args[idx] if idx < len(args) else None
|
| 142 |
+
|
| 143 |
+
m_type = MODEL_TYPE_MAP.get(model_name, "SDXL")
|
| 144 |
+
|
| 145 |
+
m_info = MODEL_MAP_CHECKPOINT.get(model_name)
|
| 146 |
+
m_cat = m_info[4] if m_info and len(m_info) > 4 else None
|
| 147 |
+
if not m_cat: m_cat = "ALL"
|
| 148 |
+
|
| 149 |
+
updates = {}
|
| 150 |
+
target_arch = m_type
|
| 151 |
+
if arch_comp_ref:
|
| 152 |
+
if current_arch == "ALL":
|
| 153 |
+
updates[arch_comp_ref] = gr.update()
|
| 154 |
+
target_arch = "ALL"
|
| 155 |
+
else:
|
| 156 |
+
updates[arch_comp_ref] = m_type
|
| 157 |
+
|
| 158 |
+
if cat_comp_ref:
|
| 159 |
+
if target_arch == "ALL":
|
| 160 |
+
valid_cats = list(set(cat for cats in ARCH_CATEGORIES_MAP.values() for cat in cats))
|
| 161 |
+
else:
|
| 162 |
+
valid_cats = ARCH_CATEGORIES_MAP.get(target_arch, [])
|
| 163 |
+
cat_choices = ["ALL"] + sorted(valid_cats)
|
| 164 |
+
|
| 165 |
+
if current_cat == "ALL":
|
| 166 |
+
updates[cat_comp_ref] = gr.update(choices=cat_choices)
|
| 167 |
+
else:
|
| 168 |
+
updates[cat_comp_ref] = gr.update(choices=cat_choices, value=m_cat)
|
| 169 |
+
|
| 170 |
+
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 171 |
+
arch_model_type = architectures_dict.get(m_type, {}).get("model_type", m_type.lower().replace(" ", "").replace(".", ""))
|
| 172 |
+
|
| 173 |
+
arch_features = FEATURES_CONFIG.get(arch_model_type, FEATURES_CONFIG.get('default', {}))
|
| 174 |
+
enabled_chains = arch_features.get('enabled_chains', [])
|
| 175 |
+
|
| 176 |
+
if lora_acc: updates[lora_acc] = gr.update(visible=('lora' in enabled_chains))
|
| 177 |
+
if cn_acc: updates[cn_acc] = gr.update(visible=('controlnet' in enabled_chains))
|
| 178 |
+
if anima_cn_acc: updates[anima_cn_acc] = gr.update(visible=('anima_controlnet_lllite' in enabled_chains))
|
| 179 |
+
if diffsynth_cn_acc: updates[diffsynth_cn_acc] = gr.update(visible=('controlnet_model_patch' in enabled_chains))
|
| 180 |
+
if ipa_acc: updates[ipa_acc] = gr.update(visible=('ipadapter' in enabled_chains))
|
| 181 |
+
if flux1_ipa_acc: updates[flux1_ipa_acc] = gr.update(visible=('flux1_ipadapter' in enabled_chains))
|
| 182 |
+
if sd3_ipa_acc: updates[sd3_ipa_acc] = gr.update(visible=('sd3_ipadapter' in enabled_chains))
|
| 183 |
+
if style_acc: updates[style_acc] = gr.update(visible=('style' in enabled_chains))
|
| 184 |
+
if embed_acc: updates[embed_acc] = gr.update(visible=('embedding' in enabled_chains))
|
| 185 |
+
if cond_acc: updates[cond_acc] = gr.update(visible=('conditioning' in enabled_chains))
|
| 186 |
+
if ref_latent_acc: updates[ref_latent_acc] = gr.update(visible=('reference_latent' in enabled_chains))
|
| 187 |
+
if hidream_o1_ref_acc: updates[hidream_o1_ref_acc] = gr.update(visible=('hidream_o1_reference' in enabled_chains))
|
| 188 |
+
|
| 189 |
+
if cs_comp:
|
| 190 |
+
updates[cs_comp] = gr.update(visible=(arch_model_type == "sd15"))
|
| 191 |
+
if guidance_comp:
|
| 192 |
+
updates[guidance_comp] = gr.update(visible=(arch_model_type == "flux1"))
|
| 193 |
+
|
| 194 |
+
if ar_comp:
|
| 195 |
+
res_key = arch_model_type
|
| 196 |
+
if res_key not in RESOLUTION_MAP:
|
| 197 |
+
res_key = 'sdxl'
|
| 198 |
+
res_map = RESOLUTION_MAP.get(res_key, {})
|
| 199 |
+
target_ar = current_ar if current_ar in res_map else (list(res_map.keys())[0] if res_map else "1:1 (Square)")
|
| 200 |
+
updates[ar_comp] = gr.update(choices=list(res_map.keys()), value=target_ar)
|
| 201 |
+
if width_comp and height_comp and target_ar in res_map:
|
| 202 |
+
updates[width_comp] = gr.update(value=res_map[target_ar][0])
|
| 203 |
+
updates[height_comp] = gr.update(value=res_map[target_ar][1])
|
| 204 |
+
|
| 205 |
+
controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
|
| 206 |
+
|
| 207 |
+
all_types, default_type, series_choices, default_series, filepath = get_cn_defaults(controlnet_key)
|
| 208 |
+
for t_comp in cn_types:
|
| 209 |
+
updates[t_comp] = gr.update(choices=all_types, value=default_type)
|
| 210 |
+
for s_comp in cn_series:
|
| 211 |
+
updates[s_comp] = gr.update(choices=series_choices, value=default_series)
|
| 212 |
+
for f_comp in cn_filepaths:
|
| 213 |
+
updates[f_comp] = filepath
|
| 214 |
+
|
| 215 |
+
anima_all_types, anima_default_type, anima_series_choices, anima_default_series, anima_filepath = get_anima_cn_defaults()
|
| 216 |
+
for t_comp in anima_cn_types:
|
| 217 |
+
updates[t_comp] = gr.update(choices=anima_all_types, value=anima_default_type)
|
| 218 |
+
for s_comp in anima_cn_series:
|
| 219 |
+
updates[s_comp] = gr.update(choices=anima_series_choices, value=anima_default_series)
|
| 220 |
+
for f_comp in anima_cn_filepaths:
|
| 221 |
+
updates[f_comp] = anima_filepath
|
| 222 |
+
|
| 223 |
+
diffsynth_all_types, diffsynth_default_type, diffsynth_series_choices, diffsynth_default_series, diffsynth_filepath = get_diffsynth_cn_defaults(controlnet_key)
|
| 224 |
+
for t_comp in diffsynth_cn_types:
|
| 225 |
+
updates[t_comp] = gr.update(choices=diffsynth_all_types, value=diffsynth_default_type)
|
| 226 |
+
for s_comp in diffsynth_cn_series:
|
| 227 |
+
updates[s_comp] = gr.update(choices=diffsynth_series_choices, value=diffsynth_default_series)
|
| 228 |
+
for f_comp in diffsynth_cn_filepaths:
|
| 229 |
+
updates[f_comp] = diffsynth_filepath
|
| 230 |
+
|
| 231 |
+
if ipa_preset and (arch_model_type in ["sdxl", "sd15", "sd35"]):
|
| 232 |
+
config = load_ipadapter_config()
|
| 233 |
+
ipa_arch_key = "SDXL" if arch_model_type in ["sdxl", "sd35"] else "SD1.5"
|
| 234 |
+
std_presets = config.get("IPAdapter_presets", {}).get(ipa_arch_key, [])
|
| 235 |
+
face_presets = config.get("IPAdapter_FaceID_presets", {}).get(ipa_arch_key, [])
|
| 236 |
+
all_ipa_presets = std_presets + face_presets
|
| 237 |
+
default_ipa = all_ipa_presets[0] if all_ipa_presets else None
|
| 238 |
+
updates[ipa_preset] = gr.update(choices=all_ipa_presets, value=default_ipa)
|
| 239 |
+
|
| 240 |
+
defaults = get_model_generation_defaults(model_name, arch_model_type, MODEL_DEFAULTS_CONFIG)
|
| 241 |
+
if steps_comp: updates[steps_comp] = gr.update(value=defaults.get('steps'))
|
| 242 |
+
if cfg_comp: updates[cfg_comp] = gr.update(value=defaults.get('cfg'))
|
| 243 |
+
if sampler_comp: updates[sampler_comp] = gr.update(value=defaults.get('sampler_name'))
|
| 244 |
+
if scheduler_comp: updates[scheduler_comp] = gr.update(value=defaults.get('scheduler'))
|
| 245 |
+
if prompt_comp: updates[prompt_comp] = gr.update(value=defaults.get('positive_prompt'))
|
| 246 |
+
if neg_prompt_comp: updates[neg_prompt_comp] = gr.update(value=defaults.get('negative_prompt'))
|
| 247 |
+
|
| 248 |
+
return updates
|
| 249 |
+
return change_fn
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
def initialize_all_cn_dropdowns(ui_components):
|
| 253 |
+
default_model_name = list(MODEL_MAP_CHECKPOINT.keys())[0] if MODEL_MAP_CHECKPOINT else None
|
| 254 |
+
default_m_type = MODEL_TYPE_MAP.get(default_model_name, "SDXL") if default_model_name else "SDXL"
|
| 255 |
+
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 256 |
+
controlnet_key = architectures_dict.get(default_m_type, {}).get("controlnet_key", default_m_type)
|
| 257 |
+
|
| 258 |
+
all_types, default_type, series_choices, default_series, filepath = get_cn_defaults(controlnet_key)
|
| 259 |
+
anima_all_types, anima_default_type, anima_series_choices, anima_default_series, anima_filepath = get_anima_cn_defaults()
|
| 260 |
+
diffsynth_all_types, diffsynth_default_type, diffsynth_series_choices, diffsynth_default_series, diffsynth_filepath = get_diffsynth_cn_defaults(controlnet_key)
|
| 261 |
+
|
| 262 |
+
updates = {}
|
| 263 |
+
for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]:
|
| 264 |
+
if f'controlnet_types_{prefix}' in ui_components:
|
| 265 |
+
for type_dd in ui_components[f'controlnet_types_{prefix}']:
|
| 266 |
+
updates[type_dd] = gr.update(choices=all_types, value=default_type)
|
| 267 |
+
for series_dd in ui_components[f'controlnet_series_{prefix}']:
|
| 268 |
+
updates[series_dd] = gr.update(choices=series_choices, value=default_series)
|
| 269 |
+
for filepath_state in ui_components[f'controlnet_filepaths_{prefix}']:
|
| 270 |
+
updates[filepath_state] = filepath
|
| 271 |
+
|
| 272 |
+
if f'anima_controlnet_lllite_types_{prefix}' in ui_components:
|
| 273 |
+
for type_dd in ui_components[f'anima_controlnet_lllite_types_{prefix}']:
|
| 274 |
+
updates[type_dd] = gr.update(choices=anima_all_types, value=anima_default_type)
|
| 275 |
+
for series_dd in ui_components[f'anima_controlnet_lllite_series_{prefix}']:
|
| 276 |
+
updates[series_dd] = gr.update(choices=anima_series_choices, value=anima_default_series)
|
| 277 |
+
for filepath_state in ui_components[f'anima_controlnet_lllite_filepaths_{prefix}']:
|
| 278 |
+
updates[filepath_state] = anima_filepath
|
| 279 |
+
|
| 280 |
+
if f'diffsynth_controlnet_types_{prefix}' in ui_components:
|
| 281 |
+
for type_dd in ui_components[f'diffsynth_controlnet_types_{prefix}']:
|
| 282 |
+
updates[type_dd] = gr.update(choices=diffsynth_all_types, value=diffsynth_default_type)
|
| 283 |
+
for series_dd in ui_components[f'diffsynth_controlnet_series_{prefix}']:
|
| 284 |
+
updates[series_dd] = gr.update(choices=diffsynth_series_choices, value=default_series)
|
| 285 |
+
for filepath_state in ui_components[f'diffsynth_controlnet_filepaths_{prefix}']:
|
| 286 |
+
updates[filepath_state] = diffsynth_filepath
|
| 287 |
+
|
| 288 |
+
return updates
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def initialize_all_ipa_dropdowns(ui_components):
|
| 292 |
+
config = load_ipadapter_config()
|
| 293 |
+
if not config: return {}
|
| 294 |
+
|
| 295 |
+
default_model_name = list(MODEL_MAP_CHECKPOINT.keys())[0] if MODEL_MAP_CHECKPOINT else None
|
| 296 |
+
default_m_type = MODEL_TYPE_MAP.get(default_model_name, "SDXL") if default_model_name else "SDXL"
|
| 297 |
+
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 298 |
+
arch_model_type = architectures_dict.get(default_m_type, {}).get("model_type", default_m_type.lower().replace(" ", "").replace(".", ""))
|
| 299 |
+
ipa_arch_key = "SDXL" if arch_model_type in ["sdxl", "sd35"] else "SD1.5"
|
| 300 |
+
|
| 301 |
+
unified_presets = config.get("IPAdapter_presets", {}).get(ipa_arch_key, [])
|
| 302 |
+
faceid_presets = config.get("IPAdapter_FaceID_presets", {}).get(ipa_arch_key, [])
|
| 303 |
+
|
| 304 |
+
all_presets = unified_presets + faceid_presets
|
| 305 |
+
default_preset = all_presets[0] if all_presets else None
|
| 306 |
+
is_faceid_default = default_preset in faceid_presets
|
| 307 |
+
|
| 308 |
+
lora_strength_update = gr.update(visible=is_faceid_default)
|
| 309 |
+
|
| 310 |
+
updates = {}
|
| 311 |
+
for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]:
|
| 312 |
+
if f'ipadapter_final_preset_{prefix}' in ui_components:
|
| 313 |
+
for lora_strength_slider in ui_components[f'ipadapter_lora_strengths_{prefix}']:
|
| 314 |
+
updates[lora_strength_slider] = lora_strength_update
|
| 315 |
+
updates[ui_components[f'ipadapter_final_preset_{prefix}']] = gr.update(choices=all_presets, value=default_preset)
|
| 316 |
+
updates[ui_components[f'ipadapter_final_lora_strength_{prefix}']] = lora_strength_update
|
| 317 |
+
return updates
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
def run_on_load(ui_components):
|
| 321 |
+
cn_updates = initialize_all_cn_dropdowns(ui_components)
|
| 322 |
+
ipa_updates = initialize_all_ipa_dropdowns(ui_components)
|
| 323 |
+
return {**cn_updates, **ipa_updates}
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
def on_aspect_ratio_change(ratio_key, model_display_name):
|
| 327 |
+
m_type = MODEL_TYPE_MAP.get(model_display_name, 'SDXL')
|
| 328 |
+
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 329 |
+
arch_model_type = architectures_dict.get(m_type, {}).get("model_type", m_type.lower().replace(" ", "").replace(".", ""))
|
| 330 |
+
|
| 331 |
+
res_map = RESOLUTION_MAP.get(arch_model_type, RESOLUTION_MAP.get("sdxl", {}))
|
| 332 |
+
w, h = res_map.get(ratio_key, (1024, 1024))
|
| 333 |
+
return w, h
|
ui/events/config_loaders.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import yaml
|
| 3 |
+
from functools import lru_cache
|
| 4 |
+
|
| 5 |
+
@lru_cache(maxsize=1)
|
| 6 |
+
def load_controlnet_config():
|
| 7 |
+
_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 8 |
+
_CN_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'controlnet_models.yaml')
|
| 9 |
+
try:
|
| 10 |
+
print("--- Loading controlnet_models.yaml ---")
|
| 11 |
+
with open(_CN_MODEL_LIST_PATH, 'r', encoding='utf-8') as f:
|
| 12 |
+
config = yaml.safe_load(f)
|
| 13 |
+
print("--- ✅ controlnet_models.yaml loaded successfully ---")
|
| 14 |
+
return config.get("ControlNet", {})
|
| 15 |
+
except Exception as e:
|
| 16 |
+
print(f"Error loading controlnet_models.yaml: {e}")
|
| 17 |
+
return {}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def get_cn_defaults(arch_val):
|
| 21 |
+
cn_full_config = load_controlnet_config()
|
| 22 |
+
cn_config = cn_full_config.get(arch_val, [])
|
| 23 |
+
|
| 24 |
+
if not cn_config:
|
| 25 |
+
return [], None, [], None, "None"
|
| 26 |
+
|
| 27 |
+
all_types = sorted(list(set(t for model in cn_config for t in model.get("Type", []))))
|
| 28 |
+
default_type = all_types[0] if all_types else None
|
| 29 |
+
|
| 30 |
+
series_choices = []
|
| 31 |
+
if default_type:
|
| 32 |
+
series_choices = sorted(list(set(model.get("Series", "Default") for model in cn_config if default_type in model.get("Type", []))))
|
| 33 |
+
default_series = series_choices[0] if series_choices else None
|
| 34 |
+
|
| 35 |
+
filepath = "None"
|
| 36 |
+
if default_series and default_type:
|
| 37 |
+
for model in cn_config:
|
| 38 |
+
if model.get("Series") == default_series and default_type in model.get("Type", []):
|
| 39 |
+
filepath = model.get("Filepath")
|
| 40 |
+
break
|
| 41 |
+
|
| 42 |
+
return all_types, default_type, series_choices, default_series, filepath
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
@lru_cache(maxsize=1)
|
| 46 |
+
def load_anima_controlnet_lllite_config():
|
| 47 |
+
_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 48 |
+
_CN_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'anima_controlnet_lllite_models.yaml')
|
| 49 |
+
try:
|
| 50 |
+
print("--- Loading anima_controlnet_lllite_models.yaml ---")
|
| 51 |
+
with open(_CN_MODEL_LIST_PATH, 'r', encoding='utf-8') as f:
|
| 52 |
+
config = yaml.safe_load(f)
|
| 53 |
+
print("--- ✅ anima_controlnet_lllite_models.yaml loaded successfully ---")
|
| 54 |
+
return config.get("Anima_ControlNet_Lllite", [])
|
| 55 |
+
except Exception as e:
|
| 56 |
+
print(f"Error loading anima_controlnet_lllite_models.yaml: {e}")
|
| 57 |
+
return []
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def get_anima_cn_defaults():
|
| 61 |
+
cn_config = load_anima_controlnet_lllite_config()
|
| 62 |
+
if not cn_config:
|
| 63 |
+
return [], None, [], None, "None"
|
| 64 |
+
all_types = sorted(list(set(t for model in cn_config for t in model.get("Type", []))))
|
| 65 |
+
default_type = all_types[0] if all_types else None
|
| 66 |
+
series_choices = []
|
| 67 |
+
if default_type:
|
| 68 |
+
series_choices = sorted(list(set(model.get("Series", "Default") for model in cn_config if default_type in model.get("Type", []))))
|
| 69 |
+
default_series = series_choices[0] if series_choices else None
|
| 70 |
+
filepath = "None"
|
| 71 |
+
if default_series and default_type:
|
| 72 |
+
for model in cn_config:
|
| 73 |
+
if model.get("Series") == default_series and default_type in model.get("Type", []):
|
| 74 |
+
filepath = model.get("Filepath")
|
| 75 |
+
break
|
| 76 |
+
return all_types, default_type, series_choices, default_series, filepath
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
@lru_cache(maxsize=1)
|
| 80 |
+
def load_diffsynth_controlnet_config():
|
| 81 |
+
_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 82 |
+
_CN_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'diffsynth_controlnet_models.yaml')
|
| 83 |
+
try:
|
| 84 |
+
print("--- Loading diffsynth_controlnet_models.yaml ---")
|
| 85 |
+
with open(_CN_MODEL_LIST_PATH, 'r', encoding='utf-8') as f:
|
| 86 |
+
config = yaml.safe_load(f)
|
| 87 |
+
print("--- ✅ diffsynth_controlnet_models.yaml loaded successfully ---")
|
| 88 |
+
return config.get("DiffSynth_ControlNet", {})
|
| 89 |
+
except Exception as e:
|
| 90 |
+
print(f"Error loading diffsynth_controlnet_models.yaml: {e}")
|
| 91 |
+
return {}
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def get_diffsynth_cn_defaults(arch_val):
|
| 95 |
+
cn_full_config = load_diffsynth_controlnet_config()
|
| 96 |
+
cn_config = cn_full_config.get(arch_val, [])
|
| 97 |
+
|
| 98 |
+
if not cn_config:
|
| 99 |
+
return [], None, [], None, "None"
|
| 100 |
+
|
| 101 |
+
all_types = sorted(list(set(t for model in cn_config for t in model.get("Type", []))))
|
| 102 |
+
default_type = all_types[0] if all_types else None
|
| 103 |
+
|
| 104 |
+
series_choices = []
|
| 105 |
+
if default_type:
|
| 106 |
+
series_choices = sorted(list(set(model.get("Series", "Default") for model in cn_config if default_type in model.get("Type", []))))
|
| 107 |
+
default_series = series_choices[0] if series_choices else None
|
| 108 |
+
|
| 109 |
+
filepath = "None"
|
| 110 |
+
if default_series and default_type:
|
| 111 |
+
for model in cn_config:
|
| 112 |
+
if model.get("Series") == default_series and default_type in model.get("Type", []):
|
| 113 |
+
filepath = model.get("Filepath")
|
| 114 |
+
break
|
| 115 |
+
|
| 116 |
+
return all_types, default_type, series_choices, default_series, filepath
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
@lru_cache(maxsize=1)
|
| 120 |
+
def load_ipadapter_config():
|
| 121 |
+
_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 122 |
+
_IPA_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'ipadapter.yaml')
|
| 123 |
+
try:
|
| 124 |
+
print("--- Loading ipadapter.yaml ---")
|
| 125 |
+
with open(_IPA_MODEL_LIST_PATH, 'r', encoding='utf-8') as f:
|
| 126 |
+
config = yaml.safe_load(f)
|
| 127 |
+
print("--- ✅ ipadapter.yaml loaded successfully ---")
|
| 128 |
+
return config
|
| 129 |
+
except Exception as e:
|
| 130 |
+
print(f"Error loading ipadapter.yaml: {e}")
|
| 131 |
+
return {}
|
ui/events/main.py
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from .chain_handlers import (
|
| 3 |
+
create_lora_event_handlers,
|
| 4 |
+
create_controlnet_event_handlers,
|
| 5 |
+
create_anima_controlnet_lllite_event_handlers,
|
| 6 |
+
create_diffsynth_controlnet_event_handlers,
|
| 7 |
+
create_ipadapter_event_handlers,
|
| 8 |
+
create_embedding_event_handlers,
|
| 9 |
+
create_conditioning_event_handlers,
|
| 10 |
+
create_flux1_ipadapter_event_handlers,
|
| 11 |
+
create_sd3_ipadapter_event_handlers,
|
| 12 |
+
create_style_event_handlers,
|
| 13 |
+
create_reference_latent_event_handlers,
|
| 14 |
+
create_hidream_o1_reference_event_handlers
|
| 15 |
+
)
|
| 16 |
+
from .change_handlers import (
|
| 17 |
+
make_update_fn,
|
| 18 |
+
make_model_change_fn,
|
| 19 |
+
run_on_load,
|
| 20 |
+
on_aspect_ratio_change
|
| 21 |
+
)
|
| 22 |
+
from .run_handlers import create_run_event
|
| 23 |
+
|
| 24 |
+
def attach_event_handlers(ui_components, demo):
|
| 25 |
+
for prefix, task_type in [
|
| 26 |
+
("txt2img", "txt2img"), ("img2img", "img2img"), ("inpaint", "inpaint"),
|
| 27 |
+
("outpaint", "outpaint"), ("hires_fix", "hires_fix"),
|
| 28 |
+
]:
|
| 29 |
+
|
| 30 |
+
arch_comp = ui_components.get(f'model_arch_{prefix}')
|
| 31 |
+
cat_comp = ui_components.get(f'model_cat_{prefix}')
|
| 32 |
+
model_comp = ui_components.get(f'base_model_{prefix}')
|
| 33 |
+
clip_skip_comp = ui_components.get(f'clip_skip_{prefix}') or ui_components.get(f'{prefix}_clip_skip')
|
| 34 |
+
guidance_comp = ui_components.get(f'guidance_{prefix}') or ui_components.get(f'{prefix}_guidance')
|
| 35 |
+
aspect_ratio_comp = ui_components.get(f'aspect_ratio_{prefix}') or ui_components.get(f'{prefix}_aspect_ratio_dropdown')
|
| 36 |
+
width_comp = ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width')
|
| 37 |
+
height_comp = ui_components.get(f'height_{prefix}') or ui_components.get(f'{prefix}_height')
|
| 38 |
+
|
| 39 |
+
cn_types_list = ui_components.get(f'controlnet_types_{prefix}', [])
|
| 40 |
+
cn_series_list = ui_components.get(f'controlnet_series_{prefix}', [])
|
| 41 |
+
cn_filepaths_list = ui_components.get(f'controlnet_filepaths_{prefix}', [])
|
| 42 |
+
|
| 43 |
+
anima_cn_types_list = ui_components.get(f'anima_controlnet_lllite_types_{prefix}', [])
|
| 44 |
+
anima_cn_series_list = ui_components.get(f'anima_controlnet_lllite_series_{prefix}', [])
|
| 45 |
+
anima_cn_filepaths_list = ui_components.get(f'anima_controlnet_lllite_filepaths_{prefix}', [])
|
| 46 |
+
|
| 47 |
+
diffsynth_cn_types_list = ui_components.get(f'diffsynth_controlnet_types_{prefix}', [])
|
| 48 |
+
diffsynth_cn_series_list = ui_components.get(f'diffsynth_controlnet_series_{prefix}', [])
|
| 49 |
+
diffsynth_cn_filepaths_list = ui_components.get(f'diffsynth_controlnet_filepaths_{prefix}', [])
|
| 50 |
+
|
| 51 |
+
lora_accordion = ui_components.get(f'lora_accordion_{prefix}')
|
| 52 |
+
cn_accordion = ui_components.get(f'controlnet_accordion_{prefix}')
|
| 53 |
+
anima_cn_accordion = ui_components.get(f'anima_controlnet_lllite_accordion_{prefix}')
|
| 54 |
+
diffsynth_cn_accordion = ui_components.get(f'diffsynth_controlnet_accordion_{prefix}')
|
| 55 |
+
ipa_accordion = ui_components.get(f'ipadapter_accordion_{prefix}')
|
| 56 |
+
sd3_ipa_accordion = ui_components.get(f'sd3_ipadapter_accordion_{prefix}')
|
| 57 |
+
flux1_ipa_accordion = ui_components.get(f'flux1_ipadapter_accordion_{prefix}')
|
| 58 |
+
style_accordion = ui_components.get(f'style_accordion_{prefix}')
|
| 59 |
+
embedding_accordion = ui_components.get(f'embedding_accordion_{prefix}')
|
| 60 |
+
conditioning_accordion = ui_components.get(f'conditioning_accordion_{prefix}')
|
| 61 |
+
ref_latent_accordion = ui_components.get(f'reference_latent_accordion_{prefix}')
|
| 62 |
+
hidream_o1_ref_accordion = ui_components.get(f'hidream_o1_reference_accordion_{prefix}')
|
| 63 |
+
|
| 64 |
+
ipa_preset_list = ui_components.get(f'ipadapter_final_preset_{prefix}')
|
| 65 |
+
|
| 66 |
+
prompt_comp = ui_components.get(f'prompt_{prefix}') or ui_components.get(f'{prefix}_positive_prompt')
|
| 67 |
+
neg_prompt_comp = ui_components.get(f'neg_prompt_{prefix}') or ui_components.get(f'{prefix}_negative_prompt')
|
| 68 |
+
steps_comp = ui_components.get(f'steps_{prefix}') or ui_components.get(f'{prefix}_steps')
|
| 69 |
+
cfg_comp = ui_components.get(f'cfg_{prefix}') or ui_components.get(f'{prefix}_cfg')
|
| 70 |
+
sampler_comp = ui_components.get(f'sampler_{prefix}') or ui_components.get(f'{prefix}_sampler_name')
|
| 71 |
+
scheduler_comp = ui_components.get(f'scheduler_{prefix}') or ui_components.get(f'{prefix}_scheduler')
|
| 72 |
+
|
| 73 |
+
extra_comps = [prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp, width_comp, height_comp]
|
| 74 |
+
valid_extra_comps = [c for c in extra_comps if c is not None]
|
| 75 |
+
|
| 76 |
+
if arch_comp and cat_comp and model_comp:
|
| 77 |
+
outputs = [model_comp, cat_comp]
|
| 78 |
+
if clip_skip_comp: outputs.append(clip_skip_comp)
|
| 79 |
+
if guidance_comp: outputs.append(guidance_comp)
|
| 80 |
+
if aspect_ratio_comp: outputs.append(aspect_ratio_comp)
|
| 81 |
+
outputs.extend(cn_types_list + cn_series_list + cn_filepaths_list)
|
| 82 |
+
outputs.extend(anima_cn_types_list + anima_cn_series_list + anima_cn_filepaths_list)
|
| 83 |
+
outputs.extend(diffsynth_cn_types_list + diffsynth_cn_series_list + diffsynth_cn_filepaths_list)
|
| 84 |
+
if lora_accordion: outputs.append(lora_accordion)
|
| 85 |
+
if cn_accordion: outputs.append(cn_accordion)
|
| 86 |
+
if anima_cn_accordion: outputs.append(anima_cn_accordion)
|
| 87 |
+
if diffsynth_cn_accordion: outputs.append(diffsynth_cn_accordion)
|
| 88 |
+
if ipa_accordion: outputs.append(ipa_accordion)
|
| 89 |
+
if sd3_ipa_accordion: outputs.append(sd3_ipa_accordion)
|
| 90 |
+
if flux1_ipa_accordion: outputs.append(flux1_ipa_accordion)
|
| 91 |
+
if style_accordion: outputs.append(style_accordion)
|
| 92 |
+
if embedding_accordion: outputs.append(embedding_accordion)
|
| 93 |
+
if conditioning_accordion: outputs.append(conditioning_accordion)
|
| 94 |
+
if ref_latent_accordion: outputs.append(ref_latent_accordion)
|
| 95 |
+
if hidream_o1_ref_accordion: outputs.append(hidream_o1_ref_accordion)
|
| 96 |
+
if ipa_preset_list: outputs.append(ipa_preset_list)
|
| 97 |
+
|
| 98 |
+
outputs.extend(valid_extra_comps)
|
| 99 |
+
|
| 100 |
+
update_fn = make_update_fn(
|
| 101 |
+
model_comp, cat_comp, clip_skip_comp, aspect_ratio_comp, width_comp, height_comp,
|
| 102 |
+
cn_types_list, cn_series_list, cn_filepaths_list,
|
| 103 |
+
anima_cn_types_list, anima_cn_series_list, anima_cn_filepaths_list,
|
| 104 |
+
diffsynth_cn_types_list, diffsynth_cn_series_list, diffsynth_cn_filepaths_list,
|
| 105 |
+
ipa_preset_list, lora_accordion, cn_accordion, anima_cn_accordion, diffsynth_cn_accordion, ipa_accordion, sd3_ipa_accordion, flux1_ipa_accordion, style_accordion, embedding_accordion, conditioning_accordion,
|
| 106 |
+
ref_latent_accordion, hidream_o1_ref_accordion, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp
|
| 107 |
+
)
|
| 108 |
+
inputs = [arch_comp, cat_comp]
|
| 109 |
+
if aspect_ratio_comp:
|
| 110 |
+
inputs.append(aspect_ratio_comp)
|
| 111 |
+
arch_comp.change(fn=update_fn, inputs=inputs, outputs=outputs)
|
| 112 |
+
cat_comp.change(fn=update_fn, inputs=inputs, outputs=outputs)
|
| 113 |
+
|
| 114 |
+
if model_comp:
|
| 115 |
+
outputs2 = []
|
| 116 |
+
if arch_comp: outputs2.append(arch_comp)
|
| 117 |
+
if cat_comp: outputs2.append(cat_comp)
|
| 118 |
+
if clip_skip_comp: outputs2.append(clip_skip_comp)
|
| 119 |
+
if guidance_comp: outputs2.append(guidance_comp)
|
| 120 |
+
if aspect_ratio_comp: outputs2.append(aspect_ratio_comp)
|
| 121 |
+
outputs2.extend(cn_types_list + cn_series_list + cn_filepaths_list)
|
| 122 |
+
outputs2.extend(anima_cn_types_list + anima_cn_series_list + anima_cn_filepaths_list)
|
| 123 |
+
outputs2.extend(diffsynth_cn_types_list + diffsynth_cn_series_list + diffsynth_cn_filepaths_list)
|
| 124 |
+
if lora_accordion: outputs2.append(lora_accordion)
|
| 125 |
+
if cn_accordion: outputs2.append(cn_accordion)
|
| 126 |
+
if anima_cn_accordion: outputs2.append(anima_cn_accordion)
|
| 127 |
+
if diffsynth_cn_accordion: outputs2.append(diffsynth_cn_accordion)
|
| 128 |
+
if ipa_accordion: outputs2.append(ipa_accordion)
|
| 129 |
+
if sd3_ipa_accordion: outputs2.append(sd3_ipa_accordion)
|
| 130 |
+
if flux1_ipa_accordion: outputs2.append(flux1_ipa_accordion)
|
| 131 |
+
if style_accordion: outputs2.append(style_accordion)
|
| 132 |
+
if embedding_accordion: outputs2.append(embedding_accordion)
|
| 133 |
+
if conditioning_accordion: outputs2.append(conditioning_accordion)
|
| 134 |
+
if ref_latent_accordion: outputs2.append(ref_latent_accordion)
|
| 135 |
+
if hidream_o1_ref_accordion: outputs2.append(hidream_o1_ref_accordion)
|
| 136 |
+
if ipa_preset_list: outputs2.append(ipa_preset_list)
|
| 137 |
+
|
| 138 |
+
outputs2.extend(valid_extra_comps)
|
| 139 |
+
|
| 140 |
+
if outputs2:
|
| 141 |
+
inputs2 = [model_comp]
|
| 142 |
+
if arch_comp: inputs2.append(arch_comp)
|
| 143 |
+
if cat_comp: inputs2.append(cat_comp)
|
| 144 |
+
if aspect_ratio_comp: inputs2.append(aspect_ratio_comp)
|
| 145 |
+
change_fn = make_model_change_fn(
|
| 146 |
+
cat_comp, clip_skip_comp, aspect_ratio_comp, width_comp, height_comp,
|
| 147 |
+
cn_types_list, cn_series_list, cn_filepaths_list,
|
| 148 |
+
anima_cn_types_list, anima_cn_series_list, anima_cn_filepaths_list,
|
| 149 |
+
diffsynth_cn_types_list, diffsynth_cn_series_list, diffsynth_cn_filepaths_list,
|
| 150 |
+
arch_comp, ipa_preset_list, lora_accordion, cn_accordion, anima_cn_accordion, diffsynth_cn_accordion, ipa_accordion, sd3_ipa_accordion, flux1_ipa_accordion, style_accordion, embedding_accordion, conditioning_accordion,
|
| 151 |
+
ref_latent_accordion, hidream_o1_ref_accordion, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp
|
| 152 |
+
)
|
| 153 |
+
model_comp.change(fn=change_fn, inputs=inputs2, outputs=outputs2)
|
| 154 |
+
|
| 155 |
+
create_lora_event_handlers(prefix, ui_components)
|
| 156 |
+
create_controlnet_event_handlers(prefix, ui_components)
|
| 157 |
+
create_anima_controlnet_lllite_event_handlers(prefix, ui_components)
|
| 158 |
+
create_diffsynth_controlnet_event_handlers(prefix, ui_components)
|
| 159 |
+
create_ipadapter_event_handlers(prefix, ui_components)
|
| 160 |
+
create_embedding_event_handlers(prefix, ui_components)
|
| 161 |
+
create_conditioning_event_handlers(prefix, ui_components)
|
| 162 |
+
create_flux1_ipadapter_event_handlers(prefix, ui_components)
|
| 163 |
+
create_sd3_ipadapter_event_handlers(prefix, ui_components)
|
| 164 |
+
create_style_event_handlers(prefix, ui_components)
|
| 165 |
+
create_reference_latent_event_handlers(prefix, ui_components)
|
| 166 |
+
create_hidream_o1_reference_event_handlers(prefix, ui_components)
|
| 167 |
+
create_run_event(prefix, task_type, ui_components)
|
| 168 |
+
|
| 169 |
+
if 'view_mode_inpaint' in ui_components:
|
| 170 |
+
def toggle_inpaint_fullscreen_view(view_mode):
|
| 171 |
+
is_fullscreen = (view_mode == "Fullscreen View")
|
| 172 |
+
other_elements_visible = not is_fullscreen
|
| 173 |
+
editor_height = 800 if is_fullscreen else 272
|
| 174 |
+
|
| 175 |
+
updates = {
|
| 176 |
+
ui_components['prompts_column_inpaint']: gr.update(visible=other_elements_visible),
|
| 177 |
+
ui_components['params_and_gallery_row_inpaint']: gr.update(visible=other_elements_visible),
|
| 178 |
+
ui_components['accordion_wrapper_inpaint']: gr.update(visible=other_elements_visible),
|
| 179 |
+
ui_components['input_image_dict_inpaint']: gr.update(height=editor_height),
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
model_and_run_rows = ui_components.get('model_and_run_row_inpaint', [])
|
| 183 |
+
for row in model_and_run_rows:
|
| 184 |
+
updates[row] = gr.update(visible=other_elements_visible)
|
| 185 |
+
|
| 186 |
+
return updates
|
| 187 |
+
|
| 188 |
+
output_components = []
|
| 189 |
+
model_and_run_rows = ui_components.get('model_and_run_row_inpaint', [])
|
| 190 |
+
if isinstance(model_and_run_rows, list):
|
| 191 |
+
output_components.extend(model_and_run_rows)
|
| 192 |
+
else:
|
| 193 |
+
output_components.append(model_and_run_rows)
|
| 194 |
+
|
| 195 |
+
output_components.extend([
|
| 196 |
+
ui_components['prompts_column_inpaint'],
|
| 197 |
+
ui_components['params_and_gallery_row_inpaint'],
|
| 198 |
+
ui_components['accordion_wrapper_inpaint'],
|
| 199 |
+
ui_components['input_image_dict_inpaint']
|
| 200 |
+
])
|
| 201 |
+
|
| 202 |
+
ui_components['view_mode_inpaint'].change(
|
| 203 |
+
fn=toggle_inpaint_fullscreen_view,
|
| 204 |
+
inputs=[ui_components['view_mode_inpaint']],
|
| 205 |
+
outputs=output_components,
|
| 206 |
+
show_progress=False
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
all_load_outputs = []
|
| 210 |
+
for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]:
|
| 211 |
+
if f'controlnet_types_{prefix}' in ui_components:
|
| 212 |
+
all_load_outputs.extend(ui_components[f'controlnet_types_{prefix}'])
|
| 213 |
+
all_load_outputs.extend(ui_components[f'controlnet_series_{prefix}'])
|
| 214 |
+
all_load_outputs.extend(ui_components[f'controlnet_filepaths_{prefix}'])
|
| 215 |
+
if f'anima_controlnet_lllite_types_{prefix}' in ui_components:
|
| 216 |
+
all_load_outputs.extend(ui_components[f'anima_controlnet_lllite_types_{prefix}'])
|
| 217 |
+
all_load_outputs.extend(ui_components[f'anima_controlnet_lllite_series_{prefix}'])
|
| 218 |
+
all_load_outputs.extend(ui_components[f'anima_controlnet_lllite_filepaths_{prefix}'])
|
| 219 |
+
if f'diffsynth_controlnet_types_{prefix}' in ui_components:
|
| 220 |
+
all_load_outputs.extend(ui_components[f'diffsynth_controlnet_types_{prefix}'])
|
| 221 |
+
all_load_outputs.extend(ui_components[f'diffsynth_controlnet_series_{prefix}'])
|
| 222 |
+
all_load_outputs.extend(ui_components[f'diffsynth_controlnet_filepaths_{prefix}'])
|
| 223 |
+
if f'ipadapter_final_preset_{prefix}' in ui_components:
|
| 224 |
+
all_load_outputs.extend(ui_components[f'ipadapter_lora_strengths_{prefix}'])
|
| 225 |
+
all_load_outputs.append(ui_components[f'ipadapter_final_preset_{prefix}'])
|
| 226 |
+
all_load_outputs.append(ui_components[f'ipadapter_final_lora_strength_{prefix}'])
|
| 227 |
+
|
| 228 |
+
if all_load_outputs:
|
| 229 |
+
demo.load(
|
| 230 |
+
fn=lambda: run_on_load(ui_components),
|
| 231 |
+
outputs=all_load_outputs
|
| 232 |
+
)
|
| 233 |
+
|
| 234 |
+
for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]:
|
| 235 |
+
aspect_ratio_dropdown = ui_components.get(f'aspect_ratio_{prefix}') or ui_components.get(f'{prefix}_aspect_ratio_dropdown')
|
| 236 |
+
width_component = ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width')
|
| 237 |
+
height_component = ui_components.get(f'height_{prefix}') or ui_components.get(f'{prefix}_height')
|
| 238 |
+
model_dropdown = ui_components.get(f'base_model_{prefix}')
|
| 239 |
+
if aspect_ratio_dropdown and width_component and height_component and model_dropdown:
|
| 240 |
+
aspect_ratio_dropdown.change(fn=on_aspect_ratio_change, inputs=[aspect_ratio_dropdown, model_dropdown], outputs=[width_component, height_component], show_progress=False)
|
ui/events/run_handlers.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from core.generation_logic import generate_image_wrapper
|
| 3 |
+
|
| 4 |
+
def create_run_event(prefix: str, task_type: str, ui_components: dict):
|
| 5 |
+
run_inputs_map = {
|
| 6 |
+
'model_display_name': ui_components[f'base_model_{prefix}'],
|
| 7 |
+
'positive_prompt': ui_components.get(f'prompt_{prefix}') or ui_components.get(f'{prefix}_positive_prompt'),
|
| 8 |
+
'negative_prompt': ui_components.get(f'neg_prompt_{prefix}') or ui_components.get(f'{prefix}_negative_prompt'),
|
| 9 |
+
'seed': ui_components.get(f'seed_{prefix}') or ui_components.get(f'{prefix}_seed'),
|
| 10 |
+
'batch_size': ui_components.get(f'batch_size_{prefix}') or ui_components.get(f'{prefix}_batch_size'),
|
| 11 |
+
'guidance_scale': ui_components.get(f'cfg_{prefix}') or ui_components.get(f'{prefix}_cfg'),
|
| 12 |
+
'num_inference_steps': ui_components.get(f'steps_{prefix}') or ui_components.get(f'{prefix}_steps'),
|
| 13 |
+
'sampler': ui_components.get(f'sampler_{prefix}') or ui_components.get(f'{prefix}_sampler_name'),
|
| 14 |
+
'scheduler': ui_components.get(f'scheduler_{prefix}') or ui_components.get(f'{prefix}_scheduler'),
|
| 15 |
+
'zero_gpu_duration': ui_components.get(f'zero_gpu_{prefix}'),
|
| 16 |
+
|
| 17 |
+
'clip_skip': ui_components.get(f'clip_skip_{prefix}'),
|
| 18 |
+
'guidance': ui_components.get(f'guidance_{prefix}'),
|
| 19 |
+
'task_type': gr.State(task_type)
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
if task_type not in ['img2img', 'inpaint']:
|
| 23 |
+
run_inputs_map.update({
|
| 24 |
+
'width': ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width'),
|
| 25 |
+
'height': ui_components.get(f'height_{prefix}') or ui_components.get(f'{prefix}_height')
|
| 26 |
+
})
|
| 27 |
+
|
| 28 |
+
task_specific_map = {
|
| 29 |
+
'img2img': {'img2img_image': f'input_image_{prefix}', 'img2img_denoise': f'denoise_{prefix}'},
|
| 30 |
+
'inpaint': {'inpaint_image_dict': f'input_image_dict_{prefix}', 'grow_mask_by': f'grow_mask_by_{prefix}'},
|
| 31 |
+
'outpaint': {'outpaint_image': f'input_image_{prefix}', 'left': f'left_{prefix}', 'top': f'top_{prefix}', 'right': f'right_{prefix}', 'bottom': f'bottom_{prefix}', 'feathering': f'feathering_{prefix}'},
|
| 32 |
+
'hires_fix': {'hires_image': f'input_image_{prefix}', 'hires_upscaler': f'hires_upscaler_{prefix}', 'hires_scale_by': f'hires_scale_by_{prefix}', 'hires_denoise': f'denoise_{prefix}'}
|
| 33 |
+
}
|
| 34 |
+
if task_type in task_specific_map:
|
| 35 |
+
for key, comp_name in task_specific_map[task_type].items():
|
| 36 |
+
if comp_name in ui_components:
|
| 37 |
+
run_inputs_map[key] = ui_components[comp_name]
|
| 38 |
+
|
| 39 |
+
lora_data_components = ui_components.get(f'all_lora_components_flat_{prefix}', [])
|
| 40 |
+
controlnet_data_components = ui_components.get(f'all_controlnet_components_flat_{prefix}', [])
|
| 41 |
+
anima_controlnet_lllite_data_components = ui_components.get(f'all_anima_controlnet_lllite_components_flat_{prefix}', [])
|
| 42 |
+
diffsynth_controlnet_data_components = ui_components.get(f'all_diffsynth_controlnet_components_flat_{prefix}', [])
|
| 43 |
+
ipadapter_data_components = ui_components.get(f'all_ipadapter_components_flat_{prefix}', [])
|
| 44 |
+
sd3_ipadapter_data_components = ui_components.get(f'all_sd3_ipadapter_components_flat_{prefix}', [])
|
| 45 |
+
flux1_ipadapter_data_components = ui_components.get(f'all_flux1_ipadapter_components_flat_{prefix}', [])
|
| 46 |
+
style_data_components = ui_components.get(f'all_style_components_flat_{prefix}', [])
|
| 47 |
+
embedding_data_components = ui_components.get(f'all_embedding_components_flat_{prefix}', [])
|
| 48 |
+
conditioning_data_components = ui_components.get(f'all_conditioning_components_flat_{prefix}', [])
|
| 49 |
+
reference_latent_data_components = ui_components.get(f'all_reference_latent_components_flat_{prefix}', [])
|
| 50 |
+
hidream_o1_reference_data_components = ui_components.get(f'all_hidream_o1_reference_components_flat_{prefix}', [])
|
| 51 |
+
|
| 52 |
+
run_inputs_map['vae_source'] = ui_components.get(f'vae_source_{prefix}')
|
| 53 |
+
run_inputs_map['vae_id'] = ui_components.get(f'vae_id_{prefix}')
|
| 54 |
+
run_inputs_map['vae_file'] = ui_components.get(f'vae_file_{prefix}')
|
| 55 |
+
|
| 56 |
+
input_keys = list(run_inputs_map.keys())
|
| 57 |
+
input_list_flat = [v for v in run_inputs_map.values() if v is not None]
|
| 58 |
+
all_chains = [
|
| 59 |
+
lora_data_components, controlnet_data_components, anima_controlnet_lllite_data_components, diffsynth_controlnet_data_components, ipadapter_data_components,
|
| 60 |
+
sd3_ipadapter_data_components, flux1_ipadapter_data_components, style_data_components,
|
| 61 |
+
embedding_data_components, conditioning_data_components, reference_latent_data_components, hidream_o1_reference_data_components
|
| 62 |
+
]
|
| 63 |
+
for chain in all_chains:
|
| 64 |
+
if chain:
|
| 65 |
+
input_list_flat.extend(chain)
|
| 66 |
+
|
| 67 |
+
def create_ui_inputs_dict(*args):
|
| 68 |
+
valid_keys = [k for k in input_keys if run_inputs_map[k] is not None]
|
| 69 |
+
ui_dict = dict(zip(valid_keys, args[:len(valid_keys)]))
|
| 70 |
+
arg_idx = len(valid_keys)
|
| 71 |
+
|
| 72 |
+
def assign_chain_data(chain_key, components_list):
|
| 73 |
+
nonlocal arg_idx
|
| 74 |
+
if components_list:
|
| 75 |
+
ui_dict[chain_key] = list(args[arg_idx : arg_idx + len(components_list)])
|
| 76 |
+
arg_idx += len(components_list)
|
| 77 |
+
|
| 78 |
+
assign_chain_data('lora_data', lora_data_components)
|
| 79 |
+
assign_chain_data('controlnet_data', controlnet_data_components)
|
| 80 |
+
assign_chain_data('anima_controlnet_lllite_data', anima_controlnet_lllite_data_components)
|
| 81 |
+
assign_chain_data('diffsynth_controlnet_data', diffsynth_controlnet_data_components)
|
| 82 |
+
assign_chain_data('ipadapter_data', ipadapter_data_components)
|
| 83 |
+
assign_chain_data('sd3_ipadapter_chain', sd3_ipadapter_data_components)
|
| 84 |
+
assign_chain_data('flux1_ipadapter_data', flux1_ipadapter_data_components)
|
| 85 |
+
assign_chain_data('style_data', style_data_components)
|
| 86 |
+
assign_chain_data('embedding_data', embedding_data_components)
|
| 87 |
+
assign_chain_data('conditioning_data', conditioning_data_components)
|
| 88 |
+
assign_chain_data('reference_latent_data', reference_latent_data_components)
|
| 89 |
+
assign_chain_data('hidream_o1_reference_data', hidream_o1_reference_data_components)
|
| 90 |
+
|
| 91 |
+
return ui_dict
|
| 92 |
+
|
| 93 |
+
run_btn = ui_components.get(f'run_{prefix}') or ui_components.get(f'{prefix}_run_button')
|
| 94 |
+
res_gal = ui_components.get(f'result_{prefix}') or ui_components.get(f'{prefix}_output_gallery')
|
| 95 |
+
if run_btn and res_gal:
|
| 96 |
+
run_btn.click(
|
| 97 |
+
fn=lambda *args, progress=gr.Progress(track_tqdm=True): generate_image_wrapper(create_ui_inputs_dict(*args), progress),
|
| 98 |
+
inputs=input_list_flat,
|
| 99 |
+
outputs=[res_gal]
|
| 100 |
+
)
|
yaml/file_list.yaml
CHANGED
|
@@ -111,10 +111,10 @@ file:
|
|
| 111 |
source: hf
|
| 112 |
repo_id: "bluepen5805/pony_pencil-XL"
|
| 113 |
repository_file_path: "pony_pencil-XL-v2.0.0.safetensors"
|
| 114 |
-
- filename: "
|
| 115 |
source: hf
|
| 116 |
repo_id: "cyberdelia/CyberRealisticPony"
|
| 117 |
-
repository_file_path: "
|
| 118 |
# SDXL-Base
|
| 119 |
- filename: "sd_xl_base_1.0.safetensors"
|
| 120 |
source: "hf"
|
|
|
|
| 111 |
source: hf
|
| 112 |
repo_id: "bluepen5805/pony_pencil-XL"
|
| 113 |
repository_file_path: "pony_pencil-XL-v2.0.0.safetensors"
|
| 114 |
+
- filename: "CyberRealisticPony_V17.0_FP16.safetensors"
|
| 115 |
source: hf
|
| 116 |
repo_id: "cyberdelia/CyberRealisticPony"
|
| 117 |
+
repository_file_path: "CyberRealisticPony_V17.0_FP16.safetensors"
|
| 118 |
# SDXL-Base
|
| 119 |
- filename: "sd_xl_base_1.0.safetensors"
|
| 120 |
source: "hf"
|
yaml/model_list.yaml
CHANGED
|
@@ -305,8 +305,8 @@ Checkpoint:
|
|
| 305 |
- display_name: "blue_pen5805/pony_pencil-XL v2.0.0"
|
| 306 |
path: "pony_pencil-XL-v2.0.0.safetensors"
|
| 307 |
category: "Pony"
|
| 308 |
-
- display_name: "Cyberdelia/CyberRealistic Pony
|
| 309 |
-
path: "
|
| 310 |
category: "Pony"
|
| 311 |
# SDXL-Base
|
| 312 |
- display_name: "stabilityai/stable-diffusion-xl-base-1.0"
|
|
|
|
| 305 |
- display_name: "blue_pen5805/pony_pencil-XL v2.0.0"
|
| 306 |
path: "pony_pencil-XL-v2.0.0.safetensors"
|
| 307 |
category: "Pony"
|
| 308 |
+
- display_name: "Cyberdelia/CyberRealistic Pony v17.0"
|
| 309 |
+
path: "CyberRealisticPony_V17.0_FP16.safetensors"
|
| 310 |
category: "Pony"
|
| 311 |
# SDXL-Base
|
| 312 |
- display_name: "stabilityai/stable-diffusion-xl-base-1.0"
|