Updated generation pages.
This commit is contained in:
@@ -9,6 +9,11 @@ from services.prompts import _cross_dedup_prompts
|
||||
|
||||
logger = logging.getLogger('gaze')
|
||||
|
||||
# Node IDs used by DetailerForEach in multi-char mode
|
||||
_SEGS_DETAILER_NODES = ['46', '47', '53', '54']
|
||||
# Node IDs for per-character CLIP prompts in multi-char mode
|
||||
_SEGS_PROMPT_NODES = ['44', '45', '51', '52']
|
||||
|
||||
|
||||
def _log_workflow_prompts(label, workflow):
|
||||
"""Log the final assembled ComfyUI prompts in a consistent, readable block."""
|
||||
@@ -17,7 +22,7 @@ def _log_workflow_prompts(label, workflow):
|
||||
lora_details = []
|
||||
|
||||
# Collect detailed LoRA information
|
||||
for node_id, label_str in [("16", "char/look"), ("17", "outfit"), ("18", "action"), ("19", "style/detail/scene")]:
|
||||
for node_id, label_str in [("16", "char/look"), ("17", "outfit"), ("18", "action"), ("19", "style/detail/scene"), ("20", "char_b")]:
|
||||
if node_id in workflow:
|
||||
name = workflow[node_id]["inputs"].get("lora_name", "")
|
||||
if name:
|
||||
@@ -41,11 +46,18 @@ def _log_workflow_prompts(label, workflow):
|
||||
|
||||
# Extract adetailer information
|
||||
adetailer_info = []
|
||||
# Single-char mode: FaceDetailer nodes 11 + 13
|
||||
for node_id, node_name in [("11", "Face"), ("13", "Hand")]:
|
||||
if node_id in workflow:
|
||||
adetailer_info.append(f" {node_name} (Node {node_id}): steps={workflow[node_id]['inputs'].get('steps', '?')}, "
|
||||
f"cfg={workflow[node_id]['inputs'].get('cfg', '?')}, "
|
||||
f"denoise={workflow[node_id]['inputs'].get('denoise', '?')}")
|
||||
# Multi-char mode: SEGS DetailerForEach nodes
|
||||
for node_id, node_name in [("46", "Person A"), ("47", "Person B"), ("53", "Face A"), ("54", "Face B")]:
|
||||
if node_id in workflow:
|
||||
adetailer_info.append(f" {node_name} (Node {node_id}): steps={workflow[node_id]['inputs'].get('steps', '?')}, "
|
||||
f"cfg={workflow[node_id]['inputs'].get('cfg', '?')}, "
|
||||
f"denoise={workflow[node_id]['inputs'].get('denoise', '?')}")
|
||||
|
||||
face_text = workflow.get('14', {}).get('inputs', {}).get('text', '')
|
||||
hand_text = workflow.get('15', {}).get('inputs', {}).get('text', '')
|
||||
@@ -95,6 +107,12 @@ def _log_workflow_prompts(label, workflow):
|
||||
if hand_text:
|
||||
lines.append(f" [H] Hand : {hand_text}")
|
||||
|
||||
# Multi-char per-character prompts
|
||||
for node_id, lbl in [("44", "Person A"), ("45", "Person B"), ("51", "Face A"), ("52", "Face B")]:
|
||||
txt = workflow.get(node_id, {}).get('inputs', {}).get('text', '')
|
||||
if txt:
|
||||
lines.append(f" [{lbl}] : {txt}")
|
||||
|
||||
lines.append(sep)
|
||||
logger.info("\n%s", "\n".join(lines))
|
||||
|
||||
@@ -119,8 +137,8 @@ def _apply_checkpoint_settings(workflow, ckpt_data):
|
||||
if scheduler and '3' in workflow:
|
||||
workflow['3']['inputs']['scheduler'] = scheduler
|
||||
|
||||
# Face/hand detailers (nodes 11, 13)
|
||||
for node_id in ['11', '13']:
|
||||
# Face/hand detailers (nodes 11, 13) + multi-char SEGS detailers
|
||||
for node_id in ['11', '13'] + _SEGS_DETAILER_NODES:
|
||||
if node_id in workflow:
|
||||
if steps:
|
||||
workflow[node_id]['inputs']['steps'] = int(steps)
|
||||
@@ -131,9 +149,9 @@ def _apply_checkpoint_settings(workflow, ckpt_data):
|
||||
if scheduler:
|
||||
workflow[node_id]['inputs']['scheduler'] = scheduler
|
||||
|
||||
# Prepend base_positive to positive prompts (main + face/hand detailers)
|
||||
# Prepend base_positive to all positive prompt nodes
|
||||
if base_positive:
|
||||
for node_id in ['6', '14', '15']:
|
||||
for node_id in ['6', '14', '15'] + _SEGS_PROMPT_NODES:
|
||||
if node_id in workflow:
|
||||
workflow[node_id]['inputs']['text'] = f"{base_positive}, {workflow[node_id]['inputs']['text']}"
|
||||
|
||||
@@ -149,7 +167,7 @@ def _apply_checkpoint_settings(workflow, ckpt_data):
|
||||
}
|
||||
if '8' in workflow:
|
||||
workflow['8']['inputs']['vae'] = ['21', 0]
|
||||
for node_id in ['11', '13']:
|
||||
for node_id in ['11', '13'] + _SEGS_DETAILER_NODES:
|
||||
if node_id in workflow:
|
||||
workflow[node_id]['inputs']['vae'] = ['21', 0]
|
||||
|
||||
@@ -187,12 +205,246 @@ def _get_default_checkpoint():
|
||||
return ckpt.checkpoint_path, ckpt.data or {}
|
||||
|
||||
|
||||
def _prepare_workflow(workflow, character, prompts, checkpoint=None, custom_negative=None, outfit=None, action=None, style=None, detailer=None, scene=None, width=None, height=None, checkpoint_data=None, look=None, fixed_seed=None):
|
||||
def _inject_multi_char_detailers(workflow, prompts, model_source, clip_source):
|
||||
"""Replace single FaceDetailer (node 11) with per-character SEGS-based detailers.
|
||||
|
||||
Injects person detection + face detection pipelines that order detections
|
||||
left-to-right and apply character A's prompt to the left person/face and
|
||||
character B's prompt to the right person/face.
|
||||
|
||||
Nodes added:
|
||||
40 - Person detector (UltralyticsDetectorProvider)
|
||||
41 - Person SEGS detection (BboxDetectorSEGS)
|
||||
42 - Filter: left person (char A)
|
||||
43 - Filter: right person (char B)
|
||||
44 - CLIPTextEncode: char A body prompt
|
||||
45 - CLIPTextEncode: char B body prompt
|
||||
46 - DetailerForEach: person A
|
||||
47 - DetailerForEach: person B
|
||||
48 - Face SEGS detection (BboxDetectorSEGS, reuses face detector node 10)
|
||||
49 - Filter: left face (char A)
|
||||
50 - Filter: right face (char B)
|
||||
51 - CLIPTextEncode: char A face prompt
|
||||
52 - CLIPTextEncode: char B face prompt
|
||||
53 - DetailerForEach: face A
|
||||
54 - DetailerForEach: face B
|
||||
|
||||
Image flow: VAEDecode(8) → PersonA(46) → PersonB(47) → FaceA(53) → FaceB(54) → Hand(13)
|
||||
"""
|
||||
vae_source = ["4", 2]
|
||||
|
||||
# Remove old single face detailer and its prompt — we replace them
|
||||
workflow.pop('11', None)
|
||||
workflow.pop('14', None)
|
||||
|
||||
# --- Person detection ---
|
||||
workflow['40'] = {
|
||||
'inputs': {'model_name': 'segm/person_yolov8m-seg.pt'},
|
||||
'class_type': 'UltralyticsDetectorProvider'
|
||||
}
|
||||
|
||||
workflow['41'] = {
|
||||
'inputs': {
|
||||
'bbox_detector': ['40', 0],
|
||||
'image': ['8', 0],
|
||||
'threshold': 0.5,
|
||||
'dilation': 10,
|
||||
'crop_factor': 3.0,
|
||||
'drop_size': 10,
|
||||
'labels': 'all',
|
||||
},
|
||||
'class_type': 'BboxDetectorSEGS'
|
||||
}
|
||||
|
||||
# Order by x1 ascending (left to right), pick index 0 = leftmost person
|
||||
workflow['42'] = {
|
||||
'inputs': {
|
||||
'segs': ['41', 0],
|
||||
'target': 'x1',
|
||||
'order': False,
|
||||
'take_start': 0,
|
||||
'take_count': 1,
|
||||
},
|
||||
'class_type': 'ImpactSEGSOrderedFilter'
|
||||
}
|
||||
|
||||
# Pick index 1 = rightmost person
|
||||
workflow['43'] = {
|
||||
'inputs': {
|
||||
'segs': ['41', 0],
|
||||
'target': 'x1',
|
||||
'order': False,
|
||||
'take_start': 1,
|
||||
'take_count': 1,
|
||||
},
|
||||
'class_type': 'ImpactSEGSOrderedFilter'
|
||||
}
|
||||
|
||||
# --- Per-character body prompts ---
|
||||
workflow['44'] = {
|
||||
'inputs': {'text': prompts.get('char_a_main', ''), 'clip': clip_source},
|
||||
'class_type': 'CLIPTextEncode'
|
||||
}
|
||||
workflow['45'] = {
|
||||
'inputs': {'text': prompts.get('char_b_main', ''), 'clip': clip_source},
|
||||
'class_type': 'CLIPTextEncode'
|
||||
}
|
||||
|
||||
# --- Person detailing (DetailerForEach) ---
|
||||
_person_base = {
|
||||
'guide_size': 512,
|
||||
'guide_size_for': True,
|
||||
'max_size': 1024,
|
||||
'seed': 0, # overwritten by seed step
|
||||
'steps': 20, # overwritten by checkpoint settings
|
||||
'cfg': 3.5, # overwritten by checkpoint settings
|
||||
'sampler_name': 'euler_ancestral',
|
||||
'scheduler': 'normal',
|
||||
'denoise': 0.4,
|
||||
'feather': 5,
|
||||
'noise_mask': True,
|
||||
'force_inpaint': True,
|
||||
'wildcard': '',
|
||||
'cycle': 1,
|
||||
'inpaint_model': False,
|
||||
'noise_mask_feather': 20,
|
||||
}
|
||||
|
||||
workflow['46'] = {
|
||||
'inputs': {
|
||||
**_person_base,
|
||||
'image': ['8', 0],
|
||||
'segs': ['42', 0],
|
||||
'model': model_source,
|
||||
'clip': clip_source,
|
||||
'vae': vae_source,
|
||||
'positive': ['44', 0],
|
||||
'negative': ['7', 0],
|
||||
},
|
||||
'class_type': 'DetailerForEach'
|
||||
}
|
||||
|
||||
workflow['47'] = {
|
||||
'inputs': {
|
||||
**_person_base,
|
||||
'image': ['46', 0], # chains from person A output
|
||||
'segs': ['43', 0],
|
||||
'model': model_source,
|
||||
'clip': clip_source,
|
||||
'vae': vae_source,
|
||||
'positive': ['45', 0],
|
||||
'negative': ['7', 0],
|
||||
},
|
||||
'class_type': 'DetailerForEach'
|
||||
}
|
||||
|
||||
# --- Face detection (on person-detailed image) ---
|
||||
workflow['48'] = {
|
||||
'inputs': {
|
||||
'bbox_detector': ['10', 0], # reuse existing face YOLO detector
|
||||
'image': ['47', 0],
|
||||
'threshold': 0.5,
|
||||
'dilation': 10,
|
||||
'crop_factor': 3.0,
|
||||
'drop_size': 10,
|
||||
'labels': 'all',
|
||||
},
|
||||
'class_type': 'BboxDetectorSEGS'
|
||||
}
|
||||
|
||||
workflow['49'] = {
|
||||
'inputs': {
|
||||
'segs': ['48', 0],
|
||||
'target': 'x1',
|
||||
'order': False,
|
||||
'take_start': 0,
|
||||
'take_count': 1,
|
||||
},
|
||||
'class_type': 'ImpactSEGSOrderedFilter'
|
||||
}
|
||||
|
||||
workflow['50'] = {
|
||||
'inputs': {
|
||||
'segs': ['48', 0],
|
||||
'target': 'x1',
|
||||
'order': False,
|
||||
'take_start': 1,
|
||||
'take_count': 1,
|
||||
},
|
||||
'class_type': 'ImpactSEGSOrderedFilter'
|
||||
}
|
||||
|
||||
# --- Per-character face prompts ---
|
||||
workflow['51'] = {
|
||||
'inputs': {'text': prompts.get('char_a_face', ''), 'clip': clip_source},
|
||||
'class_type': 'CLIPTextEncode'
|
||||
}
|
||||
workflow['52'] = {
|
||||
'inputs': {'text': prompts.get('char_b_face', ''), 'clip': clip_source},
|
||||
'class_type': 'CLIPTextEncode'
|
||||
}
|
||||
|
||||
# --- Face detailing (DetailerForEach) ---
|
||||
_face_base = {
|
||||
'guide_size': 384,
|
||||
'guide_size_for': True,
|
||||
'max_size': 1024,
|
||||
'seed': 0,
|
||||
'steps': 20,
|
||||
'cfg': 3.5,
|
||||
'sampler_name': 'euler_ancestral',
|
||||
'scheduler': 'normal',
|
||||
'denoise': 0.5,
|
||||
'feather': 5,
|
||||
'noise_mask': True,
|
||||
'force_inpaint': True,
|
||||
'wildcard': '',
|
||||
'cycle': 1,
|
||||
'inpaint_model': False,
|
||||
'noise_mask_feather': 20,
|
||||
}
|
||||
|
||||
workflow['53'] = {
|
||||
'inputs': {
|
||||
**_face_base,
|
||||
'image': ['47', 0],
|
||||
'segs': ['49', 0],
|
||||
'model': model_source,
|
||||
'clip': clip_source,
|
||||
'vae': vae_source,
|
||||
'positive': ['51', 0],
|
||||
'negative': ['7', 0],
|
||||
},
|
||||
'class_type': 'DetailerForEach'
|
||||
}
|
||||
|
||||
workflow['54'] = {
|
||||
'inputs': {
|
||||
**_face_base,
|
||||
'image': ['53', 0], # chains from face A output
|
||||
'segs': ['50', 0],
|
||||
'model': model_source,
|
||||
'clip': clip_source,
|
||||
'vae': vae_source,
|
||||
'positive': ['52', 0],
|
||||
'negative': ['7', 0],
|
||||
},
|
||||
'class_type': 'DetailerForEach'
|
||||
}
|
||||
|
||||
# Rewire hand detailer: image input from last face detailer instead of old node 11
|
||||
if '13' in workflow:
|
||||
workflow['13']['inputs']['image'] = ['54', 0]
|
||||
|
||||
logger.debug("Injected multi-char SEGS detailers (nodes 40-54)")
|
||||
|
||||
|
||||
def _prepare_workflow(workflow, character, prompts, checkpoint=None, custom_negative=None, outfit=None, action=None, style=None, detailer=None, scene=None, width=None, height=None, checkpoint_data=None, look=None, fixed_seed=None, character_b=None):
|
||||
# 1. Update prompts using replacement to preserve embeddings
|
||||
workflow["6"]["inputs"]["text"] = workflow["6"]["inputs"]["text"].replace("{{POSITIVE_PROMPT}}", prompts["main"])
|
||||
|
||||
if custom_negative:
|
||||
workflow["7"]["inputs"]["text"] = f"{workflow['7']['inputs']['text']}, {custom_negative}"
|
||||
workflow["7"]["inputs"]["text"] = f"{custom_negative}, {workflow['7']['inputs']['text']}"
|
||||
|
||||
if "14" in workflow:
|
||||
workflow["14"]["inputs"]["text"] = workflow["14"]["inputs"]["text"].replace("{{FACE_PROMPT}}", prompts["face"])
|
||||
@@ -289,23 +541,39 @@ def _prepare_workflow(workflow, character, prompts, checkpoint=None, custom_nega
|
||||
clip_source = ["19", 1]
|
||||
logger.debug("Style/Detailer LoRA: %s @ %s", style_lora_name, _w19)
|
||||
|
||||
# Apply connections to all model/clip consumers
|
||||
workflow["3"]["inputs"]["model"] = model_source
|
||||
workflow["11"]["inputs"]["model"] = model_source
|
||||
workflow["13"]["inputs"]["model"] = model_source
|
||||
# Second character LoRA (Node 20) - for multi-character generation
|
||||
if character_b:
|
||||
char_b_lora_data = character_b.data.get('lora', {})
|
||||
char_b_lora_name = char_b_lora_data.get('lora_name')
|
||||
if char_b_lora_name and "20" in workflow:
|
||||
_w20 = _resolve_lora_weight(char_b_lora_data)
|
||||
workflow["20"]["inputs"]["lora_name"] = char_b_lora_name
|
||||
workflow["20"]["inputs"]["strength_model"] = _w20
|
||||
workflow["20"]["inputs"]["strength_clip"] = _w20
|
||||
workflow["20"]["inputs"]["model"] = model_source
|
||||
workflow["20"]["inputs"]["clip"] = clip_source
|
||||
model_source = ["20", 0]
|
||||
clip_source = ["20", 1]
|
||||
logger.debug("Character B LoRA: %s @ %s", char_b_lora_name, _w20)
|
||||
|
||||
workflow["6"]["inputs"]["clip"] = clip_source
|
||||
workflow["7"]["inputs"]["clip"] = clip_source
|
||||
workflow["11"]["inputs"]["clip"] = clip_source
|
||||
workflow["13"]["inputs"]["clip"] = clip_source
|
||||
workflow["14"]["inputs"]["clip"] = clip_source
|
||||
workflow["15"]["inputs"]["clip"] = clip_source
|
||||
# 3b. Multi-char: inject per-character SEGS detailers (replaces node 11/14)
|
||||
if character_b:
|
||||
_inject_multi_char_detailers(workflow, prompts, model_source, clip_source)
|
||||
|
||||
# Apply connections to all model/clip consumers (conditional on node existence)
|
||||
for nid in ["3", "11", "13"] + _SEGS_DETAILER_NODES:
|
||||
if nid in workflow:
|
||||
workflow[nid]["inputs"]["model"] = model_source
|
||||
|
||||
for nid in ["6", "7", "11", "13", "14", "15"] + _SEGS_PROMPT_NODES:
|
||||
if nid in workflow:
|
||||
workflow[nid]["inputs"]["clip"] = clip_source
|
||||
|
||||
# 4. Randomize seeds (or use a fixed seed for reproducible batches like Strengths Gallery)
|
||||
gen_seed = fixed_seed if fixed_seed is not None else random.randint(1, 10**15)
|
||||
workflow["3"]["inputs"]["seed"] = gen_seed
|
||||
if "11" in workflow: workflow["11"]["inputs"]["seed"] = gen_seed
|
||||
if "13" in workflow: workflow["13"]["inputs"]["seed"] = gen_seed
|
||||
for nid in ["3", "11", "13"] + _SEGS_DETAILER_NODES:
|
||||
if nid in workflow:
|
||||
workflow[nid]["inputs"]["seed"] = gen_seed
|
||||
|
||||
# 5. Set image dimensions
|
||||
if "5" in workflow:
|
||||
@@ -321,7 +589,7 @@ def _prepare_workflow(workflow, character, prompts, checkpoint=None, custom_nega
|
||||
# 7. Sync sampler/scheduler from main KSampler to adetailer nodes
|
||||
sampler_name = workflow["3"]["inputs"].get("sampler_name")
|
||||
scheduler = workflow["3"]["inputs"].get("scheduler")
|
||||
for node_id in ["11", "13"]:
|
||||
for node_id in ["11", "13"] + _SEGS_DETAILER_NODES:
|
||||
if node_id in workflow:
|
||||
if sampler_name:
|
||||
workflow[node_id]["inputs"]["sampler_name"] = sampler_name
|
||||
|
||||
Reference in New Issue
Block a user