Spaces:
Running on Zero
Running on Zero
feat: add Ming-Image architecture & Prompt Enhancer and update upstream deps
Browse filesFiles changed (22)
- README.md+4
- chain_injectors/ming_image_prompt_enhancer_injector.pyAdded+262
- chain_injectors/qwen_image_2_1_prompt_enhancer_injector.py+1-1
- core/pipelines/pipeline_input_processor.py+15-1
- core/pipelines/sd_image_pipeline.py+2
- core/pipelines/workflow_executor.py+4
- core/pipelines/workflow_recipes/_partials/conditioning/ming-image.yamlAdded+108
- mcp_tools/common.py+29-2
- requirements.txt+1-1
- ui/events/change_handlers.py+4-2
- ui/events/main.py+7-2
- ui/events/run_handlers.py+9
- ui/imagegen_ui.py+2-1
- ui/shared/ui_components.py+54-2
- yaml/chain_features.yaml+27-2
- yaml/constants.yaml+8
- yaml/file_list.yaml+21-1
- yaml/model_architecture_features.yaml+6
- yaml/model_architectures.yaml+3
- yaml/model_defaults.yaml+7
- yaml/model_list.yaml+8
- yaml/task_features.yaml+5
51 unmodified lines52535455565758596061626389 unmodified lines15315415515615715815912 unmodified lines17217317417517617717851 unmodified lines - Comfy-Org/LongCat-Image
- Comfy-Org/Lumina_Image_2.0_Repackaged
- Comfy-Org/Mage-Flow
- Comfy-Org/Ming-Image
- Comfy-Org/NewBie-image-Exp0.1_repackaged
- Comfy-Org/Omnigen2_ComfyUI_repackaged
- Comfy-Org/Ovis-Image
- Comfy-Org/PixelDiT
- Comfy-Org/Qwen3.8-27B
- Comfy-Org/Qwen-Image_ComfyUI
- Comfy-Org/Qwen-Image-2.1
- Comfy-Org/Qwen-Image-Edit_ComfyUI89 unmodified lines - HiDream-ai/HiDream-O1-Image
- HiDream-ai/HiDream-O1-Image-Dev
- ideogram-ai/ideogram-4-fp8
- inclusionAI/Ming-Image-0.1-Design
- kohya-ss/Anima-LLLite
- krea/Krea-2-Raw
- krea/Krea-2-Turbo12 unmodified lines - nvidia/PiD
- nvidia/PixelDiT-1300M-1024px
- OmniGen2/OmniGen2
- Qwen/Qwen3.8-27B
- Qwen/Qwen-Image
- Qwen/Qwen-Image-2512
- Qwen/Qwen-Image-2.1123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262"""Ming-Image Prompt Enhancer Chain Injector.
This injector automatically integrates the Qwen3.8-27B prompt enhancement model intothe Ming-Image generation workflow:- Detects whether the task is pure text-to-image (T2I) or involves images (I2I, inpainting, outpainting, hires.fix, or multi-reference images).- Uses the Qwen3.8-27B PE text encoder: qwen3.8_27b_w4a8.safetensors (type: qwen_image).- Handles single or multi-reference inputs: multiple reference images are stitched into a structured grid layout via ComfyUI native ImageStitch nodes and scaled via ImageScaleToTotalPixels.- Supports reasoning mode (thinking=True) leveraging ComfyUI TextGenerate native reasoning separation (output slot 0 outputs clean prompt text, while output slot 1 isolates reasoning chain)."""
try: from utils.app_utils import ensure_file_downloadedexcept ImportError: ensure_file_downloaded = None
DEFAULT_MING_IMAGE_SYSTEM_PROMPT = ( "You are a senior visual designer and image-prompt engineer. Expand the user's request into one precise, high-resolution Figma-style caption. Return only one JSON object. " "Use exactly two top-level keys. `canvas_settings` contains exactly `aspect_ratio`, `ambient_lighting`, and `image_style`. `layers` lists visible groups from background to topmost overlay. Every layer contains exactly `description`, `coordinates`, `hierarchy_and_relation`, and `color_specs`; `color_specs` is an array of hex colors. " '`coordinates` MUST be one string, never an object or array, in exactly this form: `"cx: 0.500, cy: 0.500, w: 1.000, h: 1.000"`. Values are normalized; each bbox encloses its complete owned object and stays inside the canvas. ' "A layer is one selectable visible semantic group: background, full person, coherent object, panel, card, row, or text block. Prefer the fewest groups that preserve the layout. Keep people and objects intact. Never create invisible parents, guides, placeholders, empty layers, duplicate summaries, or multiple owners for one element. " "Preserve every user-supplied rendered string character-for-character and as one contiguous string. Unless multiple visible copies are requested, it must occur exactly once across all `description` fields and zero times in `hierarchy_and_relation`. Quote it only where describing its visible rendering; refer to the related subject elsewhere with unquoted semantic wording. Enumerate intended copy, invent extra copy sparingly, and never hide content behind \"other text\", \"remaining labels\", or \"etc.\" " "Describe concrete composition, typography, materials, texture, lighting, pose, and camera treatment without literary filler. Use `hierarchy_and_relation` only for ownership, alignment, containment, stacking, and occlusion. " "Infer structured layouts first. Use one complete layer per card and state its row and column. A compact secondary table may be one layer only if every header and cell is listed; otherwise use a visible shared frame when present, one complete header, and one complete layer per body row, binding values to columns and stating blanks. Enumerate sequences, schedules, spans, gaps, and vacant tracks in visual order. Do not mistake ordinary alignment for a table. " "Silently verify schema, string coordinates, Z-order, exact-text counts, geometry, bbox validity, and completeness.")
def create_node(assembler, class_type, title): """Create a workflow node dictionary with fallback template generation.""" try: node = assembler._get_node_template(class_type) except Exception: node = { "inputs": {}, "class_type": class_type, "_meta": {"title": title} } if "_meta" not in node: node["_meta"] = {} node['_meta']['title'] = title return node
def inject(assembler, chain_definition, chain_items): """Inject Ming-Image prompt enhancer nodes into the target generation workflow.""" if not chain_items: return
is_enabled = False thinking_enabled = False max_length = 4096 system_prompt = DEFAULT_MING_IMAGE_SYSTEM_PROMPT for item in chain_items: if isinstance(item, dict): if item.get("enable", False) or item.get("enabled", False) or item.get("value", False): is_enabled = True if item.get("thinking", False) in (True, "true", "on", "yes", "1", 1): thinking_enabled = True if "max_length" in item and item["max_length"]: try: max_length = int(item["max_length"]) except (ValueError, TypeError): pass if "system_prompt" in item and item["system_prompt"]: system_prompt = str(item["system_prompt"]) elif item is True or str(item).lower() in ("on", "true", "yes", "1"): is_enabled = True break
if not is_enabled: return
target_node_name = chain_definition.get('target_node', 'prompt') target_node_id = assembler.node_map.get(target_node_name)
if not target_node_id or target_node_id not in assembler.workflow: for node_id, node in assembler.workflow.items(): if isinstance(node, dict) and node.get('class_type') == 'TextEncodeMingImageEdit': target_node_id = node_id break
if not target_node_id or target_node_id not in assembler.workflow: print(f"Warning: Target node '{target_node_name}' (TextEncodeMingImageEdit) not found for Ming-Image Prompt Enhancer. Skipping.") return
target_node = assembler.workflow[target_node_id] original_prompt = target_node.get('inputs', {}).get('prompt', '')
# 1. Check if any LoadImage nodes exist in the workflow load_image_nodes = [ node_id for node_id, node in assembler.workflow.items() if isinstance(node, dict) and node.get('class_type') == 'LoadImage' ] has_load_image = len(load_image_nodes) > 0
target_image_conn = None clip_model_name = "qwen3.8_27b_w4a8.safetensors"
if has_load_image: # Collect image connections # Prioritize extracting all images.image_* slots from target_node['inputs'] (injected by reference image injectors) indexed_slots = [] target_inputs = target_node.get('inputs', {}) for slot_key, slot_val in target_inputs.items(): if slot_key.startswith('images.image_') and isinstance(slot_val, (list, tuple)): try: idx = int(slot_key.split('_')[-1]) except Exception: idx = 999 indexed_slots.append((idx, slot_val))
indexed_slots.sort(key=lambda x: x[0]) ref_image_conns = [s[1] for s in indexed_slots]
# If no reference image slots exist (e.g. pure img2img / inpaint / outpaint), retrieve from LoadImage nodes if not ref_image_conns: for lid in load_image_nodes: scaled_conn = None for nid, node in assembler.workflow.items(): if isinstance(node, dict) and node.get('class_type') == 'ImageScaleToTotalPixels': img_input = node.get('inputs', {}).get('image') if isinstance(img_input, (list, tuple)) and str(img_input[0]) == str(lid): scaled_conn = [nid, 0] break if scaled_conn: ref_image_conns.append(scaled_conn) else: scale_id = assembler._get_unique_id() scale_node = create_node(assembler, "ImageScaleToTotalPixels", "Scale Input Image") scale_node['inputs'] = { "upscale_method": "nearest-exact", "megapixels": 1, "resolution_steps": 1, "image": [lid, 0] } assembler.workflow[scale_id] = scale_node ref_image_conns.append([scale_id, 0])
# Organize multiple reference images into grid stitching if len(ref_image_conns) == 1: target_image_conn = ref_image_conns[0] elif len(ref_image_conns) >= 2: num_cols = 2 if len(ref_image_conns) <= 4 else 3
rows = [] for i in range(0, len(ref_image_conns), num_cols): rows.append(ref_image_conns[i:i + num_cols])
# Horizontally stitch images in each row stitched_rows = [] for r_idx, row_imgs in enumerate(rows): if len(row_imgs) == 1: stitched_rows.append(row_imgs[0]) else: curr_stitch = row_imgs[0] for c_idx in range(1, len(row_imgs)): st_id = assembler._get_unique_id() st_node = create_node(assembler, "ImageStitch", f"Stitch Images (Row {r_idx+1}-{c_idx})") st_node['inputs'] = { "direction": "right", "match_image_size": True, "spacing_width": 0, "spacing_color": "white", "image1": curr_stitch, "image2": row_imgs[c_idx] } assembler.workflow[st_id] = st_node curr_stitch = [st_id, 0] stitched_rows.append(curr_stitch)
# Vertically stitch multiple rows if len(stitched_rows) == 1: final_stitched = stitched_rows[0] else: curr_vertical = stitched_rows[0] for r_idx in range(1, len(stitched_rows)): st_id = assembler._get_unique_id() st_node = create_node(assembler, "ImageStitch", f"Stitch Images (Vertical {r_idx})") st_node['inputs'] = { "direction": "down", "match_image_size": True, "spacing_width": 0, "spacing_color": "white", "image1": curr_vertical, "image2": stitched_rows[r_idx] } assembler.workflow[st_id] = st_node curr_vertical = [st_id, 0] final_stitched = curr_vertical
# Scale final stitched image to ~1024 level via ImageScaleToTotalPixels final_scale_id = assembler._get_unique_id() final_scale_node = create_node(assembler, "ImageScaleToTotalPixels", "Scale Stitched Image") final_scale_node['inputs'] = { "upscale_method": "nearest-exact", "megapixels": 1, "resolution_steps": 1, "image": final_stitched } assembler.workflow[final_scale_id] = final_scale_node target_image_conn = [final_scale_id, 0]
# 2. Ensure model is downloaded in CPU stage before workflow execution if ensure_file_downloaded: try: ensure_file_downloaded(clip_model_name) except Exception as e: print(f"Warning: Failed to ensure '{clip_model_name}' downloaded: {e}")
# 3. Create CLIPLoader node (using qwen_image type for Qwen3.8-27B PE) clip_node_id = assembler._get_unique_id() clip_node = create_node(assembler, "CLIPLoader", "Load CLIP") clip_node['inputs'] = { "clip_name": clip_model_name, "type": "qwen_image", "device": "default" } assembler.workflow[clip_node_id] = clip_node
# 4. Create PrimitiveString node for System Prompt (Text node) system_prompt_node_id = assembler._get_unique_id() system_prompt_node = create_node(assembler, "PrimitiveString", "Text") system_prompt_node['inputs'] = { "value": system_prompt } assembler.workflow[system_prompt_node_id] = system_prompt_node
# 5. Create TextGenerate node text_gen_node_id = assembler._get_unique_id() text_gen_node = create_node(assembler, "TextGenerate", "Generate Text") text_gen_inputs = { "prompt": original_prompt, "max_length": max_length, "sampling_mode": "on", "sampling_mode.temperature": 0.7, "sampling_mode.top_k": 64, "sampling_mode.top_p": 0.95, "sampling_mode.min_p": 0.05, "sampling_mode.repetition_penalty": 1.05, "sampling_mode.seed": 0, "sampling_mode.presence_penalty": 0, "thinking": thinking_enabled, "use_default_template": True, "mtp": "auto", "clip": [clip_node_id, 0], "system_prompt": [system_prompt_node_id, 0] } if target_image_conn is not None: text_gen_inputs["image"] = target_image_conn
text_gen_node['inputs'] = text_gen_inputs assembler.workflow[text_gen_node_id] = text_gen_node
# 6. Connect TextGenerate output directly to target node prompt # ComfyUI TextGenerate node natively strips reasoning tags (<think>...</think>) into output slot 1, # leaving clean enhanced prompt in output slot 0. target_node['inputs']['prompt'] = [text_gen_node_id, 0] print(f"[Injector] Ming-Image Prompt Enhancer applied successfully ({'I2I' if has_load_image else 'T2I'}, clip='{clip_model_name}', thinking={thinking_enabled}).")41 unmodified lines424344454546474841 unmodified lines
is_enabled = False thinking_enabled = False max_length = 512 max_length = 4096 for item in chain_items: if isinstance(item, dict): if item.get("enable", False) or item.get("enabled", False) or item.get("value", False):462 unmodified lines46346446546646646746846947047147247347447547647747847948048148248348415 unmodified lines500501502503504505462 unmodified lines active_qwen_image_2_1_prompt_enhancer.append({
"enable": True,
"thinking": bool(ui_inputs.get('qwen_image_2_1_prompt_enhancer_thinking', False)),
"max_length": int(ui_inputs.get('qwen_image_2_1_prompt_enhancer_max_length', 512))
"max_length": int(ui_inputs.get('qwen_image_2_1_prompt_enhancer_max_length', 4096))
})
ming_pe_enable = ui_inputs.get('ming_image_prompt_enhancer_enable', False)
active_ming_image_prompt_enhancer = []
if 'ming_image_prompt_enhancer' in enabled_chains and ming_pe_enable:
item = {
"enable": True,
"thinking": bool(ui_inputs.get('ming_image_prompt_enhancer_thinking', False)),
"max_length": int(ui_inputs.get('ming_image_prompt_enhancer_max_length', 4096))
}
sys_p = ui_inputs.get('ming_image_prompt_enhancer_system_prompt')
if sys_p:
item["system_prompt"] = str(sys_p)
active_ming_image_prompt_enhancer.append(item)
return {
"active_loras_for_gpu": active_loras_for_gpu,
"active_loras_for_meta": active_loras_for_meta,15 unmodified lines "active_reference_images": active_reference_images,
"active_conditioning": active_conditioning,
"active_qwen_image_2_1_prompt_enhancer": active_qwen_image_2_1_prompt_enhancer,
"active_ming_image_prompt_enhancer": active_ming_image_prompt_enhancer,
"temp_files_to_clean": temp_files_to_clean
}122 unmodified lines12312412512612712812955 unmodified lines185186187188189190191122 unmodified lines active_reference_images = processed.get("active_reference_images", [])
active_conditioning = processed["active_conditioning"]
active_qwen_image_2_1_prompt_enhancer = processed.get("active_qwen_image_2_1_prompt_enhancer", [])
active_ming_image_prompt_enhancer = processed.get("active_ming_image_prompt_enhancer", [])
loras_string = f"LoRAs: [{', '.join(active_loras_for_meta)}]" if active_loras_for_meta else ""
55 unmodified lines "qwen_image_edit_chain": active_qwen_image_edit,
"reference_image_chain": active_reference_images,
"qwen_image_2_1_prompt_enhancer_chain": active_qwen_image_2_1_prompt_enhancer,
"ming_image_prompt_enhancer_chain": active_ming_image_prompt_enhancer,
"vae_chain": [ui_inputs.get('vae_name')] if (ui_inputs.get('vae_name') and 'vae' in enabled_chains) else [],
"hidream_o1_smoothing_chain": hidream_o1_smoothing_data,
"pid_chain": [ui_inputs.get('pid_settings', 'OFF')] if is_pid_enabled else [],112 unmodified lines113114115116117118119120121122112 unmodified lines else:
kwargs[param_name] = actual_value
# Safety guard for nodes expecting dynamic autogrow dictionary (e.g. TextEncodeMingImageEdit)
if class_type == 'TextEncodeMingImageEdit' and ('images' not in kwargs or kwargs.get('images') is None):
kwargs['images'] = {}
function_name = getattr(node_class, 'FUNCTION')
execution_method = getattr(node_instance, function_name)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108nodes: prompt: class_type: TextEncodeMingImageEdit title: "Text Encode Ming Image Edit" params: images: {} unet_loader: class_type: UNETLoader title: "Load Diffusion Model" params: weight_dtype: "default" vae_loader: class_type: VAELoader title: "Load VAE" clip_loader: class_type: CLIPLoader title: "Load CLIP" params: type: "qwen_image" device: "default" guider: class_type: BasicGuider title: "Basic Guider" ksampler_select: class_type: KSamplerSelect title: "KSamplerSelect" scheduler_node: class_type: BasicScheduler title: "BasicScheduler" params: scheduler: "simple" steps: 12 denoise: 1.0 random_noise: class_type: RandomNoise title: "RandomNoise" ksampler: class_type: SamplerCustomAdvanced title: "SamplerCustomAdvanced"
connections: - from: "unet_loader:0" to: "guider:model" - from: "unet_loader:0" to: "scheduler_node:model" - from: "clip_loader:0" to: "prompt:clip" - from: "prompt:0" to: "guider:conditioning" - from: "random_noise:0" to: "ksampler:noise" - from: "guider:0" to: "ksampler:guider" - from: "ksampler_select:0" to: "ksampler:sampler" - from: "scheduler_node:0" to: "ksampler:sigmas" - from: "vae_loader:0" to: "vae_decode:vae" - from: "vae_loader:0" to: "vae_encode:vae"
dynamic_lora_chains: lora_chain: template: "LoraLoader" output_map: "unet_loader:0": "model" "clip_loader:0": "clip" input_map: "model": "model" "clip": "clip" end_input_map: "model": ["guider:model", "scheduler_node:model"] "clip": ["prompt:clip"]
dynamic_conditioning_chains: conditioning_chain: guider_node: "guider" guider_target_inputs: ["conditioning"] clip_source: "clip_loader:0"
dynamic_pid_chains: pid_chain: ksampler_node: "ksampler"
dynamic_reference_image_chains: reference_image_chain: text_encode_node: "prompt" vae_node: "vae_loader" max_images: 8
dynamic_ming_image_prompt_enhancer_chains: ming_image_prompt_enhancer_chain: target_node: "prompt"
ui_map: positive_prompt: "prompt:prompt" negative_prompt: "dummy:negative_prompt" unet_name: "unet_loader:unet_name" clip_name: "clip_loader:clip_name" vae_name: "vae_loader:vae_name" seed: "random_noise:noise_seed" steps: "scheduler_node:steps" cfg: "dummy:cfg" sampler_name: "ksampler_select:sampler_name" scheduler: "scheduler_node:scheduler" denoise: "scheduler_node:denoise"678 unmodified lines679680681682682683684685686687688689690691692693694695696697104 unmodified lines802803804793805806807808809810811812813814815816817818819820821822823824825826827828678 unmodified lines if isinstance(is_thinking, str):
is_thinking = is_thinking.upper() in ("ON", "TRUE", "1")
ui_inputs["qwen_image_2_1_prompt_enhancer_thinking"] = bool(is_thinking)
ui_inputs["qwen_image_2_1_prompt_enhancer_max_length"] = int(item.get("max_length", 512))
ui_inputs["qwen_image_2_1_prompt_enhancer_max_length"] = int(item.get("max_length", 4096))
elif itype == "ming_image_prompt_enhancer":
is_enabled = item.get("enable", item.get("enabled", True))
if isinstance(is_enabled, str):
is_enabled = is_enabled.upper() in ("ON", "TRUE", "1")
ui_inputs["ming_image_prompt_enhancer_enable"] = bool(is_enabled)
is_thinking = item.get("thinking", False)
if isinstance(is_thinking, str):
is_thinking = is_thinking.upper() in ("ON", "TRUE", "1")
ui_inputs["ming_image_prompt_enhancer_thinking"] = bool(is_thinking)
ui_inputs["ming_image_prompt_enhancer_max_length"] = int(item.get("max_length", 4096))
if "system_prompt" in item:
ui_inputs["ming_image_prompt_enhancer_system_prompt"] = str(item["system_prompt"])
elif itype == "krea2_identity_edit":
img = _parse_image_param(item.get("image"))
if img:104 unmodified lines elif isinstance(pe_val, dict):
ui_inputs["qwen_image_2_1_prompt_enhancer_enable"] = bool(pe_val.get("enable", pe_val.get("enabled", True)))
ui_inputs["qwen_image_2_1_prompt_enhancer_thinking"] = bool(pe_val.get("thinking", False))
ui_inputs["qwen_image_2_1_prompt_enhancer_max_length"] = int(pe_val.get("max_length", 512))
ui_inputs["qwen_image_2_1_prompt_enhancer_max_length"] = int(pe_val.get("max_length", 4096))
elif str(pe_val).upper() in ("ON", "TRUE", "1"):
ui_inputs["qwen_image_2_1_prompt_enhancer_enable"] = True
else:
ui_inputs["qwen_image_2_1_prompt_enhancer_enable"] = False
ming_pe_val = params.get("ming_image_prompt_enhancer") or params.get("ming_image_prompt_enhancer_enable")
if ming_pe_val is not None:
if isinstance(ming_pe_val, bool):
ui_inputs["ming_image_prompt_enhancer_enable"] = ming_pe_val
elif isinstance(ming_pe_val, dict):
ui_inputs["ming_image_prompt_enhancer_enable"] = bool(ming_pe_val.get("enable", ming_pe_val.get("enabled", True)))
ui_inputs["ming_image_prompt_enhancer_thinking"] = bool(ming_pe_val.get("thinking", False))
ui_inputs["ming_image_prompt_enhancer_max_length"] = int(ming_pe_val.get("max_length", 4096))
if "system_prompt" in ming_pe_val:
ui_inputs["ming_image_prompt_enhancer_system_prompt"] = str(ming_pe_val["system_prompt"])
elif str(ming_pe_val).upper() in ("ON", "TRUE", "1"):
ui_inputs["ming_image_prompt_enhancer_enable"] = True
else:
ui_inputs["ming_image_prompt_enhancer_enable"] = False
_TASKS_DB[task_id]["progress"] = 50
# Execute Pipeline122345comfyui-frontend-package==1.53.6comfyui-workflow-templates==0.11.68comfyui-workflow-templates==0.11.69comfyui-embedded-docs==0.5.12torchtorchsde17 unmodified lines181920212122232466 unmodified lines9192939495969761 unmodified lines15916016116116216316416574 unmodified lines24024124224324424524617 unmodified lines load_ipadapter_config
)
def make_update_fn(m_comp, cat_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, 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, krea2_reference_edit_acc=None, qwen_image_edit_acc=None, ref_img_acc=None, sensenova_ref_acc=None, task_type=None, type_comp=None, qwen_pe_acc=None):
def make_update_fn(m_comp, cat_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, 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, krea2_reference_edit_acc=None, qwen_image_edit_acc=None, ref_img_acc=None, sensenova_ref_acc=None, task_type=None, type_comp=None, qwen_pe_acc=None, ming_pe_acc=None):
def update_fn(*args):
arch = args[0]
category = args[1]66 unmodified lines 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))
if qwen_pe_acc: updates[qwen_pe_acc] = gr.update(visible=('qwen_image_2_1_prompt_enhancer' in enabled_chains))
if ming_pe_acc: updates[ming_pe_acc] = gr.update(visible=('ming_image_prompt_enhancer' in enabled_chains))
if ar_comp:
res_key = arch_model_type61 unmodified lines return update_fn
def make_model_change_fn(cat_comp_ref, 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, 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, krea2_reference_edit_acc=None, qwen_image_edit_acc=None, ref_img_acc=None, sensenova_ref_acc=None, task_type=None, type_comp=None, qwen_pe_acc=None):
def make_model_change_fn(cat_comp_ref, 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, 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, krea2_reference_edit_acc=None, qwen_image_edit_acc=None, ref_img_acc=None, sensenova_ref_acc=None, task_type=None, type_comp=None, qwen_pe_acc=None, ming_pe_acc=None):
def change_fn(*args):
model_name = args[0]
idx = 174 unmodified lines 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))
if qwen_pe_acc: updates[qwen_pe_acc] = gr.update(visible=('qwen_image_2_1_prompt_enhancer' in enabled_chains))
if ming_pe_acc: updates[ming_pe_acc] = gr.update(visible=('ming_image_prompt_enhancer' in enabled_chains))
if ar_comp:
res_key = arch_model_type80 unmodified lines8182838485868736 unmodified lines1241251261271281291307 unmodified lines13813914013914114214314434 unmodified lines17918018118218318418512 unmodified lines19819920019820120220320488 unmodified lines29329429529629729829933 unmodified lines33333433533633733833980 unmodified lines pid_accordion = ui_components.get(f'pid_accordion_{prefix}')
vae_accordion = ui_components.get(f'vae_accordion_{prefix}')
qwen_pe_accordion = ui_components.get(f'qwen_image_2_1_prompt_enhancer_accordion_{prefix}')
ming_pe_accordion = ui_components.get(f'ming_image_prompt_enhancer_accordion_{prefix}')
ipa_preset_list = ui_components.get(f'ipadapter_final_preset_{prefix}')
36 unmodified lines if pid_accordion: outputs.append(pid_accordion)
if vae_accordion: outputs.append(vae_accordion)
if qwen_pe_accordion: outputs.append(qwen_pe_accordion)
if ming_pe_accordion: outputs.append(ming_pe_accordion)
if ipa_preset_list: outputs.append(ipa_preset_list)
outputs.extend(valid_extra_comps)7 unmodified lines 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, 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, krea2_reference_edit_acc=krea2_reference_edit_accordion, qwen_image_edit_acc=qwen_image_edit_accordion, ref_img_acc=ref_img_accordion, sensenova_ref_acc=sensenova_ref_accordion,
task_type=task_type, type_comp=type_comp, qwen_pe_acc=qwen_pe_accordion
task_type=task_type, type_comp=type_comp, qwen_pe_acc=qwen_pe_accordion, ming_pe_acc=ming_pe_accordion
)
inputs = [arch_comp, cat_comp]
if aspect_ratio_comp:34 unmodified lines if pid_accordion: outputs2.append(pid_accordion)
if vae_accordion: outputs2.append(vae_accordion)
if qwen_pe_accordion: outputs2.append(qwen_pe_accordion)
if ming_pe_accordion: outputs2.append(ming_pe_accordion)
if ipa_preset_list: outputs2.append(ipa_preset_list)
outputs2.extend(valid_extra_comps)12 unmodified lines 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, 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, krea2_reference_edit_acc=krea2_reference_edit_accordion, qwen_image_edit_acc=qwen_image_edit_accordion, ref_img_acc=ref_img_accordion, sensenova_ref_acc=sensenova_ref_accordion,
task_type=task_type, type_comp=type_comp, qwen_pe_acc=qwen_pe_accordion
task_type=task_type, type_comp=type_comp, qwen_pe_acc=qwen_pe_accordion, ming_pe_acc=ming_pe_accordion
)
if type_comp:
inputs2.append(type_comp)88 unmodified lines f'qwen_image_edit_accordion_{prefix}': 'qwen_image_edit',
f'reference_image_accordion_{prefix}': 'reference_image',
f'qwen_image_2_1_prompt_enhancer_accordion_{prefix}': 'qwen_image_2_1_prompt_enhancer',
f'ming_image_prompt_enhancer_accordion_{prefix}': 'ming_image_prompt_enhancer',
f'pid_accordion_{prefix}': 'pid',
f'vae_accordion_{prefix}': 'vae',
}33 unmodified lines 'qwen_image_edit_accordion_imagegen',
'reference_image_accordion_imagegen',
'qwen_image_2_1_prompt_enhancer_accordion_imagegen',
'ming_image_prompt_enhancer_accordion_imagegen',
'pid_accordion_imagegen', 'vae_accordion_imagegen',
]
for key in accordion_keys:43 unmodified lines44454647484950515253545556575843 unmodified lines if ui_components.get(f'qwen_image_2_1_prompt_enhancer_max_length_{prefix}'):
run_inputs_map['qwen_image_2_1_prompt_enhancer_max_length'] = ui_components[f'qwen_image_2_1_prompt_enhancer_max_length_{prefix}']
if ui_components.get(f'ming_image_prompt_enhancer_enable_{prefix}'):
run_inputs_map['ming_image_prompt_enhancer_enable'] = ui_components[f'ming_image_prompt_enhancer_enable_{prefix}']
if ui_components.get(f'ming_image_prompt_enhancer_thinking_{prefix}'):
run_inputs_map['ming_image_prompt_enhancer_thinking'] = ui_components[f'ming_image_prompt_enhancer_thinking_{prefix}']
if ui_components.get(f'ming_image_prompt_enhancer_max_length_{prefix}'):
run_inputs_map['ming_image_prompt_enhancer_max_length'] = ui_components[f'ming_image_prompt_enhancer_max_length_{prefix}']
if ui_components.get(f'ming_image_prompt_enhancer_system_prompt_{prefix}'):
run_inputs_map['ming_image_prompt_enhancer_system_prompt'] = ui_components[f'ming_image_prompt_enhancer_system_prompt_{prefix}']
# Generic / Txt2Img inputs
if ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width'):
run_inputs_map['width'] = ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width')8 unmodified lines910111212131415175 unmodified lines1911921931941951961978 unmodified lines 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_sensenova_reference_ui, create_joyai_reference_ui, create_reference_image_ui, create_krea2_identity_edit_ui, create_krea2_reference_edit_ui, create_qwen_image_edit_ui, create_pid_ui, create_qwen_image_2_1_prompt_enhancer_ui create_pid_ui, create_qwen_image_2_1_prompt_enhancer_ui, create_ming_image_prompt_enhancer_ui)
default_vals = MODEL_DEFAULTS_CONFIG.get('Default', {})175 unmodified lines components.update(create_qwen_image_edit_ui(prefix)) components.update(create_reference_image_ui(prefix)) components.update(create_qwen_image_2_1_prompt_enhancer_ui(prefix)) components.update(create_ming_image_prompt_enhancer_ui(prefix)) components.update(create_vae_override_ui(prefix)) components.update(create_pid_ui(prefix)) components[f'accordion_wrapper_{prefix}'] = accordion_wrapper899 unmodified lines9009019029039039049059069079089099109109119129131 unmodified line915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970899 unmodified lines scale=2
)
components[key('qwen_image_2_1_prompt_enhancer_thinking')] = gr.Checkbox(
label="Enable Thinking (Reasoning CoT)",
label="Enable Thinking (Requires longer ZeroGPU Duration)",
value=False,
interactive=True,
scale=2
)
components[key('qwen_image_2_1_prompt_enhancer_max_length')] = gr.Number(
label="Max Length",
value=512,
value=4096,
precision=0,
minimum=16,
step=16,1 unmodified line scale=1
)
return components
DEFAULT_MING_IMAGE_SYSTEM_PROMPT = (
"You are a senior visual designer and image-prompt engineer. Expand the user's request into one precise, high-resolution Figma-style caption. Return only one JSON object. "
"Use exactly two top-level keys. `canvas_settings` contains exactly `aspect_ratio`, `ambient_lighting`, and `image_style`. `layers` lists visible groups from background to topmost overlay. Every layer contains exactly `description`, `coordinates`, `hierarchy_and_relation`, and `color_specs`; `color_specs` is an array of hex colors. "
'`coordinates` MUST be one string, never an object or array, in exactly this form: `"cx: 0.500, cy: 0.500, w: 1.000, h: 1.000"`. Values are normalized; each bbox encloses its complete owned object and stays inside the canvas. '
"A layer is one selectable visible semantic group: background, full person, coherent object, panel, card, row, or text block. Prefer the fewest groups that preserve the layout. Keep people and objects intact. Never create invisible parents, guides, placeholders, empty layers, duplicate summaries, or multiple owners for one element. "
"Preserve every user-supplied rendered string character-for-character and as one contiguous string. Unless multiple visible copies are requested, it must occur exactly once across all `description` fields and zero times in `hierarchy_and_relation`. Quote it only where describing its visible rendering; refer to the related subject elsewhere with unquoted semantic wording. Enumerate intended copy, invent extra copy sparingly, and never hide content behind \"other text\", \"remaining labels\", or \"etc.\" "
"Describe concrete composition, typography, materials, texture, lighting, pose, and camera treatment without literary filler. Use `hierarchy_and_relation` only for ownership, alignment, containment, stacking, and occlusion. "
"Infer structured layouts first. Use one complete layer per card and state its row and column. A compact secondary table may be one layer only if every header and cell is listed; otherwise use a visible shared frame when present, one complete header, and one complete layer per body row, binding values to columns and stating blanks. Enumerate sequences, schedules, spans, gaps, and vacant tracks in visual order. Do not mistake ordinary alignment for a table. "
"Silently verify schema, string coordinates, Z-order, exact-text counts, geometry, bbox validity, and completeness."
)
def create_ming_image_prompt_enhancer_ui(prefix: str):
components = {}
key = lambda name: f"{name}_{prefix}"
with gr.Accordion("Ming-Image Prompt Enhancer Settings", open=False, visible=('ming_image_prompt_enhancer' in default_enabled_chains)) as enhancer_accordion:
components[key('ming_image_prompt_enhancer_accordion')] = enhancer_accordion
gr.Markdown("💡 **Tip:** Leverages [Qwen3.8-27B](https://huggingface.co/Qwen/Qwen3.8-27B) guided by the official [System Prompt](https://github.com/inclusionAI/Ming-Image#text-to-image-prompt-rewriting) to automatically enhance prompts into structured layouts based on input context.")
with gr.Row():
components[key('ming_image_prompt_enhancer_enable')] = gr.Checkbox(
label="Enable Ming-Image Prompt Enhancer",
value=False,
interactive=True,
scale=2
)
components[key('ming_image_prompt_enhancer_thinking')] = gr.Checkbox(
label="Enable Thinking (Requires longer ZeroGPU Duration)",
value=False,
interactive=True,
scale=2
)
components[key('ming_image_prompt_enhancer_max_length')] = gr.Number(
label="Max Length",
value=4096,
precision=0,
minimum=16,
step=16,
interactive=True,
scale=1
)
components[key('ming_image_prompt_enhancer_system_prompt')] = gr.Textbox(
label="System Prompt",
value=DEFAULT_MING_IMAGE_SYSTEM_PROMPT,
lines=4,
max_lines=12,
interactive=True
)
return components
544 unmodified lines545546547548549548549550551552553554555556557558559560561562563564565566567568569570571572573574544 unmodified lines description: "Enable thinking (reasoning CoT). Thought text inside <think> tags will be automatically stripped before passing prompt to downstream text encoding."
max_length:
type: integer
default: 512
description: "Maximum generation length for prompt enhancement." default: 4096
description: "Maximum generation length for prompt enhancement (default 4096)."
ming_image_prompt_enhancer:
chains: ming_image_prompt_enhancer
display_name: "Ming-Image Prompt Enhancer Settings"
description: "Enhance prompts using Ming-Image Prompt Enhancer (Qwen3.8-27B) guided by official Figma-style rewriter System Prompt, with optional reasoning CoT thinking mode."
max_count: 1
usage_guideline: "Set enable to true to activate Ming-Image prompt enhancement. Supports single/multi-reference images, thinking mode, and custom system prompt."
parameters_schema:
type: object
properties:
enable:
type: boolean
default: false
description: "Enable Ming-Image Prompt Enhancer."
thinking:
type: boolean
default: false
description: "Enable thinking (reasoning CoT)."
max_length:
type: integer
default: 4096
description: "Maximum generation length for prompt enhancement (default 4096)."
system_prompt:
type: string
description: "System prompt for Qwen3.8-27B prompt enhancer (defaults to official Ming-Image Figma-style rewriter prompt)."102 unmodified lines103104105106107108109110111112113114115116102 unmodified lines "3:4 (Classic Portrait)": [896, 1152]
"3:2 (Photography)": [1216, 832]
"2:3 (Photography Portrait)": [832, 1216]
ming-image:
"1:1 (Square)": [1024, 1024]
"16:9 (Landscape)": [1344, 768]
"9:16 (Portrait)": [768, 1344]
"4:3 (Classic)": [1152, 896]
"3:4 (Classic Portrait)": [896, 1152]
"3:2 (Photography)": [1216, 832]
"2:3 (Photography Portrait)": [832, 1216]
qwen-image-2.1:
"1:1 (Square)": [1024, 1024]
"16:9 (Landscape)": [1344, 768]641 unmodified lines642643644645646647648649650651652272 unmodified lines925926927928929930931932933934935936937938939940121 unmodified lines1062106310641050106510661067106810691070641 unmodified lines source: "hf"
repo_id: "Comfy-Org/Qwen-Image-2.1"
repository_file_path: "diffusion_models/qwen_image_2.1_int8_convrot.safetensors"
# Ming-Image
- filename: "ming_image_0.1_design_int8_convrot.safetensors"
source: "hf"
repo_id: "Comfy-Org/Ming-Image"
repository_file_path: "diffusion_models/ming_image_0.1_design_int8_convrot.safetensors"
# Qwen-Image
- filename: "qwen_image_2512_fp8_e4m3fn_scaled_comfyui_4steps_v1.0.safetensors"
source: "hf"272 unmodified lines source: "hf"
repo_id: "Comfy-Org/Qwen-Image-2.1"
repository_file_path: "text_encoders/qwen3.5_9b_qwen_image_2.1_pe_t2i.int8_convrot.safetensors"
# Ming-Image
- filename: "ming_image_0.1_ling_mini_2.0_w4a8.safetensors"
source: "hf"
repo_id: "Comfy-Org/Ming-Image"
repository_file_path: "text_encoders/ming_image_0.1_ling_mini_2.0_w4a8.safetensors"
# Qwen3.8-27B (Ming-Image Prompt Enhancer)
- filename: "qwen3.8_27b_w4a8.safetensors"
source: "hf"
repo_id: "Comfy-Org/Qwen3.8-27B"
repository_file_path: "text_encoders/qwen3.8_27b_w4a8.safetensors"
# PixelDiT
- filename: "gemma_2_2b_it_elm_fp8_scaled.safetensors"
source: "hf"121 unmodified lines - filename: "mage_flow_vae_bf16.safetensors"
source: "hf"
repo_id: "Comfy-Org/Mage-Flow"
repository_file_path: "vae/mage_flow_vae_bf16.safetensors" repository_file_path: "vae/mage_flow_vae_bf16.safetensors"
# Ming-Image
- filename: "ming_image_vae_bf16.safetensors"
source: "hf"
repo_id: "Comfy-Org/Ming-Image"
repository_file_path: "vae/ming_image_vae_bf16.safetensors"69 unmodified lines70717273747576777879808169 unmodified lines - vae - pid
ming-image: enabled_chains: - lora - reference_image - ming_image_prompt_enhancer
qwen-image-2.1: enabled_chains: - lora123456755 unmodified lines6364656667686970architecture_order:
- "Krea-2"
- "Qwen-Image-2.1"
- "Ming-Image"
- "SenseNova-U1.5"
- "Mage-Flow"
- "JoyAI-Image"55 unmodified lines "Z-Image":
model_type: "z-image"
controlnet_key: "Z-Image"
"Ming-Image":
model_type: "ming-image"
"Qwen-Image-2.1":
model_type: "qwen-image-2.1"
controlnet_key: "Qwen-Image"130 unmodified lines131132133134135136137138139140141142143130 unmodified lines steps: 9
cfg: 1.0
Ming-Image:
_defaults:
steps: 12
cfg: 1.0
sampler_name: "euler"
scheduler: "simple"
Qwen-Image-2.1:
_defaults:
steps: 2519 unmodified lines202122232425262728293031323319 unmodified lines unet: "qwen_image_2.1_int8_convrot.safetensors"
vae: "qwen_image_2.1_vae_bf16.safetensors"
clip: "qwen3vl_8b_nvfp4.safetensors"
Ming-Image:
latent_type: latent
models:
- display_name: "Ming-Image-0.1-Design"
components:
unet: "ming_image_0.1_design_int8_convrot.safetensors"
clip: "ming_image_0.1_ling_mini_2.0_w4a8.safetensors"
vae: "ming_image_vae_bf16.safetensors"
SenseNova-U1.5:
latent_type: hidream_o1_latent
models:25 unmodified lines2627282930313220 unmodified lines5354555657585919 unmodified lines7980818283848519 unmodified lines10510610710810911011119 unmodified lines13113213313413525 unmodified lines - qwen_image_edit - reference_image - qwen_image_2_1_prompt_enhancer - ming_image_prompt_enhancer - pid - vae
20 unmodified lines - qwen_image_edit - reference_image - qwen_image_2_1_prompt_enhancer - ming_image_prompt_enhancer - vae
inpaint:19 unmodified lines - qwen_image_edit - reference_image - qwen_image_2_1_prompt_enhancer - ming_image_prompt_enhancer - vae
outpaint:19 unmodified lines - qwen_image_edit - reference_image - qwen_image_2_1_prompt_enhancer - ming_image_prompt_enhancer - vae
hires_fix:19 unmodified lines - qwen_image_edit - reference_image - qwen_image_2_1_prompt_enhancer - ming_image_prompt_enhancer - vaeREADME.md+4
chain_injectors/ming_image_prompt_enhancer_injector.pyAdded+262
chain_injectors/qwen_image_2_1_prompt_enhancer_injector.py+1-1
core/pipelines/pipeline_input_processor.py+15-1
core/pipelines/sd_image_pipeline.py+2
core/pipelines/workflow_executor.py+4
core/pipelines/workflow_recipes/_partials/conditioning/ming-image.yamlAdded+108
mcp_tools/common.py+29-2
requirements.txt+1-1
ui/events/change_handlers.py+4-2
ui/events/main.py+7-2
ui/events/run_handlers.py+9
ui/imagegen_ui.py+2-1
ui/shared/ui_components.py+54-2
yaml/chain_features.yaml+27-2
yaml/constants.yaml+8
yaml/file_list.yaml+21-1
yaml/model_architecture_features.yaml+6
yaml/model_architectures.yaml+3
yaml/model_defaults.yaml+7
yaml/model_list.yaml+8
yaml/task_features.yaml+5