Add Qwen-Image Edit injector.
Browse filesFiles changed (20)
- README.md+6
- chain_injectors/qwen_image_edit_injector.pyAdded+156
- core/pipelines/pipeline_input_processor.py+12
- core/pipelines/sd_image_pipeline.py+2
- core/pipelines/workflow_recipes/_partials/conditioning/qwen-image.yaml+9
- ui/events/chain_handlers.py+924-891
- ui/events/change_handlers.py+4-2
- ui/events/main.py+284-279
- ui/events/run_handlers.py+3-1
- ui/shared/hires_fix_ui.py+2-1
- ui/shared/img2img_ui.py+2-1
- ui/shared/inpaint_ui.py+2-1
- ui/shared/outpaint_ui.py+2-1
- ui/shared/txt2img_ui.py+2-1
- ui/shared/ui_components.py+29
- yaml/file_list.yaml+21
- yaml/image_gen_features.yaml+1
- yaml/injectors.yaml+3
- yaml/model_defaults.yaml+6
- yaml/model_list.yaml+25
57 unmodified lines5859606162636431 unmodified lines9697989910010110210356 unmodified lines16016116216316416516616716857 unmodified lines - Comfy-Org/Ovis-Image
- Comfy-Org/PixelDiT
- Comfy-Org/Qwen-Image_ComfyUI
- Comfy-Org/Qwen-Image-Edit_ComfyUI
- Comfy-Org/sigclip_vision_384
- Comfy-Org/stable-diffusion-3.5-fp8
- Comfy-Org/vae-text-encorder-for-flux-klein-4b31 unmodified lines - Laxhar/noobai-XL-1.1
- Laxhar/noobai-XL-Vpred-1.0
- licyk/sd_control_collection
- lightx2v/Qwen-Image-2512-Lightning
- lightx2v/Qwen-Image-Edit-2511-Lightning
- LyliaEngine/Pony_Diffusion_V6_XL
- MIC-Lab/illustriousXLv0.1_controlnet
- MIC-Lab/illustriousXLv1.1_controlnet56 unmodified lines - OmniGen2/OmniGen2
- Qwen/Qwen-Image
- Qwen/Qwen-Image-2512
- Qwen/Qwen-Image-Edit
- Qwen/Qwen-Image-Edit-2509
- Qwen/Qwen-Image-Edit-2511
- stabilityai/stable-diffusion-3.5-large
- stabilityai/stable-diffusion-3.5-medium
- tencent/HunyuanImage-2.1123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156import os
def create_node(assembler, class_type, title): try: node = assembler._get_node_template(class_type) except Exception: node = { "inputs": {}, "class_type": class_type, "_meta": {"title": title} } node['_meta']['title'] = title return node
def inject(assembler, chain_definition, chain_items): if not chain_items: return
valid_images = [] for item in chain_items: if not item: continue img_path = item if isinstance(item, dict): img_path = item.get('image') or item.get('filename') or item.get('path') if img_path: valid_images.append(img_path)
if not valid_images: return
valid_images = valid_images[:3]
ksampler_name = chain_definition.get('ksampler_node', 'ksampler') pos_prompt_name = chain_definition.get('pos_prompt_node', 'pos_prompt') neg_prompt_name = chain_definition.get('neg_prompt_node', 'neg_prompt') clip_loader_name = chain_definition.get('clip_loader_node', 'clip_loader') vae_loader_name = chain_definition.get('vae_loader_node', 'vae_loader') model_sampler_name = chain_definition.get('model_sampler_node', 'model_sampler')
if ksampler_name not in assembler.node_map: print(f"Warning: Target node '{ksampler_name}' for Qwen-Image Edit chain not found. Skipping.") return
ksampler_id = assembler.node_map[ksampler_name]
if 'model' not in assembler.workflow[ksampler_id]['inputs']: print(f"Warning: KSampler node '{ksampler_name}' is missing 'model' input. Skipping.") return
vae_connection = None if vae_loader_name in assembler.node_map: vae_connection = [assembler.node_map[vae_loader_name], 0] else: for node_id, node in assembler.workflow.items(): if isinstance(node, dict) and node.get('class_type') == 'VAELoader': vae_connection = [node_id, 0] break
clip_connection = None if clip_loader_name in assembler.node_map: clip_connection = [assembler.node_map[clip_loader_name], 0] elif pos_prompt_name in assembler.node_map: pos_id = assembler.node_map[pos_prompt_name] clip_connection = assembler.workflow[pos_id]['inputs'].get('clip')
pos_prompt_id = assembler.node_map.get(pos_prompt_name) neg_prompt_id = assembler.node_map.get(neg_prompt_name)
pos_text = "" if pos_prompt_id and pos_prompt_id in assembler.workflow: pos_text = assembler.workflow[pos_prompt_id]['inputs'].get('text', '')
neg_text = "" if neg_prompt_id and neg_prompt_id in assembler.workflow: neg_text = assembler.workflow[neg_prompt_id]['inputs'].get('text', '')
scaled_image_ids = [] for i, img_filename in enumerate(valid_images): load_id = assembler._get_unique_id() load_node = create_node(assembler, "LoadImage", f"Load Reference Image {i+1}") load_node['inputs']['image'] = img_filename assembler.workflow[load_id] = load_node
scale_id = assembler._get_unique_id() scale_node = create_node(assembler, "ImageScaleToTotalPixels", f"Scale Reference {i+1}") scale_node['inputs']['upscale_method'] = "lanczos" scale_node['inputs']['megapixels'] = 1 scale_node['inputs']['resolution_steps'] = 1 scale_node['inputs']['image'] = [load_id, 0] assembler.workflow[scale_id] = scale_node scaled_image_ids.append(scale_id)
pos_encode_id = assembler._get_unique_id() pos_encode_node = create_node(assembler, "TextEncodeQwenImageEditPlus", "TextEncodeQwenImageEditPlus (Positive)") pos_encode_node['inputs']['prompt'] = pos_text if clip_connection: pos_encode_node['inputs']['clip'] = clip_connection if vae_connection: pos_encode_node['inputs']['vae'] = vae_connection for idx, s_id in enumerate(scaled_image_ids): pos_encode_node['inputs'][f"image{idx+1}"] = [s_id, 0] assembler.workflow[pos_encode_id] = pos_encode_node
neg_encode_id = assembler._get_unique_id() neg_encode_node = create_node(assembler, "TextEncodeQwenImageEditPlus", "TextEncodeQwenImageEditPlus") neg_encode_node['inputs']['prompt'] = neg_text if clip_connection: neg_encode_node['inputs']['clip'] = clip_connection if vae_connection: neg_encode_node['inputs']['vae'] = vae_connection for idx, s_id in enumerate(scaled_image_ids): neg_encode_node['inputs'][f"image{idx+1}"] = [s_id, 0] assembler.workflow[neg_encode_id] = neg_encode_node
pos_ref_id = assembler._get_unique_id() pos_ref_node = create_node(assembler, "FluxKontextMultiReferenceLatentMethod", "Edit Model Reference Method") pos_ref_node['inputs']['reference_latents_method'] = "index_timestep_zero" pos_ref_node['inputs']['conditioning'] = [pos_encode_id, 0] assembler.workflow[pos_ref_id] = pos_ref_node
neg_ref_id = assembler._get_unique_id() neg_ref_node = create_node(assembler, "FluxKontextMultiReferenceLatentMethod", "Edit Model Reference Method") neg_ref_node['inputs']['reference_latents_method'] = "index_timestep_zero" neg_ref_node['inputs']['conditioning'] = [neg_encode_id, 0] assembler.workflow[neg_ref_id] = neg_ref_node
assembler.workflow[ksampler_id]['inputs']['positive'] = [pos_ref_id, 0] assembler.workflow[ksampler_id]['inputs']['negative'] = [neg_ref_id, 0]
model_sampler_id = assembler.node_map.get(model_sampler_name) if not model_sampler_id: for node_id, node in assembler.workflow.items(): if isinstance(node, dict) and node.get('class_type') == 'ModelSamplingAuraFlow': model_sampler_id = node_id break
if model_sampler_id and model_sampler_id in assembler.workflow: assembler.workflow[model_sampler_id]['inputs']['shift'] = 3
current_model_connection = assembler.workflow[ksampler_id]['inputs']['model'] cfg_norm_id = assembler._get_unique_id() cfg_norm_node = create_node(assembler, "CFGNorm", "CFGNorm") cfg_norm_node['inputs']['strength'] = 1 cfg_norm_node['inputs']['pre_cfg'] = False cfg_norm_node['inputs']['model'] = current_model_connection assembler.workflow[cfg_norm_id] = cfg_norm_node assembler.workflow[ksampler_id]['inputs']['model'] = [cfg_norm_id, 0]
if pos_prompt_id and pos_prompt_id in assembler.workflow: del assembler.workflow[pos_prompt_id]
if neg_prompt_id and neg_prompt_id in assembler.workflow: del assembler.workflow[neg_prompt_id]
print(f"Qwen-Image Edit injector applied with {len(valid_images)} reference image(s). Original CLIPTextEncode nodes replaced.")367 unmodified lines36836937037137237337437537637737837938038138238338448 unmodified lines433434435436437438439367 unmodified lines temp_files_to_clean.append(temp_path)
active_krea2_identity_edit.append(os.path.basename(temp_path))
qwen_image_edit_data = ui_inputs.get('qwen_image_edit_data', [])
active_qwen_image_edit = []
if qwen_image_edit_data:
for img in qwen_image_edit_data:
if img:
if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR)
temp_path = os.path.join(INPUT_DIR, f"temp_qwen_edit_ref_{random.randint(1000, 9999)}.png")
img.save(temp_path, "PNG")
temp_files_to_clean.append(temp_path)
active_qwen_image_edit.append(os.path.basename(temp_path))
reference_image_data = ui_inputs.get('reference_image_data', [])
active_reference_images = []
if reference_image_data:48 unmodified lines "active_hidream_o1_reference": active_hidream_o1_reference,
"active_joyai_reference": active_joyai_reference,
"active_krea2_identity_edit": active_krea2_identity_edit,
"active_qwen_image_edit": active_qwen_image_edit,
"active_reference_images": active_reference_images,
"active_conditioning": active_conditioning,
"temp_files_to_clean": temp_files_to_clean117 unmodified lines11811912012112212312453 unmodified lines178179180181182183184117 unmodified lines active_hidream_o1_reference = processed["active_hidream_o1_reference"]
active_joyai_reference = processed.get("active_joyai_reference", [])
active_krea2_identity_edit = processed.get("active_krea2_identity_edit", [])
active_qwen_image_edit = processed.get("active_qwen_image_edit", [])
active_reference_images = processed.get("active_reference_images", [])
active_conditioning = processed["active_conditioning"]
53 unmodified lines "hidream_o1_reference_chain": active_hidream_o1_reference,
"joyai_reference_chain": active_joyai_reference,
"krea2_identity_edit_chain": active_krea2_identity_edit,
"qwen_image_edit_chain": active_qwen_image_edit,
"reference_image_chain": active_reference_images,
"vae_chain": [ui_inputs.get('vae_name')] if ui_inputs.get('vae_name') else [],
"hidream_o1_smoothing_chain": hidream_o1_smoothing_data,70 unmodified lines71727374757677787980818283848570 unmodified lines ksampler_node: "ksampler"
clip_source: "clip_loader:0"
dynamic_qwen_image_edit_chains:
qwen_image_edit_chain:
ksampler_node: "ksampler"
pos_prompt_node: "pos_prompt"
neg_prompt_node: "neg_prompt"
clip_loader_node: "clip_loader"
vae_loader_node: "vae_loader"
model_sampler_node: "model_sampler"
dynamic_pid_chains:
pid_chain:
ksampler_node: "ksampler"123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925import gradio as grfrom core.settings import VAE_DIR, LORA_DIR, EMBEDDING_DIR, ARCHITECTURES_CONFIGfrom utils.app_utils import save_uploaded_file_with_hashfrom ui.shared.ui_components import ( MAX_CONTROLNETS, MAX_IPADAPTERS, MAX_EMBEDDINGS, MAX_CONDITIONINGS, MAX_LORAS)from .config_loaders import ( load_controlnet_config, load_anima_controlnet_lllite_config, load_diffsynth_controlnet_config, load_krea2_controlnet_config, load_ipadapter_config)
def on_vae_upload(file_obj): if not file_obj: return gr.update(), gr.update(), None hashed_filename = save_uploaded_file_with_hash(file_obj, VAE_DIR) return hashed_filename, "File", file_obj
def on_lora_upload(file_obj): if not file_obj: return gr.update(), gr.update() hashed_filename = save_uploaded_file_with_hash(file_obj, LORA_DIR) return hashed_filename, "File"
def on_embedding_upload(file_obj): if not file_obj: return gr.update(), gr.update(), None hashed_filename = save_uploaded_file_with_hash(file_obj, EMBEDDING_DIR) return hashed_filename, "File", file_obj
def create_lora_event_handlers(prefix, ui_components): lora_rows = ui_components.get(f'lora_rows_{prefix}') if not lora_rows: return lora_ids = ui_components[f'lora_ids_{prefix}'] lora_scales = ui_components[f'lora_scales_{prefix}'] lora_uploads = ui_components[f'lora_uploads_{prefix}'] lora_sources = ui_components[f'lora_sources_{prefix}'] count_state = ui_components[f'lora_count_state_{prefix}'] add_button = ui_components[f'add_lora_button_{prefix}'] del_button = ui_components[f'delete_lora_button_{prefix}']
for i in range(MAX_LORAS): lora_uploads[i].upload( fn=on_lora_upload, inputs=[lora_uploads[i]], outputs=[lora_ids[i], lora_sources[i]], show_progress=True )
def add_lora_row(c): updates = {} if c < MAX_LORAS: c += 1 updates[lora_rows[c - 1]] = gr.update(visible=True) updates[count_state] = c updates[add_button] = gr.update(visible=c < MAX_LORAS) updates[del_button] = gr.update(visible=c > 1) return updates
def del_lora_row(c): updates = {} if c > 1: updates[lora_rows[c - 1]] = gr.update(visible=False) updates[lora_ids[c - 1]] = "" updates[lora_scales[c - 1]] = 0.0 updates[lora_uploads[c - 1]] = None c -= 1
updates[count_state] = c updates[add_button] = gr.update(visible=True) updates[del_button] = gr.update(visible=c > 1) return updates add_outputs = [count_state, add_button, del_button] + lora_rows del_outputs = [count_state, add_button, del_button] + lora_rows + lora_ids + lora_scales + lora_uploads
add_button.click(add_lora_row, [count_state], add_outputs, show_progress=False) del_button.click(del_lora_row, [count_state], del_outputs, show_progress=False)
def create_controlnet_event_handlers(prefix, ui_components): cn_rows = ui_components.get(f'controlnet_rows_{prefix}') if not cn_rows: return cn_types = ui_components[f'controlnet_types_{prefix}'] cn_series = ui_components[f'controlnet_series_{prefix}'] cn_filepaths = ui_components[f'controlnet_filepaths_{prefix}'] cn_images = ui_components[f'controlnet_images_{prefix}'] cn_strengths = ui_components[f'controlnet_strengths_{prefix}'] count_state = ui_components[f'controlnet_count_state_{prefix}'] add_button = ui_components[f'add_controlnet_button_{prefix}'] del_button = ui_components[f'delete_controlnet_button_{prefix}'] accordion = ui_components[f'controlnet_accordion_{prefix}']
base_model_comp = ui_components.get(f'base_model_{prefix}') actual_arch_comp = base_model_comp if base_model_comp else gr.State("SDXL")
def add_cn_row(c): c += 1 updates = { count_state: c, cn_rows[c-1]: gr.update(visible=True), add_button: gr.update(visible=c < MAX_CONTROLNETS), del_button: gr.update(visible=True) } return updates
def del_cn_row(c): c -= 1 updates = { count_state: c, cn_rows[c]: gr.update(visible=False), cn_images[c]: None, cn_strengths[c]: 1.0, add_button: gr.update(visible=True), del_button: gr.update(visible=c > 0) } return updates add_outputs = [count_state, add_button, del_button] + cn_rows del_outputs = [count_state, add_button, del_button] + cn_rows + cn_images + cn_strengths add_button.click(fn=add_cn_row, inputs=[count_state], outputs=add_outputs, show_progress=False) del_button.click(fn=del_cn_row, inputs=[count_state], outputs=del_outputs, show_progress=False) def on_cn_type_change(selected_type, model_name): from core.settings import MODEL_TYPE_MAP m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL" cn_full_config = load_controlnet_config() architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {}) controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
cn_config = cn_full_config.get(controlnet_key, []) series_choices = [] if selected_type: series_choices = sorted(list(set( model.get("Series", "Default") for model in cn_config if selected_type in model.get("Type", []) ))) default_series = series_choices[0] if series_choices else None filepath = "None" if default_series: for model in cn_config: if model.get("Series") == default_series and selected_type in model.get("Type", []): filepath = model.get("Filepath") break return gr.update(choices=series_choices, value=default_series), filepath
def on_cn_series_change(selected_series, selected_type, model_name): from core.settings import MODEL_TYPE_MAP m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL" cn_full_config = load_controlnet_config() architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {}) controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
cn_config = cn_full_config.get(controlnet_key, []) filepath = "None" if selected_series and selected_type: for model in cn_config: if model.get("Series") == selected_series and selected_type in model.get("Type", []): filepath = model.get("Filepath") break return filepath for i in range(MAX_CONTROLNETS): cn_types[i].change( fn=on_cn_type_change, inputs=[cn_types[i], actual_arch_comp], outputs=[cn_series[i], cn_filepaths[i]], show_progress=False ) cn_series[i].change( fn=on_cn_series_change, inputs=[cn_series[i], cn_types[i], actual_arch_comp], outputs=[cn_filepaths[i]], show_progress=False )
def on_accordion_expand(*images): return [gr.update() for _ in images] accordion.expand( fn=on_accordion_expand, inputs=cn_images, outputs=cn_images, show_progress=False )
def create_krea2_controlnet_event_handlers(prefix, ui_components): cn_rows = ui_components.get(f'krea2_controlnet_rows_{prefix}') if not cn_rows: return cn_types = ui_components[f'krea2_controlnet_types_{prefix}'] cn_series = ui_components[f'krea2_controlnet_series_{prefix}'] cn_filepaths = ui_components[f'krea2_controlnet_filepaths_{prefix}'] cn_images = ui_components[f'krea2_controlnet_images_{prefix}'] cn_strengths = ui_components[f'krea2_controlnet_strengths_{prefix}'] count_state = ui_components[f'krea2_controlnet_count_state_{prefix}'] add_button = ui_components[f'add_krea2_controlnet_button_{prefix}'] del_button = ui_components[f'delete_krea2_controlnet_button_{prefix}'] accordion = ui_components[f'krea2_controlnet_accordion_{prefix}']
def add_cn_row(c): c += 1 updates = { count_state: c, cn_rows[c-1]: gr.update(visible=True), add_button: gr.update(visible=c < MAX_CONTROLNETS), del_button: gr.update(visible=True) } return updates
def del_cn_row(c): c -= 1 updates = { count_state: c, cn_rows[c]: gr.update(visible=False), cn_images[c]: None, cn_strengths[c]: 1.0, add_button: gr.update(visible=True), del_button: gr.update(visible=c > 0) } return updates add_outputs = [count_state, add_button, del_button] + cn_rows del_outputs = [count_state, add_button, del_button] + cn_rows + cn_images + cn_strengths add_button.click(fn=add_cn_row, inputs=[count_state], outputs=add_outputs, show_progress=False) del_button.click(fn=del_cn_row, inputs=[count_state], outputs=del_outputs, show_progress=False) def on_cn_type_change(selected_type): cn_config = load_krea2_controlnet_config() series_choices = [] if selected_type: series_choices = sorted(list(set( model.get("Series", "Default") for model in cn_config if selected_type in model.get("Type", []) ))) default_series = series_choices[0] if series_choices else None filepath = "None" if default_series: for model in cn_config: if model.get("Series") == default_series and selected_type in model.get("Type", []): filepath = model.get("Filepath") break return gr.update(choices=series_choices, value=default_series), filepath
def on_cn_series_change(selected_series, selected_type): cn_config = load_krea2_controlnet_config() filepath = "None" if selected_series and selected_type: for model in cn_config: if model.get("Series") == selected_series and selected_type in model.get("Type", []): filepath = model.get("Filepath") break return filepath for i in range(MAX_CONTROLNETS): cn_types[i].change( fn=on_cn_type_change, inputs=[cn_types[i]], outputs=[cn_series[i], cn_filepaths[i]], show_progress=False ) cn_series[i].change( fn=on_cn_series_change, inputs=[cn_series[i], cn_types[i]], outputs=[cn_filepaths[i]], show_progress=False )
def on_accordion_expand(*images): return [gr.update() for _ in images] accordion.expand( fn=on_accordion_expand, inputs=cn_images, outputs=cn_images, show_progress=False )
def create_anima_controlnet_lllite_event_handlers(prefix, ui_components): cn_rows = ui_components.get(f'anima_controlnet_lllite_rows_{prefix}') if not cn_rows: return cn_types = ui_components[f'anima_controlnet_lllite_types_{prefix}'] cn_series = ui_components[f'anima_controlnet_lllite_series_{prefix}'] cn_filepaths = ui_components[f'anima_controlnet_lllite_filepaths_{prefix}'] cn_images = ui_components[f'anima_controlnet_lllite_images_{prefix}'] cn_strengths = ui_components[f'anima_controlnet_lllite_strengths_{prefix}'] count_state = ui_components[f'anima_controlnet_lllite_count_state_{prefix}'] add_button = ui_components[f'add_anima_controlnet_lllite_button_{prefix}'] del_button = ui_components[f'delete_anima_controlnet_lllite_button_{prefix}'] accordion = ui_components[f'anima_controlnet_lllite_accordion_{prefix}']
def add_cn_row(c): c += 1 updates = { count_state: c, cn_rows[c-1]: gr.update(visible=True), add_button: gr.update(visible=c < MAX_CONTROLNETS), del_button: gr.update(visible=True) } return updates
def del_cn_row(c): c -= 1 updates = { count_state: c, cn_rows[c]: gr.update(visible=False), cn_images[c]: None, cn_strengths[c]: 1.0, add_button: gr.update(visible=True), del_button: gr.update(visible=c > 0) } return updates add_outputs = [count_state, add_button, del_button] + cn_rows del_outputs = [count_state, add_button, del_button] + cn_rows + cn_images + cn_strengths add_button.click(fn=add_cn_row, inputs=[count_state], outputs=add_outputs, show_progress=False) del_button.click(fn=del_cn_row, inputs=[count_state], outputs=del_outputs, show_progress=False) def on_cn_type_change(selected_type): cn_config = load_anima_controlnet_lllite_config() series_choices = [] if selected_type: series_choices = sorted(list(set( model.get("Series", "Default") for model in cn_config if selected_type in model.get("Type", []) ))) default_series = series_choices[0] if series_choices else None filepath = "None" if default_series: for model in cn_config: if model.get("Series") == default_series and selected_type in model.get("Type", []): filepath = model.get("Filepath") break return gr.update(choices=series_choices, value=default_series), filepath
def on_cn_series_change(selected_series, selected_type): cn_config = load_anima_controlnet_lllite_config() filepath = "None" if selected_series and selected_type: for model in cn_config: if model.get("Series") == selected_series and selected_type in model.get("Type", []): filepath = model.get("Filepath") break return filepath for i in range(MAX_CONTROLNETS): cn_types[i].change( fn=on_cn_type_change, inputs=[cn_types[i]], outputs=[cn_series[i], cn_filepaths[i]], show_progress=False ) cn_series[i].change( fn=on_cn_series_change, inputs=[cn_series[i], cn_types[i]], outputs=[cn_filepaths[i]], show_progress=False )
def on_accordion_expand(*images): return [gr.update() for _ in images] accordion.expand( fn=on_accordion_expand, inputs=cn_images, outputs=cn_images, show_progress=False )
def create_diffsynth_controlnet_event_handlers(prefix, ui_components): cn_rows = ui_components.get(f'diffsynth_controlnet_rows_{prefix}') if not cn_rows: return cn_types = ui_components[f'diffsynth_controlnet_types_{prefix}'] cn_series = ui_components[f'diffsynth_controlnet_series_{prefix}'] cn_filepaths = ui_components[f'diffsynth_controlnet_filepaths_{prefix}'] cn_images = ui_components[f'diffsynth_controlnet_images_{prefix}'] cn_strengths = ui_components[f'diffsynth_controlnet_strengths_{prefix}'] count_state = ui_components[f'diffsynth_controlnet_count_state_{prefix}'] add_button = ui_components[f'add_diffsynth_controlnet_button_{prefix}'] del_button = ui_components[f'delete_diffsynth_controlnet_button_{prefix}'] accordion = ui_components[f'diffsynth_controlnet_accordion_{prefix}']
base_model_comp = ui_components.get(f'base_model_{prefix}') actual_arch_comp = base_model_comp if base_model_comp else gr.State("SDXL")
def add_cn_row(c): c += 1 updates = { count_state: c, cn_rows[c-1]: gr.update(visible=True), add_button: gr.update(visible=c < MAX_CONTROLNETS), del_button: gr.update(visible=True) } return updates
def del_cn_row(c): c -= 1 updates = { count_state: c, cn_rows[c]: gr.update(visible=False), cn_images[c]: None, cn_strengths[c]: 1.0, add_button: gr.update(visible=True), del_button: gr.update(visible=c > 0) } return updates add_outputs = [count_state, add_button, del_button] + cn_rows del_outputs = [count_state, add_button, del_button] + cn_rows + cn_images + cn_strengths add_button.click(fn=add_cn_row, inputs=[count_state], outputs=add_outputs, show_progress=False) del_button.click(fn=del_cn_row, inputs=[count_state], outputs=del_outputs, show_progress=False) def on_cn_type_change(selected_type, model_name): from core.settings import MODEL_TYPE_MAP m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL" cn_full_config = load_diffsynth_controlnet_config() architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {}) controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
cn_config = cn_full_config.get(controlnet_key, []) series_choices = [] if selected_type: series_choices = sorted(list(set( model.get("Series", "Default") for model in cn_config if selected_type in model.get("Type", []) ))) default_series = series_choices[0] if series_choices else None filepath = "None" if default_series: for model in cn_config: if model.get("Series") == default_series and selected_type in model.get("Type", []): filepath = model.get("Filepath") break return gr.update(choices=series_choices, value=default_series), filepath
def on_cn_series_change(selected_series, selected_type, model_name): from core.settings import MODEL_TYPE_MAP m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL" cn_full_config = load_diffsynth_controlnet_config() architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {}) controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
cn_config = cn_full_config.get(controlnet_key, []) filepath = "None" if selected_series and selected_type: for model in cn_config: if model.get("Series") == selected_series and selected_type in model.get("Type", []): filepath = model.get("Filepath") break return filepath for i in range(MAX_CONTROLNETS): cn_types[i].change( fn=on_cn_type_change, inputs=[cn_types[i], actual_arch_comp], outputs=[cn_series[i], cn_filepaths[i]], show_progress=False ) cn_series[i].change( fn=on_cn_series_change, inputs=[cn_series[i], cn_types[i], actual_arch_comp], outputs=[cn_filepaths[i]], show_progress=False )
def on_accordion_expand(*images): return [gr.update() for _ in images] accordion.expand( fn=on_accordion_expand, inputs=cn_images, outputs=cn_images, show_progress=False )
def create_flux1_ipadapter_event_handlers(prefix, ui_components): fipa_rows = ui_components.get(f'flux1_ipadapter_rows_{prefix}') if not fipa_rows: return count_state = ui_components[f'flux1_ipadapter_count_state_{prefix}'] add_button = ui_components[f'add_flux1_ipadapter_button_{prefix}'] del_button = ui_components[f'delete_flux1_ipadapter_button_{prefix}']
def add_fipa_row(c): c += 1 return { count_state: c, fipa_rows[c - 1]: gr.update(visible=True), add_button: gr.update(visible=c < MAX_IPADAPTERS), del_button: gr.update(visible=True), }
def del_fipa_row(c): c -= 1 return { count_state: c, fipa_rows[c]: gr.update(visible=False), add_button: gr.update(visible=True), del_button: gr.update(visible=c > 0), }
add_outputs = [count_state, add_button, del_button] + fipa_rows del_outputs = [count_state, add_button, del_button] + fipa_rows add_button.click(fn=add_fipa_row, inputs=[count_state], outputs=add_outputs, show_progress=False) del_button.click(fn=del_fipa_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_sd3_ipadapter_event_handlers(prefix, ui_components): ipa_rows = ui_components.get(f'sd3_ipadapter_rows_{prefix}') if not ipa_rows: return count_state = ui_components[f'sd3_ipadapter_count_state_{prefix}'] add_button = ui_components[f'add_sd3_ipadapter_button_{prefix}'] del_button = ui_components[f'delete_sd3_ipadapter_button_{prefix}'] images = ui_components[f'sd3_ipadapter_images_{prefix}'] weights = ui_components[f'sd3_ipadapter_weights_{prefix}'] start_percents = ui_components[f'sd3_ipadapter_start_percents_{prefix}'] end_percents = ui_components[f'sd3_ipadapter_end_percents_{prefix}']
def add_ipa_row(c): c += 1 return { count_state: c, ipa_rows[c - 1]: gr.update(visible=True), add_button: gr.update(visible=c < MAX_IPADAPTERS), del_button: gr.update(visible=True), }
def del_ipa_row(c): c -= 1 return { count_state: c, ipa_rows[c]: gr.update(visible=False), images[c]: None, weights[c]: 0.5, start_percents[c]: 0.0, end_percents[c]: 1.0, add_button: gr.update(visible=True), del_button: gr.update(visible=c > 0), }
add_outputs = [count_state, add_button, del_button] + ipa_rows del_outputs = [count_state, add_button, del_button] + ipa_rows + images + weights + start_percents + end_percents add_button.click(fn=add_ipa_row, inputs=[count_state], outputs=add_outputs, show_progress=False) del_button.click(fn=del_ipa_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_style_event_handlers(prefix, ui_components): style_rows = ui_components.get(f'style_rows_{prefix}') if not style_rows: return count_state = ui_components[f'style_count_state_{prefix}'] add_button = ui_components[f'add_style_button_{prefix}'] del_button = ui_components[f'delete_style_button_{prefix}']
def add_style_row(c): c += 1 return { count_state: c, style_rows[c - 1]: gr.update(visible=True), add_button: gr.update(visible=c < 5), del_button: gr.update(visible=True), }
def del_style_row(c): c -= 1 return { count_state: c, style_rows[c]: gr.update(visible=False), add_button: gr.update(visible=True), del_button: gr.update(visible=c > 0), }
add_outputs = [count_state, add_button, del_button] + style_rows del_outputs = [count_state, add_button, del_button] + style_rows add_button.click(fn=add_style_row, inputs=[count_state], outputs=add_outputs, show_progress=False) del_button.click(fn=del_style_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_ipadapter_event_handlers(prefix, ui_components): ipa_rows = ui_components.get(f'ipadapter_rows_{prefix}') if not ipa_rows: return ipa_lora_strengths = ui_components[f'ipadapter_lora_strengths_{prefix}'] ipa_final_preset = ui_components[f'ipadapter_final_preset_{prefix}'] ipa_final_lora_strength = ui_components[f'ipadapter_final_lora_strength_{prefix}'] count_state = ui_components[f'ipadapter_count_state_{prefix}'] add_button = ui_components[f'add_ipadapter_button_{prefix}'] del_button = ui_components[f'delete_ipadapter_button_{prefix}'] accordion = ui_components[f'ipadapter_accordion_{prefix}']
def add_ipa_row(c): c += 1 return { count_state: c, ipa_rows[c - 1]: gr.update(visible=True), add_button: gr.update(visible=c < MAX_IPADAPTERS), del_button: gr.update(visible=True), }
def del_ipa_row(c): c -= 1 return { count_state: c, ipa_rows[c]: gr.update(visible=False), add_button: gr.update(visible=True), del_button: gr.update(visible=c > 0), }
add_outputs = [count_state, add_button, del_button] + ipa_rows del_outputs = [count_state, add_button, del_button] + ipa_rows add_button.click(fn=add_ipa_row, inputs=[count_state], outputs=add_outputs, show_progress=False) del_button.click(fn=del_ipa_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def on_preset_change(preset_value): config = load_ipadapter_config() faceid_presets = [] if config: faceid_presets.extend(config.get("IPAdapter_FaceID_presets", {}).get("SDXL", [])) faceid_presets.extend(config.get("IPAdapter_FaceID_presets", {}).get("SD1.5", []))
is_visible = preset_value in faceid_presets updates = [gr.update(visible=is_visible)] * (MAX_IPADAPTERS + 1) return updates
all_lora_strength_sliders = [ipa_final_lora_strength] + ipa_lora_strengths ipa_final_preset.change(fn=on_preset_change, inputs=[ipa_final_preset], outputs=all_lora_strength_sliders, show_progress=False) 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)
def create_reference_latent_event_handlers(prefix, ui_components): ref_rows = ui_components.get(f'reference_latent_rows_{prefix}') if not ref_rows: return count_state = ui_components[f'reference_latent_count_state_{prefix}'] add_button = ui_components[f'add_reference_latent_button_{prefix}'] del_button = ui_components[f'delete_reference_latent_button_{prefix}'] images = ui_components[f'reference_latent_images_{prefix}']
def add_ref_row(c): c += 1 return { count_state: c, ref_rows[c - 1]: gr.update(visible=True), add_button: gr.update(visible=c < 10), del_button: gr.update(visible=True), }
def del_ref_row(c): c -= 1 return { count_state: c, ref_rows[c]: gr.update(visible=False), images[c]: None, add_button: gr.update(visible=True), del_button: gr.update(visible=c > 0), }
add_outputs = [count_state, add_button, del_button] + ref_rows del_outputs = [count_state, add_button, del_button] + ref_rows + images add_button.click(fn=add_ref_row, inputs=[count_state], outputs=add_outputs, show_progress=False) del_button.click(fn=del_ref_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_hidream_o1_reference_event_handlers(prefix, ui_components): ref_rows = ui_components.get(f'hidream_o1_reference_rows_{prefix}') if not ref_rows: return count_state = ui_components[f'hidream_o1_reference_count_state_{prefix}'] add_button = ui_components[f'add_hidream_o1_reference_button_{prefix}'] del_button = ui_components[f'delete_hidream_o1_reference_button_{prefix}'] images = ui_components[f'hidream_o1_reference_images_{prefix}']
def add_ref_row(c): c += 1 return { count_state: c, ref_rows[c - 1]: gr.update(visible=True), add_button: gr.update(visible=c < 10), del_button: gr.update(visible=True), }
def del_ref_row(c): c -= 1 return { count_state: c, ref_rows[c]: gr.update(visible=False), images[c]: None, add_button: gr.update(visible=True), del_button: gr.update(visible=c > 0), }
add_outputs = [count_state, add_button, del_button] + ref_rows del_outputs = [count_state, add_button, del_button] + ref_rows + images add_button.click(fn=add_ref_row, inputs=[count_state], outputs=add_outputs, show_progress=False) del_button.click(fn=del_ref_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_joyai_reference_event_handlers(prefix, ui_components): ref_rows = ui_components.get(f'joyai_reference_rows_{prefix}') if not ref_rows: return count_state = ui_components[f'joyai_reference_count_state_{prefix}'] add_button = ui_components[f'add_joyai_reference_button_{prefix}'] del_button = ui_components[f'delete_joyai_reference_button_{prefix}'] images = ui_components[f'joyai_reference_images_{prefix}']
def add_ref_row(c): c += 1 return { count_state: c, ref_rows[c - 1]: gr.update(visible=True), add_button: gr.update(visible=c < 2), del_button: gr.update(visible=True), }
def del_ref_row(c): c -= 1 return { count_state: c, ref_rows[c]: gr.update(visible=False), images[c]: None, add_button: gr.update(visible=True), del_button: gr.update(visible=c > 0), }
add_outputs = [count_state, add_button, del_button] + ref_rows del_outputs = [count_state, add_button, del_button] + ref_rows + images add_button.click(fn=add_ref_row, inputs=[count_state], outputs=add_outputs, show_progress=False) del_button.click(fn=del_ref_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_reference_image_event_handlers(prefix, ui_components): ref_rows = ui_components.get(f'reference_image_rows_{prefix}') if not ref_rows: return count_state = ui_components[f'reference_image_count_state_{prefix}'] add_button = ui_components[f'add_reference_image_button_{prefix}'] del_button = ui_components[f'delete_reference_image_button_{prefix}'] images = ui_components[f'reference_image_images_{prefix}']
def add_ref_row(c): c += 1 return { count_state: c, ref_rows[c - 1]: gr.update(visible=True), add_button: gr.update(visible=c < 10), del_button: gr.update(visible=True), }
def del_ref_row(c): c -= 1 return { count_state: c, ref_rows[c]: gr.update(visible=False), images[c]: None, add_button: gr.update(visible=True), del_button: gr.update(visible=c > 0), }
add_outputs = [count_state, add_button, del_button] + ref_rows del_outputs = [count_state, add_button, del_button] + ref_rows + images add_button.click(fn=add_ref_row, inputs=[count_state], outputs=add_outputs, show_progress=False) del_button.click(fn=del_ref_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_embedding_event_handlers(prefix, ui_components): rows = ui_components.get(f'embedding_rows_{prefix}') if not rows: return ids = ui_components[f'embeddings_ids_{prefix}'] files = ui_components[f'embeddings_files_{prefix}'] sources = ui_components[f'embeddings_sources_{prefix}'] upload_buttons = ui_components[f'embeddings_uploads_{prefix}'] count_state = ui_components[f'embedding_count_state_{prefix}'] add_button = ui_components[f'add_embedding_button_{prefix}'] del_button = ui_components[f'delete_embedding_button_{prefix}']
for i in range(MAX_EMBEDDINGS): upload_buttons[i].upload( fn=on_embedding_upload, inputs=[upload_buttons[i]], outputs=[ids[i], sources[i], files[i]], show_progress=True )
def add_row(c): c += 1 return { count_state: c, rows[c - 1]: gr.update(visible=True), add_button: gr.update(visible=c < MAX_EMBEDDINGS), del_button: gr.update(visible=True) }
def del_row(c): c -= 1 return { count_state: c, rows[c]: gr.update(visible=False), ids[c]: "", files[c]: None, add_button: gr.update(visible=True), del_button: gr.update(visible=c > 0) } add_outputs = [count_state, add_button, del_button] + rows del_outputs = [count_state, add_button, del_button] + rows + ids + files add_button.click(fn=add_row, inputs=[count_state], outputs=add_outputs, show_progress=False) del_button.click(fn=del_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_conditioning_event_handlers(prefix, ui_components): rows = ui_components.get(f'conditioning_rows_{prefix}') if not rows: return prompts = ui_components[f'conditioning_prompts_{prefix}'] count_state = ui_components[f'conditioning_count_state_{prefix}'] add_button = ui_components[f'add_conditioning_button_{prefix}'] del_button = ui_components[f'delete_conditioning_button_{prefix}'] def add_row(c): c += 1 return { count_state: c, rows[c - 1]: gr.update(visible=True), add_button: gr.update(visible=c < MAX_CONDITIONINGS), del_button: gr.update(visible=True), }
def del_row(c): c -= 1 return { count_state: c, rows[c]: gr.update(visible=False), prompts[c]: "", add_button: gr.update(visible=True), del_button: gr.update(visible=c > 0), }
add_outputs = [count_state, add_button, del_button] + rows del_outputs = [count_state, add_button, del_button] + rows + prompts add_button.click(fn=add_row, inputs=[count_state], outputs=add_outputs, show_progress=False) del_button.click(fn=del_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_krea2_identity_edit_event_handlers(prefix, ui_components): ref_rows = ui_components.get(f'krea2_identity_edit_rows_{prefix}') if not ref_rows: return count_state = ui_components[f'krea2_identity_edit_count_state_{prefix}'] add_button = ui_components[f'add_krea2_identity_edit_button_{prefix}'] del_button = ui_components[f'delete_krea2_identity_edit_button_{prefix}'] images = ui_components[f'krea2_identity_edit_images_{prefix}']
def add_ref_row(c): c += 1 return { count_state: c, ref_rows[c - 1]: gr.update(visible=True), add_button: gr.update(visible=c < 2), del_button: gr.update(visible=True), }
def del_ref_row(c): c -= 1 return { count_state: c, ref_rows[c]: gr.update(visible=False), images[c]: None, add_button: gr.update(visible=True), del_button: gr.update(visible=c > 0), }
add_outputs = [count_state, add_button, del_button] + ref_rows del_outputs = [count_state, add_button, del_button] + ref_rows + images add_button.click(fn=add_ref_row, inputs=[count_state], outputs=add_outputs, show_progress=False)import gradio as gr
from core.settings import VAE_DIR, LORA_DIR, EMBEDDING_DIR, ARCHITECTURES_CONFIG
from utils.app_utils import save_uploaded_file_with_hash
from ui.shared.ui_components import (
MAX_CONTROLNETS,
MAX_IPADAPTERS,
MAX_EMBEDDINGS,
MAX_CONDITIONINGS,
MAX_LORAS
)
from .config_loaders import (
load_controlnet_config,
load_anima_controlnet_lllite_config,
load_diffsynth_controlnet_config,
load_krea2_controlnet_config,
load_ipadapter_config
)
def on_vae_upload(file_obj):
if not file_obj:
return gr.update(), gr.update(), None
hashed_filename = save_uploaded_file_with_hash(file_obj, VAE_DIR)
return hashed_filename, "File", file_obj
def on_lora_upload(file_obj):
if not file_obj:
return gr.update(), gr.update()
hashed_filename = save_uploaded_file_with_hash(file_obj, LORA_DIR)
return hashed_filename, "File"
def on_embedding_upload(file_obj):
if not file_obj:
return gr.update(), gr.update(), None
hashed_filename = save_uploaded_file_with_hash(file_obj, EMBEDDING_DIR)
return hashed_filename, "File", file_obj
def create_lora_event_handlers(prefix, ui_components):
lora_rows = ui_components.get(f'lora_rows_{prefix}')
if not lora_rows: return
lora_ids = ui_components[f'lora_ids_{prefix}']
lora_scales = ui_components[f'lora_scales_{prefix}']
lora_uploads = ui_components[f'lora_uploads_{prefix}']
lora_sources = ui_components[f'lora_sources_{prefix}']
count_state = ui_components[f'lora_count_state_{prefix}']
add_button = ui_components[f'add_lora_button_{prefix}']
del_button = ui_components[f'delete_lora_button_{prefix}']
for i in range(MAX_LORAS):
lora_uploads[i].upload(
fn=on_lora_upload,
inputs=[lora_uploads[i]],
outputs=[lora_ids[i], lora_sources[i]],
show_progress=True
)
def add_lora_row(c):
updates = {}
if c < MAX_LORAS:
c += 1
updates[lora_rows[c - 1]] = gr.update(visible=True)
updates[count_state] = c
updates[add_button] = gr.update(visible=c < MAX_LORAS)
updates[del_button] = gr.update(visible=c > 1)
return updates
def del_lora_row(c):
updates = {}
if c > 1:
updates[lora_rows[c - 1]] = gr.update(visible=False)
updates[lora_ids[c - 1]] = ""
updates[lora_scales[c - 1]] = 0.0
updates[lora_uploads[c - 1]] = None
c -= 1
updates[count_state] = c
updates[add_button] = gr.update(visible=True)
updates[del_button] = gr.update(visible=c > 1)
return updates
add_outputs = [count_state, add_button, del_button] + lora_rows
del_outputs = [count_state, add_button, del_button] + lora_rows + lora_ids + lora_scales + lora_uploads
add_button.click(add_lora_row, [count_state], add_outputs, show_progress=False)
del_button.click(del_lora_row, [count_state], del_outputs, show_progress=False)
def create_controlnet_event_handlers(prefix, ui_components):
cn_rows = ui_components.get(f'controlnet_rows_{prefix}')
if not cn_rows: return
cn_types = ui_components[f'controlnet_types_{prefix}']
cn_series = ui_components[f'controlnet_series_{prefix}']
cn_filepaths = ui_components[f'controlnet_filepaths_{prefix}']
cn_images = ui_components[f'controlnet_images_{prefix}']
cn_strengths = ui_components[f'controlnet_strengths_{prefix}']
count_state = ui_components[f'controlnet_count_state_{prefix}']
add_button = ui_components[f'add_controlnet_button_{prefix}']
del_button = ui_components[f'delete_controlnet_button_{prefix}']
accordion = ui_components[f'controlnet_accordion_{prefix}']
base_model_comp = ui_components.get(f'base_model_{prefix}')
actual_arch_comp = base_model_comp if base_model_comp else gr.State("SDXL")
def add_cn_row(c):
c += 1
updates = {
count_state: c,
cn_rows[c-1]: gr.update(visible=True),
add_button: gr.update(visible=c < MAX_CONTROLNETS),
del_button: gr.update(visible=True)
}
return updates
def del_cn_row(c):
c -= 1
updates = {
count_state: c,
cn_rows[c]: gr.update(visible=False),
cn_images[c]: None,
cn_strengths[c]: 1.0,
add_button: gr.update(visible=True),
del_button: gr.update(visible=c > 0)
}
return updates
add_outputs = [count_state, add_button, del_button] + cn_rows
del_outputs = [count_state, add_button, del_button] + cn_rows + cn_images + cn_strengths
add_button.click(fn=add_cn_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
del_button.click(fn=del_cn_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def on_cn_type_change(selected_type, model_name):
from core.settings import MODEL_TYPE_MAP
m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL"
cn_full_config = load_controlnet_config()
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
cn_config = cn_full_config.get(controlnet_key, [])
series_choices = []
if selected_type:
series_choices = sorted(list(set(
model.get("Series", "Default") for model in cn_config
if selected_type in model.get("Type", [])
)))
default_series = series_choices[0] if series_choices else None
filepath = "None"
if default_series:
for model in cn_config:
if model.get("Series") == default_series and selected_type in model.get("Type", []):
filepath = model.get("Filepath")
break
return gr.update(choices=series_choices, value=default_series), filepath
def on_cn_series_change(selected_series, selected_type, model_name):
from core.settings import MODEL_TYPE_MAP
m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL"
cn_full_config = load_controlnet_config()
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
cn_config = cn_full_config.get(controlnet_key, [])
filepath = "None"
if selected_series and selected_type:
for model in cn_config:
if model.get("Series") == selected_series and selected_type in model.get("Type", []):
filepath = model.get("Filepath")
break
return filepath
for i in range(MAX_CONTROLNETS):
cn_types[i].change(
fn=on_cn_type_change,
inputs=[cn_types[i], actual_arch_comp],
outputs=[cn_series[i], cn_filepaths[i]],
show_progress=False
)
cn_series[i].change(
fn=on_cn_series_change,
inputs=[cn_series[i], cn_types[i], actual_arch_comp],
outputs=[cn_filepaths[i]],
show_progress=False
)
def on_accordion_expand(*images):
return [gr.update() for _ in images]
accordion.expand(
fn=on_accordion_expand,
inputs=cn_images,
outputs=cn_images,
show_progress=False
)
def create_krea2_controlnet_event_handlers(prefix, ui_components):
cn_rows = ui_components.get(f'krea2_controlnet_rows_{prefix}')
if not cn_rows: return
cn_types = ui_components[f'krea2_controlnet_types_{prefix}']
cn_series = ui_components[f'krea2_controlnet_series_{prefix}']
cn_filepaths = ui_components[f'krea2_controlnet_filepaths_{prefix}']
cn_images = ui_components[f'krea2_controlnet_images_{prefix}']
cn_strengths = ui_components[f'krea2_controlnet_strengths_{prefix}']
count_state = ui_components[f'krea2_controlnet_count_state_{prefix}']
add_button = ui_components[f'add_krea2_controlnet_button_{prefix}']
del_button = ui_components[f'delete_krea2_controlnet_button_{prefix}']
accordion = ui_components[f'krea2_controlnet_accordion_{prefix}']
def add_cn_row(c):
c += 1
updates = {
count_state: c,
cn_rows[c-1]: gr.update(visible=True),
add_button: gr.update(visible=c < MAX_CONTROLNETS),
del_button: gr.update(visible=True)
}
return updates
def del_cn_row(c):
c -= 1
updates = {
count_state: c,
cn_rows[c]: gr.update(visible=False),
cn_images[c]: None,
cn_strengths[c]: 1.0,
add_button: gr.update(visible=True),
del_button: gr.update(visible=c > 0)
}
return updates
add_outputs = [count_state, add_button, del_button] + cn_rows
del_outputs = [count_state, add_button, del_button] + cn_rows + cn_images + cn_strengths
add_button.click(fn=add_cn_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
del_button.click(fn=del_cn_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def on_cn_type_change(selected_type):
cn_config = load_krea2_controlnet_config()
series_choices = []
if selected_type:
series_choices = sorted(list(set(
model.get("Series", "Default") for model in cn_config
if selected_type in model.get("Type", [])
)))
default_series = series_choices[0] if series_choices else None
filepath = "None"
if default_series:
for model in cn_config:
if model.get("Series") == default_series and selected_type in model.get("Type", []):
filepath = model.get("Filepath")
break
return gr.update(choices=series_choices, value=default_series), filepath
def on_cn_series_change(selected_series, selected_type):
cn_config = load_krea2_controlnet_config()
filepath = "None"
if selected_series and selected_type:
for model in cn_config:
if model.get("Series") == selected_series and selected_type in model.get("Type", []):
filepath = model.get("Filepath")
break
return filepath
for i in range(MAX_CONTROLNETS):
cn_types[i].change(
fn=on_cn_type_change,
inputs=[cn_types[i]],
outputs=[cn_series[i], cn_filepaths[i]],
show_progress=False
)
cn_series[i].change(
fn=on_cn_series_change,
inputs=[cn_series[i], cn_types[i]],
outputs=[cn_filepaths[i]],
show_progress=False
)
def on_accordion_expand(*images):
return [gr.update() for _ in images]
accordion.expand(
fn=on_accordion_expand,
inputs=cn_images,
outputs=cn_images,
show_progress=False
)
def create_anima_controlnet_lllite_event_handlers(prefix, ui_components):
cn_rows = ui_components.get(f'anima_controlnet_lllite_rows_{prefix}')
if not cn_rows: return
cn_types = ui_components[f'anima_controlnet_lllite_types_{prefix}']
cn_series = ui_components[f'anima_controlnet_lllite_series_{prefix}']
cn_filepaths = ui_components[f'anima_controlnet_lllite_filepaths_{prefix}']
cn_images = ui_components[f'anima_controlnet_lllite_images_{prefix}']
cn_strengths = ui_components[f'anima_controlnet_lllite_strengths_{prefix}']
count_state = ui_components[f'anima_controlnet_lllite_count_state_{prefix}']
add_button = ui_components[f'add_anima_controlnet_lllite_button_{prefix}']
del_button = ui_components[f'delete_anima_controlnet_lllite_button_{prefix}']
accordion = ui_components[f'anima_controlnet_lllite_accordion_{prefix}']
def add_cn_row(c):
c += 1
updates = {
count_state: c,
cn_rows[c-1]: gr.update(visible=True),
add_button: gr.update(visible=c < MAX_CONTROLNETS),
del_button: gr.update(visible=True)
}
return updates
def del_cn_row(c):
c -= 1
updates = {
count_state: c,
cn_rows[c]: gr.update(visible=False),
cn_images[c]: None,
cn_strengths[c]: 1.0,
add_button: gr.update(visible=True),
del_button: gr.update(visible=c > 0)
}
return updates
add_outputs = [count_state, add_button, del_button] + cn_rows
del_outputs = [count_state, add_button, del_button] + cn_rows + cn_images + cn_strengths
add_button.click(fn=add_cn_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
del_button.click(fn=del_cn_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def on_cn_type_change(selected_type):
cn_config = load_anima_controlnet_lllite_config()
series_choices = []
if selected_type:
series_choices = sorted(list(set(
model.get("Series", "Default") for model in cn_config
if selected_type in model.get("Type", [])
)))
default_series = series_choices[0] if series_choices else None
filepath = "None"
if default_series:
for model in cn_config:
if model.get("Series") == default_series and selected_type in model.get("Type", []):
filepath = model.get("Filepath")
break
return gr.update(choices=series_choices, value=default_series), filepath
def on_cn_series_change(selected_series, selected_type):
cn_config = load_anima_controlnet_lllite_config()
filepath = "None"
if selected_series and selected_type:
for model in cn_config:
if model.get("Series") == selected_series and selected_type in model.get("Type", []):
filepath = model.get("Filepath")
break
return filepath
for i in range(MAX_CONTROLNETS):
cn_types[i].change(
fn=on_cn_type_change,
inputs=[cn_types[i]],
outputs=[cn_series[i], cn_filepaths[i]],
show_progress=False
)
cn_series[i].change(
fn=on_cn_series_change,
inputs=[cn_series[i], cn_types[i]],
outputs=[cn_filepaths[i]],
show_progress=False
)
def on_accordion_expand(*images):
return [gr.update() for _ in images]
accordion.expand(
fn=on_accordion_expand,
inputs=cn_images,
outputs=cn_images,
show_progress=False
)
def create_diffsynth_controlnet_event_handlers(prefix, ui_components):
cn_rows = ui_components.get(f'diffsynth_controlnet_rows_{prefix}')
if not cn_rows: return
cn_types = ui_components[f'diffsynth_controlnet_types_{prefix}']
cn_series = ui_components[f'diffsynth_controlnet_series_{prefix}']
cn_filepaths = ui_components[f'diffsynth_controlnet_filepaths_{prefix}']
cn_images = ui_components[f'diffsynth_controlnet_images_{prefix}']
cn_strengths = ui_components[f'diffsynth_controlnet_strengths_{prefix}']
count_state = ui_components[f'diffsynth_controlnet_count_state_{prefix}']
add_button = ui_components[f'add_diffsynth_controlnet_button_{prefix}']
del_button = ui_components[f'delete_diffsynth_controlnet_button_{prefix}']
accordion = ui_components[f'diffsynth_controlnet_accordion_{prefix}']
base_model_comp = ui_components.get(f'base_model_{prefix}')
actual_arch_comp = base_model_comp if base_model_comp else gr.State("SDXL")
def add_cn_row(c):
c += 1
updates = {
count_state: c,
cn_rows[c-1]: gr.update(visible=True),
add_button: gr.update(visible=c < MAX_CONTROLNETS),
del_button: gr.update(visible=True)
}
return updates
def del_cn_row(c):
c -= 1
updates = {
count_state: c,
cn_rows[c]: gr.update(visible=False),
cn_images[c]: None,
cn_strengths[c]: 1.0,
add_button: gr.update(visible=True),
del_button: gr.update(visible=c > 0)
}
return updates
add_outputs = [count_state, add_button, del_button] + cn_rows
del_outputs = [count_state, add_button, del_button] + cn_rows + cn_images + cn_strengths
add_button.click(fn=add_cn_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
del_button.click(fn=del_cn_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def on_cn_type_change(selected_type, model_name):
from core.settings import MODEL_TYPE_MAP
m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL"
cn_full_config = load_diffsynth_controlnet_config()
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
cn_config = cn_full_config.get(controlnet_key, [])
series_choices = []
if selected_type:
series_choices = sorted(list(set(
model.get("Series", "Default") for model in cn_config
if selected_type in model.get("Type", [])
)))
default_series = series_choices[0] if series_choices else None
filepath = "None"
if default_series:
for model in cn_config:
if model.get("Series") == default_series and selected_type in model.get("Type", []):
filepath = model.get("Filepath")
break
return gr.update(choices=series_choices, value=default_series), filepath
def on_cn_series_change(selected_series, selected_type, model_name):
from core.settings import MODEL_TYPE_MAP
m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL"
cn_full_config = load_diffsynth_controlnet_config()
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type)
cn_config = cn_full_config.get(controlnet_key, [])
filepath = "None"
if selected_series and selected_type:
for model in cn_config:
if model.get("Series") == selected_series and selected_type in model.get("Type", []):
filepath = model.get("Filepath")
break
return filepath
for i in range(MAX_CONTROLNETS):
cn_types[i].change(
fn=on_cn_type_change,
inputs=[cn_types[i], actual_arch_comp],
outputs=[cn_series[i], cn_filepaths[i]],
show_progress=False
)
cn_series[i].change(
fn=on_cn_series_change,
inputs=[cn_series[i], cn_types[i], actual_arch_comp],
outputs=[cn_filepaths[i]],
show_progress=False
)
def on_accordion_expand(*images):
return [gr.update() for _ in images]
accordion.expand(
fn=on_accordion_expand,
inputs=cn_images,
outputs=cn_images,
show_progress=False
)
def create_flux1_ipadapter_event_handlers(prefix, ui_components):
fipa_rows = ui_components.get(f'flux1_ipadapter_rows_{prefix}')
if not fipa_rows: return
count_state = ui_components[f'flux1_ipadapter_count_state_{prefix}']
add_button = ui_components[f'add_flux1_ipadapter_button_{prefix}']
del_button = ui_components[f'delete_flux1_ipadapter_button_{prefix}']
def add_fipa_row(c):
c += 1
return {
count_state: c,
fipa_rows[c - 1]: gr.update(visible=True),
add_button: gr.update(visible=c < MAX_IPADAPTERS),
del_button: gr.update(visible=True),
}
def del_fipa_row(c):
c -= 1
return {
count_state: c,
fipa_rows[c]: gr.update(visible=False),
add_button: gr.update(visible=True),
del_button: gr.update(visible=c > 0),
}
add_outputs = [count_state, add_button, del_button] + fipa_rows
del_outputs = [count_state, add_button, del_button] + fipa_rows
add_button.click(fn=add_fipa_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
del_button.click(fn=del_fipa_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_sd3_ipadapter_event_handlers(prefix, ui_components):
ipa_rows = ui_components.get(f'sd3_ipadapter_rows_{prefix}')
if not ipa_rows: return
count_state = ui_components[f'sd3_ipadapter_count_state_{prefix}']
add_button = ui_components[f'add_sd3_ipadapter_button_{prefix}']
del_button = ui_components[f'delete_sd3_ipadapter_button_{prefix}']
images = ui_components[f'sd3_ipadapter_images_{prefix}']
weights = ui_components[f'sd3_ipadapter_weights_{prefix}']
start_percents = ui_components[f'sd3_ipadapter_start_percents_{prefix}']
end_percents = ui_components[f'sd3_ipadapter_end_percents_{prefix}']
def add_ipa_row(c):
c += 1
return {
count_state: c,
ipa_rows[c - 1]: gr.update(visible=True),
add_button: gr.update(visible=c < MAX_IPADAPTERS),
del_button: gr.update(visible=True),
}
def del_ipa_row(c):
c -= 1
return {
count_state: c,
ipa_rows[c]: gr.update(visible=False),
images[c]: None,
weights[c]: 0.5,
start_percents[c]: 0.0,
end_percents[c]: 1.0,
add_button: gr.update(visible=True),
del_button: gr.update(visible=c > 0),
}
add_outputs = [count_state, add_button, del_button] + ipa_rows
del_outputs = [count_state, add_button, del_button] + ipa_rows + images + weights + start_percents + end_percents
add_button.click(fn=add_ipa_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
del_button.click(fn=del_ipa_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_style_event_handlers(prefix, ui_components):
style_rows = ui_components.get(f'style_rows_{prefix}')
if not style_rows: return
count_state = ui_components[f'style_count_state_{prefix}']
add_button = ui_components[f'add_style_button_{prefix}']
del_button = ui_components[f'delete_style_button_{prefix}']
def add_style_row(c):
c += 1
return {
count_state: c,
style_rows[c - 1]: gr.update(visible=True),
add_button: gr.update(visible=c < 5),
del_button: gr.update(visible=True),
}
def del_style_row(c):
c -= 1
return {
count_state: c,
style_rows[c]: gr.update(visible=False),
add_button: gr.update(visible=True),
del_button: gr.update(visible=c > 0),
}
add_outputs = [count_state, add_button, del_button] + style_rows
del_outputs = [count_state, add_button, del_button] + style_rows
add_button.click(fn=add_style_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
del_button.click(fn=del_style_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_ipadapter_event_handlers(prefix, ui_components):
ipa_rows = ui_components.get(f'ipadapter_rows_{prefix}')
if not ipa_rows: return
ipa_lora_strengths = ui_components[f'ipadapter_lora_strengths_{prefix}']
ipa_final_preset = ui_components[f'ipadapter_final_preset_{prefix}']
ipa_final_lora_strength = ui_components[f'ipadapter_final_lora_strength_{prefix}']
count_state = ui_components[f'ipadapter_count_state_{prefix}']
add_button = ui_components[f'add_ipadapter_button_{prefix}']
del_button = ui_components[f'delete_ipadapter_button_{prefix}']
accordion = ui_components[f'ipadapter_accordion_{prefix}']
def add_ipa_row(c):
c += 1
return {
count_state: c,
ipa_rows[c - 1]: gr.update(visible=True),
add_button: gr.update(visible=c < MAX_IPADAPTERS),
del_button: gr.update(visible=True),
}
def del_ipa_row(c):
c -= 1
return {
count_state: c,
ipa_rows[c]: gr.update(visible=False),
add_button: gr.update(visible=True),
del_button: gr.update(visible=c > 0),
}
add_outputs = [count_state, add_button, del_button] + ipa_rows
del_outputs = [count_state, add_button, del_button] + ipa_rows
add_button.click(fn=add_ipa_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
del_button.click(fn=del_ipa_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def on_preset_change(preset_value):
config = load_ipadapter_config()
faceid_presets = []
if config:
faceid_presets.extend(config.get("IPAdapter_FaceID_presets", {}).get("SDXL", []))
faceid_presets.extend(config.get("IPAdapter_FaceID_presets", {}).get("SD1.5", []))
is_visible = preset_value in faceid_presets
updates = [gr.update(visible=is_visible)] * (MAX_IPADAPTERS + 1)
return updates
all_lora_strength_sliders = [ipa_final_lora_strength] + ipa_lora_strengths
ipa_final_preset.change(fn=on_preset_change, inputs=[ipa_final_preset], outputs=all_lora_strength_sliders, show_progress=False)
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)
def create_reference_latent_event_handlers(prefix, ui_components):
ref_rows = ui_components.get(f'reference_latent_rows_{prefix}')
if not ref_rows: return
count_state = ui_components[f'reference_latent_count_state_{prefix}']
add_button = ui_components[f'add_reference_latent_button_{prefix}']
del_button = ui_components[f'delete_reference_latent_button_{prefix}']
images = ui_components[f'reference_latent_images_{prefix}']
def add_ref_row(c):
c += 1
return {
count_state: c,
ref_rows[c - 1]: gr.update(visible=True),
add_button: gr.update(visible=c < 10),
del_button: gr.update(visible=True),
}
def del_ref_row(c):
c -= 1
return {
count_state: c,
ref_rows[c]: gr.update(visible=False),
images[c]: None,
add_button: gr.update(visible=True),
del_button: gr.update(visible=c > 0),
}
add_outputs = [count_state, add_button, del_button] + ref_rows
del_outputs = [count_state, add_button, del_button] + ref_rows + images
add_button.click(fn=add_ref_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
del_button.click(fn=del_ref_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_hidream_o1_reference_event_handlers(prefix, ui_components):
ref_rows = ui_components.get(f'hidream_o1_reference_rows_{prefix}')
if not ref_rows: return
count_state = ui_components[f'hidream_o1_reference_count_state_{prefix}']
add_button = ui_components[f'add_hidream_o1_reference_button_{prefix}']
del_button = ui_components[f'delete_hidream_o1_reference_button_{prefix}']
images = ui_components[f'hidream_o1_reference_images_{prefix}']
def add_ref_row(c):
c += 1
return {
count_state: c,
ref_rows[c - 1]: gr.update(visible=True),
add_button: gr.update(visible=c < 10),
del_button: gr.update(visible=True),
}
def del_ref_row(c):
c -= 1
return {
count_state: c,
ref_rows[c]: gr.update(visible=False),
images[c]: None,
add_button: gr.update(visible=True),
del_button: gr.update(visible=c > 0),
}
add_outputs = [count_state, add_button, del_button] + ref_rows
del_outputs = [count_state, add_button, del_button] + ref_rows + images
add_button.click(fn=add_ref_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
del_button.click(fn=del_ref_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_joyai_reference_event_handlers(prefix, ui_components):
ref_rows = ui_components.get(f'joyai_reference_rows_{prefix}')
if not ref_rows: return
count_state = ui_components[f'joyai_reference_count_state_{prefix}']
add_button = ui_components[f'add_joyai_reference_button_{prefix}']
del_button = ui_components[f'delete_joyai_reference_button_{prefix}']
images = ui_components[f'joyai_reference_images_{prefix}']
def add_ref_row(c):
c += 1
return {
count_state: c,
ref_rows[c - 1]: gr.update(visible=True),
add_button: gr.update(visible=c < 2),
del_button: gr.update(visible=True),
}
def del_ref_row(c):
c -= 1
return {
count_state: c,
ref_rows[c]: gr.update(visible=False),
images[c]: None,
add_button: gr.update(visible=True),
del_button: gr.update(visible=c > 0),
}
add_outputs = [count_state, add_button, del_button] + ref_rows
del_outputs = [count_state, add_button, del_button] + ref_rows + images
add_button.click(fn=add_ref_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
del_button.click(fn=del_ref_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_reference_image_event_handlers(prefix, ui_components):
ref_rows = ui_components.get(f'reference_image_rows_{prefix}')
if not ref_rows: return
count_state = ui_components[f'reference_image_count_state_{prefix}']
add_button = ui_components[f'add_reference_image_button_{prefix}']
del_button = ui_components[f'delete_reference_image_button_{prefix}']
images = ui_components[f'reference_image_images_{prefix}']
def add_ref_row(c):
c += 1
return {
count_state: c,
ref_rows[c - 1]: gr.update(visible=True),
add_button: gr.update(visible=c < 10),
del_button: gr.update(visible=True),
}
def del_ref_row(c):
c -= 1
return {
count_state: c,
ref_rows[c]: gr.update(visible=False),
images[c]: None,
add_button: gr.update(visible=True),
del_button: gr.update(visible=c > 0),
}
add_outputs = [count_state, add_button, del_button] + ref_rows
del_outputs = [count_state, add_button, del_button] + ref_rows + images
add_button.click(fn=add_ref_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
del_button.click(fn=del_ref_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_embedding_event_handlers(prefix, ui_components):
rows = ui_components.get(f'embedding_rows_{prefix}')
if not rows: return
ids = ui_components[f'embeddings_ids_{prefix}']
files = ui_components[f'embeddings_files_{prefix}']
sources = ui_components[f'embeddings_sources_{prefix}']
upload_buttons = ui_components[f'embeddings_uploads_{prefix}']
count_state = ui_components[f'embedding_count_state_{prefix}']
add_button = ui_components[f'add_embedding_button_{prefix}']
del_button = ui_components[f'delete_embedding_button_{prefix}']
for i in range(MAX_EMBEDDINGS):
upload_buttons[i].upload(
fn=on_embedding_upload,
inputs=[upload_buttons[i]],
outputs=[ids[i], sources[i], files[i]],
show_progress=True
)
def add_row(c):
c += 1
return {
count_state: c,
rows[c - 1]: gr.update(visible=True),
add_button: gr.update(visible=c < MAX_EMBEDDINGS),
del_button: gr.update(visible=True)
}
def del_row(c):
c -= 1
return {
count_state: c,
rows[c]: gr.update(visible=False),
ids[c]: "",
files[c]: None,
add_button: gr.update(visible=True),
del_button: gr.update(visible=c > 0)
}
add_outputs = [count_state, add_button, del_button] + rows
del_outputs = [count_state, add_button, del_button] + rows + ids + files
add_button.click(fn=add_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
del_button.click(fn=del_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_conditioning_event_handlers(prefix, ui_components):
rows = ui_components.get(f'conditioning_rows_{prefix}')
if not rows: return
prompts = ui_components[f'conditioning_prompts_{prefix}']
count_state = ui_components[f'conditioning_count_state_{prefix}']
add_button = ui_components[f'add_conditioning_button_{prefix}']
del_button = ui_components[f'delete_conditioning_button_{prefix}']
def add_row(c):
c += 1
return {
count_state: c,
rows[c - 1]: gr.update(visible=True),
add_button: gr.update(visible=c < MAX_CONDITIONINGS),
del_button: gr.update(visible=True),
}
def del_row(c):
c -= 1
return {
count_state: c,
rows[c]: gr.update(visible=False),
prompts[c]: "",
add_button: gr.update(visible=True),
del_button: gr.update(visible=c > 0),
}
add_outputs = [count_state, add_button, del_button] + rows
del_outputs = [count_state, add_button, del_button] + rows + prompts
add_button.click(fn=add_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
del_button.click(fn=del_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_krea2_identity_edit_event_handlers(prefix, ui_components):
ref_rows = ui_components.get(f'krea2_identity_edit_rows_{prefix}')
if not ref_rows: return
count_state = ui_components[f'krea2_identity_edit_count_state_{prefix}']
add_button = ui_components[f'add_krea2_identity_edit_button_{prefix}']
del_button = ui_components[f'delete_krea2_identity_edit_button_{prefix}']
images = ui_components[f'krea2_identity_edit_images_{prefix}']
def add_ref_row(c):
c += 1
return {
count_state: c,
ref_rows[c - 1]: gr.update(visible=True),
add_button: gr.update(visible=c < 2),
del_button: gr.update(visible=True),
}
def del_ref_row(c):
c -= 1
return {
count_state: c,
ref_rows[c]: gr.update(visible=False),
images[c]: None,
add_button: gr.update(visible=True),
del_button: gr.update(visible=c > 0),
}
add_outputs = [count_state, add_button, del_button] + ref_rows
del_outputs = [count_state, add_button, del_button] + ref_rows + images
add_button.click(fn=add_ref_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
del_button.click(fn=del_ref_row, inputs=[count_state], outputs=del_outputs, show_progress=False)
def create_qwen_image_edit_event_handlers(prefix, ui_components):
ref_rows = ui_components.get(f'qwen_image_edit_rows_{prefix}')
if not ref_rows: return
count_state = ui_components[f'qwen_image_edit_count_state_{prefix}']
add_button = ui_components[f'add_qwen_image_edit_button_{prefix}']
del_button = ui_components[f'delete_qwen_image_edit_button_{prefix}']
images = ui_components[f'qwen_image_edit_images_{prefix}']
def add_ref_row(c):
c += 1
return {
count_state: c,
ref_rows[c - 1]: gr.update(visible=True),
add_button: gr.update(visible=c < 3),
del_button: gr.update(visible=True),
}
def del_ref_row(c):
c -= 1
return {
count_state: c,
ref_rows[c]: gr.update(visible=False),
images[c]: None,
add_button: gr.update(visible=True),
del_button: gr.update(visible=c > 0),
}
add_outputs = [count_state, add_button, del_button] + ref_rows
del_outputs = [count_state, add_button, del_button] + ref_rows + images
add_button.click(fn=add_ref_row, inputs=[count_state], outputs=add_outputs, show_progress=False)
del_button.click(fn=del_ref_row, inputs=[count_state], outputs=del_outputs, show_progress=False)16 unmodified lines171819202021222346 unmodified lines7071727374757669 unmodified lines14614714814814915015115251 unmodified lines20420520620720820921016 unmodified lines load_ipadapter_config
)
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, krea2_cn_types, krea2_cn_series, krea2_cn_filepaths, ipa_preset, lora_acc, cn_acc, anima_cn_acc, diffsynth_cn_acc, krea2_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, pid_acc=None, vae_acc=None, joyai_ref_acc=None, krea2_identity_edit_acc=None, ref_img_acc=None):
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, krea2_cn_types, krea2_cn_series, krea2_cn_filepaths, ipa_preset, lora_acc, cn_acc, anima_cn_acc, diffsynth_cn_acc, krea2_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, pid_acc=None, vae_acc=None, joyai_ref_acc=None, krea2_identity_edit_acc=None, qwen_image_edit_acc=None, ref_img_acc=None):
def update_fn(*args):
arch = args[0]
category = args[1]46 unmodified lines if hidream_o1_ref_acc: updates[hidream_o1_ref_acc] = gr.update(visible=('hidream_o1_reference' in enabled_chains))
if joyai_ref_acc: updates[joyai_ref_acc] = gr.update(visible=('joyai_reference' in enabled_chains))
if krea2_identity_edit_acc: updates[krea2_identity_edit_acc] = gr.update(visible=('krea2_identity_edit' in enabled_chains))
if qwen_image_edit_acc: updates[qwen_image_edit_acc] = gr.update(visible=('qwen_image_edit' in enabled_chains))
if ref_img_acc: updates[ref_img_acc] = gr.update(visible=('reference_image' in enabled_chains))
if pid_acc: updates[pid_acc] = gr.update(visible=('pid' in enabled_chains))
if vae_acc: updates[vae_acc] = gr.update(visible=('vae' in enabled_chains))69 unmodified lines return update_fn
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, krea2_cn_types, krea2_cn_series, krea2_cn_filepaths, arch_comp_ref, ipa_preset, lora_acc, cn_acc, anima_cn_acc, diffsynth_cn_acc, krea2_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, pid_acc=None, vae_acc=None, joyai_ref_acc=None, krea2_identity_edit_acc=None, ref_img_acc=None):
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, krea2_cn_types, krea2_cn_series, krea2_cn_filepaths, arch_comp_ref, ipa_preset, lora_acc, cn_acc, anima_cn_acc, diffsynth_cn_acc, krea2_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, pid_acc=None, vae_acc=None, joyai_ref_acc=None, krea2_identity_edit_acc=None, qwen_image_edit_acc=None, ref_img_acc=None):
def change_fn(*args):
model_name = args[0]
idx = 151 unmodified lines if hidream_o1_ref_acc: updates[hidream_o1_ref_acc] = gr.update(visible=('hidream_o1_reference' in enabled_chains))
if joyai_ref_acc: updates[joyai_ref_acc] = gr.update(visible=('joyai_reference' in enabled_chains))
if krea2_identity_edit_acc: updates[krea2_identity_edit_acc] = gr.update(visible=('krea2_identity_edit' in enabled_chains))
if qwen_image_edit_acc: updates[qwen_image_edit_acc] = gr.update(visible=('qwen_image_edit' in enabled_chains))
if ref_img_acc: updates[ref_img_acc] = gr.update(visible=('reference_image' in enabled_chains))
if pid_acc: updates[pid_acc] = gr.update(visible=('pid' in enabled_chains))
if vae_acc: updates[vae_acc] = gr.update(visible=('vae' in enabled_chains))123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285import gradio as grfrom .chain_handlers import ( create_lora_event_handlers, create_controlnet_event_handlers, create_anima_controlnet_lllite_event_handlers, create_diffsynth_controlnet_event_handlers, create_krea2_controlnet_event_handlers, create_ipadapter_event_handlers, create_embedding_event_handlers, create_conditioning_event_handlers, create_flux1_ipadapter_event_handlers, create_sd3_ipadapter_event_handlers, create_style_event_handlers, create_reference_latent_event_handlers, create_hidream_o1_reference_event_handlers, create_joyai_reference_event_handlers, create_krea2_identity_edit_event_handlers, create_reference_image_event_handlers)from .change_handlers import ( make_update_fn, make_model_change_fn, run_on_load, on_aspect_ratio_change)from .run_handlers import create_run_event
def attach_event_handlers(ui_components, demo): for prefix, task_type in [ ("txt2img", "txt2img"), ("img2img", "img2img"), ("inpaint", "inpaint"), ("outpaint", "outpaint"), ("hires_fix", "hires_fix"), ]:
arch_comp = ui_components.get(f'model_arch_{prefix}') cat_comp = ui_components.get(f'model_cat_{prefix}') model_comp = ui_components.get(f'base_model_{prefix}') clip_skip_comp = ui_components.get(f'clip_skip_{prefix}') or ui_components.get(f'{prefix}_clip_skip') guidance_comp = ui_components.get(f'guidance_{prefix}') or ui_components.get(f'{prefix}_guidance') aspect_ratio_comp = ui_components.get(f'aspect_ratio_{prefix}') or ui_components.get(f'{prefix}_aspect_ratio_dropdown') width_comp = ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width') height_comp = ui_components.get(f'height_{prefix}') or ui_components.get(f'{prefix}_height') cn_types_list = ui_components.get(f'controlnet_types_{prefix}', []) cn_series_list = ui_components.get(f'controlnet_series_{prefix}', []) cn_filepaths_list = ui_components.get(f'controlnet_filepaths_{prefix}', []) anima_cn_types_list = ui_components.get(f'anima_controlnet_lllite_types_{prefix}', []) anima_cn_series_list = ui_components.get(f'anima_controlnet_lllite_series_{prefix}', []) anima_cn_filepaths_list = ui_components.get(f'anima_controlnet_lllite_filepaths_{prefix}', [])
diffsynth_cn_types_list = ui_components.get(f'diffsynth_controlnet_types_{prefix}', []) diffsynth_cn_series_list = ui_components.get(f'diffsynth_controlnet_series_{prefix}', []) diffsynth_cn_filepaths_list = ui_components.get(f'diffsynth_controlnet_filepaths_{prefix}', [])
krea2_cn_types_list = ui_components.get(f'krea2_controlnet_types_{prefix}', []) krea2_cn_series_list = ui_components.get(f'krea2_controlnet_series_{prefix}', []) krea2_cn_filepaths_list = ui_components.get(f'krea2_controlnet_filepaths_{prefix}', []) lora_accordion = ui_components.get(f'lora_accordion_{prefix}') cn_accordion = ui_components.get(f'controlnet_accordion_{prefix}') anima_cn_accordion = ui_components.get(f'anima_controlnet_lllite_accordion_{prefix}') diffsynth_cn_accordion = ui_components.get(f'diffsynth_controlnet_accordion_{prefix}') krea2_cn_accordion = ui_components.get(f'krea2_controlnet_accordion_{prefix}') ipa_accordion = ui_components.get(f'ipadapter_accordion_{prefix}') sd3_ipa_accordion = ui_components.get(f'sd3_ipadapter_accordion_{prefix}') flux1_ipa_accordion = ui_components.get(f'flux1_ipadapter_accordion_{prefix}') style_accordion = ui_components.get(f'style_accordion_{prefix}') embedding_accordion = ui_components.get(f'embedding_accordion_{prefix}') conditioning_accordion = ui_components.get(f'conditioning_accordion_{prefix}') ref_latent_accordion = ui_components.get(f'reference_latent_accordion_{prefix}') hidream_o1_ref_accordion = ui_components.get(f'hidream_o1_reference_accordion_{prefix}') joyai_ref_accordion = ui_components.get(f'joyai_reference_accordion_{prefix}') krea2_identity_edit_accordion = ui_components.get(f'krea2_identity_edit_accordion_{prefix}') ref_img_accordion = ui_components.get(f'reference_image_accordion_{prefix}') pid_accordion = ui_components.get(f'pid_accordion_{prefix}') vae_accordion = ui_components.get(f'vae_accordion_{prefix}') ipa_preset_list = ui_components.get(f'ipadapter_final_preset_{prefix}') prompt_comp = ui_components.get(f'prompt_{prefix}') or ui_components.get(f'{prefix}_positive_prompt') neg_prompt_comp = ui_components.get(f'neg_prompt_{prefix}') or ui_components.get(f'{prefix}_negative_prompt') steps_comp = ui_components.get(f'steps_{prefix}') or ui_components.get(f'{prefix}_steps') cfg_comp = ui_components.get(f'cfg_{prefix}') or ui_components.get(f'{prefix}_cfg') sampler_comp = ui_components.get(f'sampler_{prefix}') or ui_components.get(f'{prefix}_sampler_name') scheduler_comp = ui_components.get(f'scheduler_{prefix}') or ui_components.get(f'{prefix}_scheduler') extra_comps = [prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp, width_comp, height_comp] valid_extra_comps = [c for c in extra_comps if c is not None] if arch_comp and cat_comp and model_comp: outputs = [model_comp, cat_comp] if clip_skip_comp: outputs.append(clip_skip_comp) if guidance_comp: outputs.append(guidance_comp) if aspect_ratio_comp: outputs.append(aspect_ratio_comp) outputs.extend(cn_types_list + cn_series_list + cn_filepaths_list) outputs.extend(anima_cn_types_list + anima_cn_series_list + anima_cn_filepaths_list) outputs.extend(diffsynth_cn_types_list + diffsynth_cn_series_list + diffsynth_cn_filepaths_list) outputs.extend(krea2_cn_types_list + krea2_cn_series_list + krea2_cn_filepaths_list) if lora_accordion: outputs.append(lora_accordion) if cn_accordion: outputs.append(cn_accordion) if anima_cn_accordion: outputs.append(anima_cn_accordion) if diffsynth_cn_accordion: outputs.append(diffsynth_cn_accordion) if krea2_cn_accordion: outputs.append(krea2_cn_accordion) if ipa_accordion: outputs.append(ipa_accordion) if sd3_ipa_accordion: outputs.append(sd3_ipa_accordion) if flux1_ipa_accordion: outputs.append(flux1_ipa_accordion) if style_accordion: outputs.append(style_accordion) if embedding_accordion: outputs.append(embedding_accordion) if conditioning_accordion: outputs.append(conditioning_accordion) if ref_latent_accordion: outputs.append(ref_latent_accordion) if hidream_o1_ref_accordion: outputs.append(hidream_o1_ref_accordion) if joyai_ref_accordion: outputs.append(joyai_ref_accordion) if krea2_identity_edit_accordion: outputs.append(krea2_identity_edit_accordion) if ref_img_accordion: outputs.append(ref_img_accordion) if pid_accordion: outputs.append(pid_accordion) if vae_accordion: outputs.append(vae_accordion) if ipa_preset_list: outputs.append(ipa_preset_list) outputs.extend(valid_extra_comps) update_fn = make_update_fn( model_comp, cat_comp, clip_skip_comp, aspect_ratio_comp, width_comp, height_comp, cn_types_list, cn_series_list, cn_filepaths_list, anima_cn_types_list, anima_cn_series_list, anima_cn_filepaths_list, diffsynth_cn_types_list, diffsynth_cn_series_list, diffsynth_cn_filepaths_list, krea2_cn_types_list, krea2_cn_series_list, krea2_cn_filepaths_list, ipa_preset_list, lora_accordion, cn_accordion, anima_cn_accordion, diffsynth_cn_accordion, krea2_cn_accordion, ipa_accordion, sd3_ipa_accordion, flux1_ipa_accordion, style_accordion, embedding_accordion, conditioning_accordion, ref_latent_accordion, hidream_o1_ref_accordion, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp, pid_acc=pid_accordion, vae_acc=vae_accordion, joyai_ref_acc=joyai_ref_accordion, krea2_identity_edit_acc=krea2_identity_edit_accordion, ref_img_acc=ref_img_accordion ) inputs = [arch_comp, cat_comp] if aspect_ratio_comp: inputs.append(aspect_ratio_comp) arch_comp.change(fn=update_fn, inputs=inputs, outputs=outputs) cat_comp.change(fn=update_fn, inputs=inputs, outputs=outputs)
if model_comp: outputs2 = [] if arch_comp: outputs2.append(arch_comp) if cat_comp: outputs2.append(cat_comp) if clip_skip_comp: outputs2.append(clip_skip_comp) if guidance_comp: outputs2.append(guidance_comp) if aspect_ratio_comp: outputs2.append(aspect_ratio_comp) outputs2.extend(cn_types_list + cn_series_list + cn_filepaths_list) outputs2.extend(anima_cn_types_list + anima_cn_series_list + anima_cn_filepaths_list) outputs2.extend(diffsynth_cn_types_list + diffsynth_cn_series_list + diffsynth_cn_filepaths_list) outputs2.extend(krea2_cn_types_list + krea2_cn_series_list + krea2_cn_filepaths_list) if lora_accordion: outputs2.append(lora_accordion) if cn_accordion: outputs2.append(cn_accordion) if anima_cn_accordion: outputs2.append(anima_cn_accordion) if diffsynth_cn_accordion: outputs2.append(diffsynth_cn_accordion) if krea2_cn_accordion: outputs2.append(krea2_cn_accordion) if ipa_accordion: outputs2.append(ipa_accordion) if sd3_ipa_accordion: outputs2.append(sd3_ipa_accordion) if flux1_ipa_accordion: outputs2.append(flux1_ipa_accordion) if style_accordion: outputs2.append(style_accordion) if embedding_accordion: outputs2.append(embedding_accordion) if conditioning_accordion: outputs2.append(conditioning_accordion) if ref_latent_accordion: outputs2.append(ref_latent_accordion) if hidream_o1_ref_accordion: outputs2.append(hidream_o1_ref_accordion) if joyai_ref_accordion: outputs2.append(joyai_ref_accordion) if krea2_identity_edit_accordion: outputs2.append(krea2_identity_edit_accordion) if ref_img_accordion: outputs2.append(ref_img_accordion) if pid_accordion: outputs2.append(pid_accordion) if vae_accordion: outputs2.append(vae_accordion) if ipa_preset_list: outputs2.append(ipa_preset_list) outputs2.extend(valid_extra_comps) if outputs2: inputs2 = [model_comp] if arch_comp: inputs2.append(arch_comp) if cat_comp: inputs2.append(cat_comp) if aspect_ratio_comp: inputs2.append(aspect_ratio_comp) change_fn = make_model_change_fn( cat_comp, clip_skip_comp, aspect_ratio_comp, width_comp, height_comp, cn_types_list, cn_series_list, cn_filepaths_list, anima_cn_types_list, anima_cn_series_list, anima_cn_filepaths_list, diffsynth_cn_types_list, diffsynth_cn_series_list, diffsynth_cn_filepaths_list, krea2_cn_types_list, krea2_cn_series_list, krea2_cn_filepaths_list, arch_comp, ipa_preset_list, lora_accordion, cn_accordion, anima_cn_accordion, diffsynth_cn_accordion, krea2_cn_accordion, ipa_accordion, sd3_ipa_accordion, flux1_ipa_accordion, style_accordion, embedding_accordion, conditioning_accordion, ref_latent_accordion, hidream_o1_ref_accordion, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp, pid_acc=pid_accordion, vae_acc=vae_accordion, joyai_ref_acc=joyai_ref_accordion, krea2_identity_edit_acc=krea2_identity_edit_accordion, ref_img_acc=ref_img_accordion ) model_comp.change(fn=change_fn, inputs=inputs2, outputs=outputs2)
create_lora_event_handlers(prefix, ui_components) create_controlnet_event_handlers(prefix, ui_components) create_anima_controlnet_lllite_event_handlers(prefix, ui_components) create_diffsynth_controlnet_event_handlers(prefix, ui_components) create_krea2_controlnet_event_handlers(prefix, ui_components) create_ipadapter_event_handlers(prefix, ui_components) create_embedding_event_handlers(prefix, ui_components) create_conditioning_event_handlers(prefix, ui_components) create_flux1_ipadapter_event_handlers(prefix, ui_components) create_sd3_ipadapter_event_handlers(prefix, ui_components) create_style_event_handlers(prefix, ui_components) create_reference_latent_event_handlers(prefix, ui_components) create_hidream_o1_reference_event_handlers(prefix, ui_components) create_joyai_reference_event_handlers(prefix, ui_components) create_krea2_identity_edit_event_handlers(prefix, ui_components) create_reference_image_event_handlers(prefix, ui_components) create_run_event(prefix, task_type, ui_components)
if 'view_mode_inpaint' in ui_components: def toggle_inpaint_fullscreen_view(view_mode): is_fullscreen = (view_mode == "Fullscreen View") other_elements_visible = not is_fullscreen editor_height = 800 if is_fullscreen else 272 updates = { ui_components['prompts_column_inpaint']: gr.update(visible=other_elements_visible), ui_components['params_and_gallery_row_inpaint']: gr.update(visible=other_elements_visible), ui_components['accordion_wrapper_inpaint']: gr.update(visible=other_elements_visible), ui_components['input_image_dict_inpaint']: gr.update(height=editor_height), } model_and_run_rows = ui_components.get('model_and_run_row_inpaint', []) for row in model_and_run_rows: updates[row] = gr.update(visible=other_elements_visible) return updates output_components = [] model_and_run_rows = ui_components.get('model_and_run_row_inpaint', []) if isinstance(model_and_run_rows, list): output_components.extend(model_and_run_rows) else: output_components.append(model_and_run_rows) output_components.extend([ ui_components['prompts_column_inpaint'], ui_components['params_and_gallery_row_inpaint'], ui_components['accordion_wrapper_inpaint'], ui_components['input_image_dict_inpaint'] ]) ui_components['view_mode_inpaint'].change( fn=toggle_inpaint_fullscreen_view, inputs=[ui_components['view_mode_inpaint']], outputs=output_components, show_progress=False )
all_load_outputs = [] for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]: if f'controlnet_types_{prefix}' in ui_components: all_load_outputs.extend(ui_components[f'controlnet_types_{prefix}']) all_load_outputs.extend(ui_components[f'controlnet_series_{prefix}']) all_load_outputs.extend(ui_components[f'controlnet_filepaths_{prefix}']) if f'anima_controlnet_lllite_types_{prefix}' in ui_components: all_load_outputs.extend(ui_components[f'anima_controlnet_lllite_types_{prefix}']) all_load_outputs.extend(ui_components[f'anima_controlnet_lllite_series_{prefix}']) all_load_outputs.extend(ui_components[f'anima_controlnet_lllite_filepaths_{prefix}']) if f'diffsynth_controlnet_types_{prefix}' in ui_components: all_load_outputs.extend(ui_components[f'diffsynth_controlnet_types_{prefix}']) all_load_outputs.extend(ui_components[f'diffsynth_controlnet_series_{prefix}']) all_load_outputs.extend(ui_components[f'diffsynth_controlnet_filepaths_{prefix}']) if f'krea2_controlnet_types_{prefix}' in ui_components: all_load_outputs.extend(ui_components[f'krea2_controlnet_types_{prefix}']) all_load_outputs.extend(ui_components[f'krea2_controlnet_series_{prefix}']) all_load_outputs.extend(ui_components[f'krea2_controlnet_filepaths_{prefix}']) if f'ipadapter_final_preset_{prefix}' in ui_components: all_load_outputs.extend(ui_components[f'ipadapter_lora_strengths_{prefix}']) all_load_outputs.append(ui_components[f'ipadapter_final_preset_{prefix}']) all_load_outputs.append(ui_components[f'ipadapter_final_lora_strength_{prefix}'])
if all_load_outputs: demo.load( fn=lambda: run_on_load(ui_components), outputs=all_load_outputs )
for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]: aspect_ratio_dropdown = ui_components.get(f'aspect_ratio_{prefix}') or ui_components.get(f'{prefix}_aspect_ratio_dropdown') width_component = ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width') height_component = ui_components.get(f'height_{prefix}') or ui_components.get(f'{prefix}_height') model_dropdown = ui_components.get(f'base_model_{prefix}') if aspect_ratio_dropdown and width_component and height_component and model_dropdown:import gradio as gr
from .chain_handlers import (
create_lora_event_handlers,
create_controlnet_event_handlers,
create_anima_controlnet_lllite_event_handlers,
create_diffsynth_controlnet_event_handlers,
create_krea2_controlnet_event_handlers,
create_ipadapter_event_handlers,
create_embedding_event_handlers,
create_conditioning_event_handlers,
create_flux1_ipadapter_event_handlers,
create_sd3_ipadapter_event_handlers,
create_style_event_handlers,
create_reference_latent_event_handlers,
create_hidream_o1_reference_event_handlers,
create_joyai_reference_event_handlers,
create_krea2_identity_edit_event_handlers,
create_qwen_image_edit_event_handlers,
create_reference_image_event_handlers
)
from .change_handlers import (
make_update_fn,
make_model_change_fn,
run_on_load,
on_aspect_ratio_change
)
from .run_handlers import create_run_event
def attach_event_handlers(ui_components, demo):
for prefix, task_type in [
("txt2img", "txt2img"), ("img2img", "img2img"), ("inpaint", "inpaint"),
("outpaint", "outpaint"), ("hires_fix", "hires_fix"),
]:
arch_comp = ui_components.get(f'model_arch_{prefix}')
cat_comp = ui_components.get(f'model_cat_{prefix}')
model_comp = ui_components.get(f'base_model_{prefix}')
clip_skip_comp = ui_components.get(f'clip_skip_{prefix}') or ui_components.get(f'{prefix}_clip_skip')
guidance_comp = ui_components.get(f'guidance_{prefix}') or ui_components.get(f'{prefix}_guidance')
aspect_ratio_comp = ui_components.get(f'aspect_ratio_{prefix}') or ui_components.get(f'{prefix}_aspect_ratio_dropdown')
width_comp = ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width')
height_comp = ui_components.get(f'height_{prefix}') or ui_components.get(f'{prefix}_height')
cn_types_list = ui_components.get(f'controlnet_types_{prefix}', [])
cn_series_list = ui_components.get(f'controlnet_series_{prefix}', [])
cn_filepaths_list = ui_components.get(f'controlnet_filepaths_{prefix}', [])
anima_cn_types_list = ui_components.get(f'anima_controlnet_lllite_types_{prefix}', [])
anima_cn_series_list = ui_components.get(f'anima_controlnet_lllite_series_{prefix}', [])
anima_cn_filepaths_list = ui_components.get(f'anima_controlnet_lllite_filepaths_{prefix}', [])
diffsynth_cn_types_list = ui_components.get(f'diffsynth_controlnet_types_{prefix}', [])
diffsynth_cn_series_list = ui_components.get(f'diffsynth_controlnet_series_{prefix}', [])
diffsynth_cn_filepaths_list = ui_components.get(f'diffsynth_controlnet_filepaths_{prefix}', [])
krea2_cn_types_list = ui_components.get(f'krea2_controlnet_types_{prefix}', [])
krea2_cn_series_list = ui_components.get(f'krea2_controlnet_series_{prefix}', [])
krea2_cn_filepaths_list = ui_components.get(f'krea2_controlnet_filepaths_{prefix}', [])
lora_accordion = ui_components.get(f'lora_accordion_{prefix}')
cn_accordion = ui_components.get(f'controlnet_accordion_{prefix}')
anima_cn_accordion = ui_components.get(f'anima_controlnet_lllite_accordion_{prefix}')
diffsynth_cn_accordion = ui_components.get(f'diffsynth_controlnet_accordion_{prefix}')
krea2_cn_accordion = ui_components.get(f'krea2_controlnet_accordion_{prefix}')
ipa_accordion = ui_components.get(f'ipadapter_accordion_{prefix}')
sd3_ipa_accordion = ui_components.get(f'sd3_ipadapter_accordion_{prefix}')
flux1_ipa_accordion = ui_components.get(f'flux1_ipadapter_accordion_{prefix}')
style_accordion = ui_components.get(f'style_accordion_{prefix}')
embedding_accordion = ui_components.get(f'embedding_accordion_{prefix}')
conditioning_accordion = ui_components.get(f'conditioning_accordion_{prefix}')
ref_latent_accordion = ui_components.get(f'reference_latent_accordion_{prefix}')
hidream_o1_ref_accordion = ui_components.get(f'hidream_o1_reference_accordion_{prefix}')
joyai_ref_accordion = ui_components.get(f'joyai_reference_accordion_{prefix}')
krea2_identity_edit_accordion = ui_components.get(f'krea2_identity_edit_accordion_{prefix}')
qwen_image_edit_accordion = ui_components.get(f'qwen_image_edit_accordion_{prefix}')
ref_img_accordion = ui_components.get(f'reference_image_accordion_{prefix}')
pid_accordion = ui_components.get(f'pid_accordion_{prefix}')
vae_accordion = ui_components.get(f'vae_accordion_{prefix}')
ipa_preset_list = ui_components.get(f'ipadapter_final_preset_{prefix}')
prompt_comp = ui_components.get(f'prompt_{prefix}') or ui_components.get(f'{prefix}_positive_prompt')
neg_prompt_comp = ui_components.get(f'neg_prompt_{prefix}') or ui_components.get(f'{prefix}_negative_prompt')
steps_comp = ui_components.get(f'steps_{prefix}') or ui_components.get(f'{prefix}_steps')
cfg_comp = ui_components.get(f'cfg_{prefix}') or ui_components.get(f'{prefix}_cfg')
sampler_comp = ui_components.get(f'sampler_{prefix}') or ui_components.get(f'{prefix}_sampler_name')
scheduler_comp = ui_components.get(f'scheduler_{prefix}') or ui_components.get(f'{prefix}_scheduler')
extra_comps = [prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp, width_comp, height_comp]
valid_extra_comps = [c for c in extra_comps if c is not None]
if arch_comp and cat_comp and model_comp:
outputs = [model_comp, cat_comp]
if clip_skip_comp: outputs.append(clip_skip_comp)
if guidance_comp: outputs.append(guidance_comp)
if aspect_ratio_comp: outputs.append(aspect_ratio_comp)
outputs.extend(cn_types_list + cn_series_list + cn_filepaths_list)
outputs.extend(anima_cn_types_list + anima_cn_series_list + anima_cn_filepaths_list)
outputs.extend(diffsynth_cn_types_list + diffsynth_cn_series_list + diffsynth_cn_filepaths_list)
outputs.extend(krea2_cn_types_list + krea2_cn_series_list + krea2_cn_filepaths_list)
if lora_accordion: outputs.append(lora_accordion)
if cn_accordion: outputs.append(cn_accordion)
if anima_cn_accordion: outputs.append(anima_cn_accordion)
if diffsynth_cn_accordion: outputs.append(diffsynth_cn_accordion)
if krea2_cn_accordion: outputs.append(krea2_cn_accordion)
if ipa_accordion: outputs.append(ipa_accordion)
if sd3_ipa_accordion: outputs.append(sd3_ipa_accordion)
if flux1_ipa_accordion: outputs.append(flux1_ipa_accordion)
if style_accordion: outputs.append(style_accordion)
if embedding_accordion: outputs.append(embedding_accordion)
if conditioning_accordion: outputs.append(conditioning_accordion)
if ref_latent_accordion: outputs.append(ref_latent_accordion)
if hidream_o1_ref_accordion: outputs.append(hidream_o1_ref_accordion)
if joyai_ref_accordion: outputs.append(joyai_ref_accordion)
if krea2_identity_edit_accordion: outputs.append(krea2_identity_edit_accordion)
if qwen_image_edit_accordion: outputs.append(qwen_image_edit_accordion)
if ref_img_accordion: outputs.append(ref_img_accordion)
if pid_accordion: outputs.append(pid_accordion)
if vae_accordion: outputs.append(vae_accordion)
if ipa_preset_list: outputs.append(ipa_preset_list)
outputs.extend(valid_extra_comps)
update_fn = make_update_fn(
model_comp, cat_comp, clip_skip_comp, aspect_ratio_comp, width_comp, height_comp,
cn_types_list, cn_series_list, cn_filepaths_list,
anima_cn_types_list, anima_cn_series_list, anima_cn_filepaths_list,
diffsynth_cn_types_list, diffsynth_cn_series_list, diffsynth_cn_filepaths_list,
krea2_cn_types_list, krea2_cn_series_list, krea2_cn_filepaths_list,
ipa_preset_list, lora_accordion, cn_accordion, anima_cn_accordion, diffsynth_cn_accordion, krea2_cn_accordion, ipa_accordion, sd3_ipa_accordion, flux1_ipa_accordion, style_accordion, embedding_accordion, conditioning_accordion,
ref_latent_accordion, hidream_o1_ref_accordion, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp,
pid_acc=pid_accordion, vae_acc=vae_accordion, joyai_ref_acc=joyai_ref_accordion, krea2_identity_edit_acc=krea2_identity_edit_accordion, qwen_image_edit_acc=qwen_image_edit_accordion, ref_img_acc=ref_img_accordion
)
inputs = [arch_comp, cat_comp]
if aspect_ratio_comp:
inputs.append(aspect_ratio_comp)
arch_comp.change(fn=update_fn, inputs=inputs, outputs=outputs)
cat_comp.change(fn=update_fn, inputs=inputs, outputs=outputs)
if model_comp:
outputs2 = []
if arch_comp: outputs2.append(arch_comp)
if cat_comp: outputs2.append(cat_comp)
if clip_skip_comp: outputs2.append(clip_skip_comp)
if guidance_comp: outputs2.append(guidance_comp)
if aspect_ratio_comp: outputs2.append(aspect_ratio_comp)
outputs2.extend(cn_types_list + cn_series_list + cn_filepaths_list)
outputs2.extend(anima_cn_types_list + anima_cn_series_list + anima_cn_filepaths_list)
outputs2.extend(diffsynth_cn_types_list + diffsynth_cn_series_list + diffsynth_cn_filepaths_list)
outputs2.extend(krea2_cn_types_list + krea2_cn_series_list + krea2_cn_filepaths_list)
if lora_accordion: outputs2.append(lora_accordion)
if cn_accordion: outputs2.append(cn_accordion)
if anima_cn_accordion: outputs2.append(anima_cn_accordion)
if diffsynth_cn_accordion: outputs2.append(diffsynth_cn_accordion)
if krea2_cn_accordion: outputs2.append(krea2_cn_accordion)
if ipa_accordion: outputs2.append(ipa_accordion)
if sd3_ipa_accordion: outputs2.append(sd3_ipa_accordion)
if flux1_ipa_accordion: outputs2.append(flux1_ipa_accordion)
if style_accordion: outputs2.append(style_accordion)
if embedding_accordion: outputs2.append(embedding_accordion)
if conditioning_accordion: outputs2.append(conditioning_accordion)
if ref_latent_accordion: outputs2.append(ref_latent_accordion)
if hidream_o1_ref_accordion: outputs2.append(hidream_o1_ref_accordion)
if joyai_ref_accordion: outputs2.append(joyai_ref_accordion)
if krea2_identity_edit_accordion: outputs2.append(krea2_identity_edit_accordion)
if qwen_image_edit_accordion: outputs2.append(qwen_image_edit_accordion)
if ref_img_accordion: outputs2.append(ref_img_accordion)
if pid_accordion: outputs2.append(pid_accordion)
if vae_accordion: outputs2.append(vae_accordion)
if ipa_preset_list: outputs2.append(ipa_preset_list)
outputs2.extend(valid_extra_comps)
if outputs2:
inputs2 = [model_comp]
if arch_comp: inputs2.append(arch_comp)
if cat_comp: inputs2.append(cat_comp)
if aspect_ratio_comp: inputs2.append(aspect_ratio_comp)
change_fn = make_model_change_fn(
cat_comp, clip_skip_comp, aspect_ratio_comp, width_comp, height_comp,
cn_types_list, cn_series_list, cn_filepaths_list,
anima_cn_types_list, anima_cn_series_list, anima_cn_filepaths_list,
diffsynth_cn_types_list, diffsynth_cn_series_list, diffsynth_cn_filepaths_list,
krea2_cn_types_list, krea2_cn_series_list, krea2_cn_filepaths_list,
arch_comp, ipa_preset_list, lora_accordion, cn_accordion, anima_cn_accordion, diffsynth_cn_accordion, krea2_cn_accordion, ipa_accordion, sd3_ipa_accordion, flux1_ipa_accordion, style_accordion, embedding_accordion, conditioning_accordion,
ref_latent_accordion, hidream_o1_ref_accordion, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp,
pid_acc=pid_accordion, vae_acc=vae_accordion, joyai_ref_acc=joyai_ref_accordion, krea2_identity_edit_acc=krea2_identity_edit_accordion, qwen_image_edit_acc=qwen_image_edit_accordion, ref_img_acc=ref_img_accordion
)
model_comp.change(fn=change_fn, inputs=inputs2, outputs=outputs2)
create_lora_event_handlers(prefix, ui_components)
create_controlnet_event_handlers(prefix, ui_components)
create_anima_controlnet_lllite_event_handlers(prefix, ui_components)
create_diffsynth_controlnet_event_handlers(prefix, ui_components)
create_krea2_controlnet_event_handlers(prefix, ui_components)
create_ipadapter_event_handlers(prefix, ui_components)
create_embedding_event_handlers(prefix, ui_components)
create_conditioning_event_handlers(prefix, ui_components)
create_flux1_ipadapter_event_handlers(prefix, ui_components)
create_sd3_ipadapter_event_handlers(prefix, ui_components)
create_style_event_handlers(prefix, ui_components)
create_reference_latent_event_handlers(prefix, ui_components)
create_hidream_o1_reference_event_handlers(prefix, ui_components)
create_joyai_reference_event_handlers(prefix, ui_components)
create_krea2_identity_edit_event_handlers(prefix, ui_components)
create_qwen_image_edit_event_handlers(prefix, ui_components)
create_reference_image_event_handlers(prefix, ui_components)
create_run_event(prefix, task_type, ui_components)
if 'view_mode_inpaint' in ui_components:
def toggle_inpaint_fullscreen_view(view_mode):
is_fullscreen = (view_mode == "Fullscreen View")
other_elements_visible = not is_fullscreen
editor_height = 800 if is_fullscreen else 272
updates = {
ui_components['prompts_column_inpaint']: gr.update(visible=other_elements_visible),
ui_components['params_and_gallery_row_inpaint']: gr.update(visible=other_elements_visible),
ui_components['accordion_wrapper_inpaint']: gr.update(visible=other_elements_visible),
ui_components['input_image_dict_inpaint']: gr.update(height=editor_height),
}
model_and_run_rows = ui_components.get('model_and_run_row_inpaint', [])
for row in model_and_run_rows:
updates[row] = gr.update(visible=other_elements_visible)
return updates
output_components = []
model_and_run_rows = ui_components.get('model_and_run_row_inpaint', [])
if isinstance(model_and_run_rows, list):
output_components.extend(model_and_run_rows)
else:
output_components.append(model_and_run_rows)
output_components.extend([
ui_components['prompts_column_inpaint'],
ui_components['params_and_gallery_row_inpaint'],
ui_components['accordion_wrapper_inpaint'],
ui_components['input_image_dict_inpaint']
])
ui_components['view_mode_inpaint'].change(
fn=toggle_inpaint_fullscreen_view,
inputs=[ui_components['view_mode_inpaint']],
outputs=output_components,
show_progress=False
)
all_load_outputs = []
for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]:
if f'controlnet_types_{prefix}' in ui_components:
all_load_outputs.extend(ui_components[f'controlnet_types_{prefix}'])
all_load_outputs.extend(ui_components[f'controlnet_series_{prefix}'])
all_load_outputs.extend(ui_components[f'controlnet_filepaths_{prefix}'])
if f'anima_controlnet_lllite_types_{prefix}' in ui_components:
all_load_outputs.extend(ui_components[f'anima_controlnet_lllite_types_{prefix}'])
all_load_outputs.extend(ui_components[f'anima_controlnet_lllite_series_{prefix}'])
all_load_outputs.extend(ui_components[f'anima_controlnet_lllite_filepaths_{prefix}'])
if f'diffsynth_controlnet_types_{prefix}' in ui_components:
all_load_outputs.extend(ui_components[f'diffsynth_controlnet_types_{prefix}'])
all_load_outputs.extend(ui_components[f'diffsynth_controlnet_series_{prefix}'])
all_load_outputs.extend(ui_components[f'diffsynth_controlnet_filepaths_{prefix}'])
if f'krea2_controlnet_types_{prefix}' in ui_components:
all_load_outputs.extend(ui_components[f'krea2_controlnet_types_{prefix}'])
all_load_outputs.extend(ui_components[f'krea2_controlnet_series_{prefix}'])
all_load_outputs.extend(ui_components[f'krea2_controlnet_filepaths_{prefix}'])
if f'ipadapter_final_preset_{prefix}' in ui_components:
all_load_outputs.extend(ui_components[f'ipadapter_lora_strengths_{prefix}'])
all_load_outputs.append(ui_components[f'ipadapter_final_preset_{prefix}'])
all_load_outputs.append(ui_components[f'ipadapter_final_lora_strength_{prefix}'])
if all_load_outputs:
demo.load(
fn=lambda: run_on_load(ui_components),
outputs=all_load_outputs
)
for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]:
aspect_ratio_dropdown = ui_components.get(f'aspect_ratio_{prefix}') or ui_components.get(f'{prefix}_aspect_ratio_dropdown')
width_component = ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width')
height_component = ui_components.get(f'height_{prefix}') or ui_components.get(f'{prefix}_height')
model_dropdown = ui_components.get(f'base_model_{prefix}')
if aspect_ratio_dropdown and width_component and height_component and model_dropdown:
aspect_ratio_dropdown.change(fn=on_aspect_ratio_change, inputs=[aspect_ratio_dropdown, model_dropdown], outputs=[width_component, height_component], show_progress=False)53 unmodified lines545556575859605 unmodified lines666768686970717225 unmodified lines989910010110210310453 unmodified lines hidream_o1_reference_data_components = ui_components.get(f'all_hidream_o1_reference_components_flat_{prefix}', [])
joyai_reference_data_components = ui_components.get(f'all_joyai_reference_components_flat_{prefix}', [])
krea2_identity_edit_data_components = ui_components.get(f'all_krea2_identity_edit_components_flat_{prefix}', [])
qwen_image_edit_data_components = ui_components.get(f'all_qwen_image_edit_components_flat_{prefix}', [])
reference_image_data_components = ui_components.get(f'all_reference_image_components_flat_{prefix}', [])
run_inputs_map['vae_source'] = ui_components.get(f'vae_source_{prefix}')5 unmodified lines all_chains = [
lora_data_components, controlnet_data_components, anima_controlnet_lllite_data_components, diffsynth_controlnet_data_components, krea2_controlnet_data_components, ipadapter_data_components,
sd3_ipadapter_data_components, flux1_ipadapter_data_components, style_data_components,
embedding_data_components, conditioning_data_components, reference_latent_data_components, hidream_o1_reference_data_components, joyai_reference_data_components, krea2_identity_edit_data_components, reference_image_data_components
embedding_data_components, conditioning_data_components, reference_latent_data_components, hidream_o1_reference_data_components, joyai_reference_data_components, krea2_identity_edit_data_components, qwen_image_edit_data_components, reference_image_data_components
]
for chain in all_chains:
if chain:25 unmodified lines assign_chain_data('hidream_o1_reference_data', hidream_o1_reference_data_components)
assign_chain_data('joyai_reference_data', joyai_reference_data_components)
assign_chain_data('krea2_identity_edit_data', krea2_identity_edit_data_components)
assign_chain_data('qwen_image_edit_data', qwen_image_edit_data_components)
assign_chain_data('reference_image_data', reference_image_data_components)
return ui_dict6 unmodified lines789101011121389 unmodified lines1031041051061071081096 unmodified lines create_conditioning_ui, create_vae_override_ui,
create_model_architecture_filter_ui, create_category_filter_ui,
create_sd3_ipadapter_ui, create_flux1_ipadapter_ui, create_style_ui,
create_reference_latent_ui, create_hidream_o1_reference_ui, create_joyai_reference_ui, create_reference_image_ui, create_krea2_identity_edit_ui
create_reference_latent_ui, create_hidream_o1_reference_ui, create_joyai_reference_ui, create_reference_image_ui, create_krea2_identity_edit_ui, create_qwen_image_edit_ui
)
default_vals = MODEL_DEFAULTS_CONFIG.get('Default', {})89 unmodified lines components.update(create_hidream_o1_reference_ui(prefix))
components.update(create_joyai_reference_ui(prefix))
components.update(create_krea2_identity_edit_ui(prefix))
components.update(create_qwen_image_edit_ui(prefix))
components.update(create_reference_image_ui(prefix))
components.update(create_vae_override_ui(prefix))
6 unmodified lines789101011121370 unmodified lines848586878889906 unmodified lines create_conditioning_ui, create_vae_override_ui,
create_model_architecture_filter_ui, create_category_filter_ui,
create_sd3_ipadapter_ui, create_flux1_ipadapter_ui, create_style_ui,
create_reference_latent_ui, create_hidream_o1_reference_ui, create_joyai_reference_ui, create_reference_image_ui, create_krea2_identity_edit_ui
create_reference_latent_ui, create_hidream_o1_reference_ui, create_joyai_reference_ui, create_reference_image_ui, create_krea2_identity_edit_ui, create_qwen_image_edit_ui
)
default_vals = MODEL_DEFAULTS_CONFIG.get('Default', {})70 unmodified lines components.update(create_hidream_o1_reference_ui(prefix))
components.update(create_joyai_reference_ui(prefix))
components.update(create_krea2_identity_edit_ui(prefix))
components.update(create_qwen_image_edit_ui(prefix))
components.update(create_reference_image_ui(prefix))
components.update(create_vae_override_ui(prefix))
5 unmodified lines67899101112103 unmodified lines1161171181191201211225 unmodified lines create_conditioning_ui, create_vae_override_ui,
create_model_architecture_filter_ui, create_category_filter_ui,
create_sd3_ipadapter_ui, create_flux1_ipadapter_ui, create_style_ui,
create_reference_latent_ui, create_hidream_o1_reference_ui, create_joyai_reference_ui, create_reference_image_ui, create_krea2_identity_edit_ui
create_reference_latent_ui, create_hidream_o1_reference_ui, create_joyai_reference_ui, create_reference_image_ui, create_krea2_identity_edit_ui, create_qwen_image_edit_ui
)
default_vals = MODEL_DEFAULTS_CONFIG.get('Default', {})103 unmodified lines components.update(create_hidream_o1_reference_ui(prefix))
components.update(create_joyai_reference_ui(prefix))
components.update(create_krea2_identity_edit_ui(prefix))
components.update(create_qwen_image_edit_ui(prefix))
components.update(create_reference_image_ui(prefix))
components.update(create_vae_override_ui(prefix))
components[f'accordion_wrapper_{prefix}'] = accordion_wrapper6 unmodified lines789101011121385 unmodified lines991001011021031041056 unmodified lines create_conditioning_ui, create_vae_override_ui,
create_model_architecture_filter_ui, create_category_filter_ui,
create_sd3_ipadapter_ui, create_flux1_ipadapter_ui, create_style_ui,
create_reference_latent_ui, create_hidream_o1_reference_ui, create_joyai_reference_ui, create_reference_image_ui, create_krea2_identity_edit_ui
create_reference_latent_ui, create_hidream_o1_reference_ui, create_joyai_reference_ui, create_reference_image_ui, create_krea2_identity_edit_ui, create_qwen_image_edit_ui
)
default_vals = MODEL_DEFAULTS_CONFIG.get('Default', {})85 unmodified lines components.update(create_hidream_o1_reference_ui(prefix))
components.update(create_joyai_reference_ui(prefix))
components.update(create_krea2_identity_edit_ui(prefix))
components.update(create_qwen_image_edit_ui(prefix))
components.update(create_reference_image_ui(prefix))
components.update(create_vae_override_ui(prefix))
5 unmodified lines6789910111243 unmodified lines565758596061625 unmodified lines create_conditioning_ui, create_vae_override_ui,
create_model_architecture_filter_ui, create_category_filter_ui,
create_sd3_ipadapter_ui, create_flux1_ipadapter_ui, create_style_ui,
create_reference_latent_ui, create_hidream_o1_reference_ui, create_joyai_reference_ui, create_reference_image_ui, create_krea2_identity_edit_ui,
create_reference_latent_ui, create_hidream_o1_reference_ui, create_joyai_reference_ui, create_reference_image_ui, create_krea2_identity_edit_ui, create_qwen_image_edit_ui,
create_pid_ui
)
43 unmodified lines components.update(create_hidream_o1_reference_ui(prefix))
components.update(create_joyai_reference_ui(prefix))
components.update(create_krea2_identity_edit_ui(prefix))
components.update(create_qwen_image_edit_ui(prefix))
components.update(create_reference_image_ui(prefix))
components.update(create_vae_override_ui(prefix))
components.update(create_pid_ui(prefix))797 unmodified lines798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830797 unmodified lines
components[key('all_krea2_identity_edit_components_flat')] = ref_image_inputs
return components
def create_qwen_image_edit_ui(prefix: str, max_units=3):
components = {}
key = lambda name: f"{name}_{prefix}"
with gr.Accordion("Qwen-Image Edit Settings", open=False, visible=('qwen_image_edit' in default_enabled_chains)) as ref_accordion:
components[key('qwen_image_edit_accordion')] = ref_accordion
gr.Markdown("💡 **Tip:** (lightx2v/Qwen-Image-Edit-2511-Lightning recommended) In txt2img mode, adding a single reference image performs an **Image Edit**, while adding multiple images performs an **Image Combine**.")
ref_image_groups = []
ref_image_inputs = []
with gr.Row():
for i in range(max_units):
with gr.Column(visible=(i < 1), min_width=160) as img_col:
img_comp = gr.Image(type="pil", label=f"Ref. {i+1}", sources=["upload"], height=150)
ref_image_groups.append(img_col)
ref_image_inputs.append(img_comp)
components[key('qwen_image_edit_rows')] = ref_image_groups
components[key('qwen_image_edit_images')] = ref_image_inputs
with gr.Row():
components[key('add_qwen_image_edit_button')] = gr.Button("✚ Add Reference Image")
components[key('delete_qwen_image_edit_button')] = gr.Button("➖ Delete Reference Image", visible=False)
components[key('qwen_image_edit_count_state')] = gr.State(1)
components[key('all_qwen_image_edit_components_flat')] = ref_image_inputs
return components589 unmodified lines5905915925935945955965975985992 unmodified lines602603604605606607608609610611612613614615616617618619620621622623624589 unmodified lines repo_id: "Comfy-Org/z_image"
repository_file_path: "split_files/diffusion_models/z_image_bf16.safetensors"
# Qwen-Image
- filename: "qwen_image_2512_fp8_e4m3fn_scaled_comfyui_4steps_v1.0.safetensors"
source: "hf"
repo_id: "lightx2v/Qwen-Image-2512-Lightning"
repository_file_path: "qwen_image_2512_fp8_e4m3fn_scaled_comfyui_4steps_v1.0.safetensors"
- filename: "qwen_image_2512_fp8_e4m3fn.safetensors"
source: "hf"
repo_id: "Comfy-Org/Qwen-Image_ComfyUI"2 unmodified lines source: "hf"
repo_id: "Comfy-Org/Qwen-Image_ComfyUI"
repository_file_path: "split_files/diffusion_models/qwen_image_nvfp4.safetensors"
# Qwen-Image-Edit
- filename: "qwen_image_edit_2511_fp8_e4m3fn_scaled_lightning_comfyui_4steps_v1.0.safetensors"
source: "hf"
repo_id: "lightx2v/Qwen-Image-Edit-2511-Lightning"
repository_file_path: "qwen_image_edit_2511_fp8_e4m3fn_scaled_lightning_comfyui_4steps_v1.0.safetensors"
- filename: "qwen_image_edit_2511_int8_convrot.safetensors"
source: "hf"
repo_id: "Comfy-Org/Qwen-Image-Edit_ComfyUI"
repository_file_path: "split_files/diffusion_models/qwen_image_edit_2511_int8_convrot.safetensors"
- filename: "qwen_image_edit_2509_fp8mixed.safetensors"
source: "hf"
repo_id: "Comfy-Org/Qwen-Image-Edit_ComfyUI"
repository_file_path: "split_files/diffusion_models/qwen_image_edit_2509_fp8mixed.safetensors"
- filename: "qwen_image_edit_fp8_e4m3fn.safetensors"
source: "hf"
repo_id: "Comfy-Org/Qwen-Image-Edit_ComfyUI"
repository_file_path: "split_files/diffusion_models/qwen_image_edit_fp8_e4m3fn.safetensors"
# Kandinsky-5
- filename: "kandinsky5lite_t2i.safetensors"
source: "hf"76 unmodified lines7778798081828376 unmodified lines - lora
- controlnet
- conditioning
- qwen_image_edit
- vae
- pid
32 unmodified lines333435363738394013 unmodified lines5455565758596032 unmodified lines module: "chain_injectors.joyai_reference_injector"
dynamic_krea2_identity_edit_chains:
module: "chain_injectors.krea2_identity_edit_injector"
dynamic_qwen_image_edit_chains:
module: "chain_injectors.qwen_image_edit_injector"
dynamic_reference_image_chains:
module: "chain_injectors.reference_image_injector"
dynamic_pid_chains:13 unmodified lines - dynamic_controlnet_chains
- dynamic_krea2_controlnet_chains
- dynamic_krea2_identity_edit_chains
- dynamic_qwen_image_edit_chains
- dynamic_anima_controlnet_lllite_chains
- dynamic_hidream_o1_smoothing_chains
- dynamic_hidream_o1_reference_chains124 unmodified lines125126127128129130131132133134135136124 unmodified lines cfg: 4.0
sampler_name: "euler"
scheduler: "simple"
"lightx2v/Qwen-Image-2512-Lightning":
steps: 4
cfg: 1.0
"lightx2v/Qwen-Image-Edit-2511-Lightning":
steps: 4
cfg: 1.0
LongCat-Image:
_defaults:155 unmodified lines1561571581591601611621631641651664 unmodified lines171172173174175176177178179180181182183184185186187188189190191192193194195196155 unmodified lines Qwen-Image:
latent_type: sd3_latent
models:
- display_name: "lightx2v/Qwen-Image-2512-Lightning"
components:
unet: "qwen_image_2512_fp8_e4m3fn_scaled_comfyui_4steps_v1.0.safetensors"
vae: "qwen_image_vae.safetensors"
clip: "qwen_2.5_vl_7b_nvfp4.safetensors"
- display_name: "Qwen-Image-2512"
components:
unet: "qwen_image_2512_fp8_e4m3fn.safetensors"4 unmodified lines unet: "qwen_image_nvfp4.safetensors"
vae: "qwen_image_vae.safetensors"
clip: "qwen_2.5_vl_7b_nvfp4.safetensors"
- display_name: "lightx2v/Qwen-Image-Edit-2511-Lightning"
components:
unet: "qwen_image_edit_2511_fp8_e4m3fn_scaled_lightning_comfyui_4steps_v1.0.safetensors"
vae: "qwen_image_vae.safetensors"
clip: "qwen_2.5_vl_7b_nvfp4.safetensors"
- display_name: "Qwen-Image-Edit-2511"
components:
unet: "qwen_image_edit_2511_int8_convrot.safetensors"
vae: "qwen_image_vae.safetensors"
clip: "qwen_2.5_vl_7b_nvfp4.safetensors"
- display_name: "Qwen-Image-Edit-2509"
components:
unet: "qwen_image_edit_2509_fp8mixed.safetensors"
vae: "qwen_image_vae.safetensors"
clip: "qwen_2.5_vl_7b_nvfp4.safetensors"
- display_name: "Qwen-Image-Edit"
components:
unet: "qwen_image_edit_fp8_e4m3fn.safetensors"
vae: "qwen_image_vae.safetensors"
clip: "qwen_2.5_vl_7b_nvfp4.safetensors"
LongCat-Image:
latent_type: sd3_latent
models:README.md+6
chain_injectors/qwen_image_edit_injector.pyAdded+156
core/pipelines/pipeline_input_processor.py+12
core/pipelines/sd_image_pipeline.py+2
core/pipelines/workflow_recipes/_partials/conditioning/qwen-image.yaml+9
ui/events/chain_handlers.py+924-891
ui/events/change_handlers.py+4-2
ui/events/main.py+284-279
ui/events/run_handlers.py+3-1
ui/shared/hires_fix_ui.py+2-1
ui/shared/img2img_ui.py+2-1
ui/shared/inpaint_ui.py+2-1
ui/shared/outpaint_ui.py+2-1
ui/shared/txt2img_ui.py+2-1
ui/shared/ui_components.py+29
yaml/file_list.yaml+21
yaml/image_gen_features.yaml+1
yaml/injectors.yaml+3
yaml/model_defaults.yaml+6
yaml/model_list.yaml+25