Add H3 prompt subject count guard
This commit is contained in:
+55
-2
@@ -36,6 +36,10 @@ _ANATOMY_GUARD_TEXT = (
|
||||
"and two legs with two feet. Limbs stay attached to the correct body and move "
|
||||
"only with the person they belong to."
|
||||
)
|
||||
_SUBJECT_COUNT_FALLBACK_TEXT = (
|
||||
"Only include the people explicitly described in the action. Do not invent "
|
||||
"extra people, doubles, duplicate bodies, background performers, or extra faces."
|
||||
)
|
||||
_ANCHOR_STYLE_PRESETS = OrderedDict(
|
||||
[
|
||||
(
|
||||
@@ -1131,13 +1135,46 @@ def _reference_context(ref, compact_picture_number):
|
||||
return " ".join(part for part in parts if part).strip()
|
||||
|
||||
|
||||
def _subject_count_guard_text(selected_refs):
|
||||
character_labels = []
|
||||
for picture_number, (_slot, ref) in enumerate(selected_refs or (), 1):
|
||||
if ref.get("kind") != "character":
|
||||
continue
|
||||
name = _reference_text(ref.get("name")) or _reference_text(ref.get("id"))
|
||||
label = f"<Picture {picture_number}>"
|
||||
if name:
|
||||
label = f"{label} {name}"
|
||||
character_labels.append(label)
|
||||
if not character_labels:
|
||||
return _SUBJECT_COUNT_FALLBACK_TEXT
|
||||
if len(character_labels) == 1:
|
||||
return (
|
||||
f"The shot contains exactly one named character: {character_labels[0]}. "
|
||||
"Do not create any extra people, doubles, duplicate bodies, background "
|
||||
"performers, or extra faces."
|
||||
)
|
||||
return (
|
||||
f"The shot contains exactly {len(character_labels)} named characters: "
|
||||
+ ", ".join(character_labels)
|
||||
+ ". Do not create any extra people, doubles, duplicate bodies, background "
|
||||
"performers, or extra faces."
|
||||
)
|
||||
|
||||
|
||||
def _append_prompt_section(parts, label, text):
|
||||
clean = _reference_text(text)
|
||||
if clean:
|
||||
parts.append(f"{label}: {clean}")
|
||||
|
||||
|
||||
def curate_h3_prompt(action_prompt, anchor="", soundscape="", refs=(), anatomy_guard="auto"):
|
||||
def curate_h3_prompt(
|
||||
action_prompt,
|
||||
anchor="",
|
||||
soundscape="",
|
||||
refs=(),
|
||||
anatomy_guard="auto",
|
||||
subject_count_guard="auto",
|
||||
):
|
||||
normalized_refs = _normalize_prompt_refs(refs)
|
||||
selected = _selected_prompt_refs(action_prompt, normalized_refs)
|
||||
picture_map = {slot_number: index for index, (slot_number, _ref) in enumerate(selected, 1)}
|
||||
@@ -1151,6 +1188,10 @@ def curate_h3_prompt(action_prompt, anchor="", soundscape="", refs=(), anatomy_g
|
||||
_append_prompt_section(prompt_parts, "Action", action)
|
||||
if anatomy_guard == "on" or (anatomy_guard == "auto" and any(ref.get("kind") == "character" for _slot, ref in selected)):
|
||||
_append_prompt_section(prompt_parts, "Anatomy guard", _ANATOMY_GUARD_TEXT)
|
||||
if subject_count_guard == "on" or (
|
||||
subject_count_guard == "auto" and any(ref.get("kind") == "character" for _slot, ref in selected)
|
||||
):
|
||||
_append_prompt_section(prompt_parts, "Subject count guard", _subject_count_guard_text(selected))
|
||||
_append_prompt_section(prompt_parts, "overall_soundscape", soundscape)
|
||||
|
||||
prompt = "\n\n".join(prompt_parts).strip()
|
||||
@@ -2526,12 +2567,22 @@ class DumasH3PromptCuratorNode:
|
||||
"anatomy_guard": (
|
||||
["auto", "on", "off"],
|
||||
{
|
||||
"default": "auto",
|
||||
"default": "on",
|
||||
"tooltip": (
|
||||
"Add the anatomy guard. Auto adds it when a character reference is used."
|
||||
),
|
||||
},
|
||||
),
|
||||
"subject_count_guard": (
|
||||
["auto", "on", "off"],
|
||||
{
|
||||
"default": "auto",
|
||||
"tooltip": (
|
||||
"Add a guard against extra people, duplicate bodies, or extra faces. "
|
||||
"Auto adds it when a character reference is used."
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
"optional": optional,
|
||||
}
|
||||
@@ -2540,6 +2591,7 @@ class DumasH3PromptCuratorNode:
|
||||
self,
|
||||
action_prompt,
|
||||
anatomy_guard,
|
||||
subject_count_guard,
|
||||
anchor="",
|
||||
soundscape="",
|
||||
ref_1=None,
|
||||
@@ -2558,6 +2610,7 @@ class DumasH3PromptCuratorNode:
|
||||
soundscape=soundscape,
|
||||
refs=(ref_1, ref_2, ref_3, ref_4, ref_5, ref_6, ref_7, ref_8, ref_9),
|
||||
anatomy_guard=anatomy_guard,
|
||||
subject_count_guard=subject_count_guard,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user