Naturalize caption character expressions

This commit is contained in:
2026-06-27 21:30:23 +02:00
parent 4de00bcc9d
commit 4f97057fc4
3 changed files with 77 additions and 5 deletions
+11
View File
@@ -526,6 +526,16 @@ def _caption_cast_descriptor_issues(name: str, row: dict[str, Any] | None, capti
return []
def _caption_expression_grammar_issues(name: str, caption_text: str) -> list[str]:
if re.search(
r"\b(?:with|are|show|shows|is|include|includes)\s+(?:woman|man) [a-z]\s+has\b",
caption_text,
flags=re.IGNORECASE,
):
return [f"{name}.caption: character_expression_has_grammar"]
return []
def _trace_dict(formatter_name: str, payload: dict[str, Any]) -> tuple[dict[str, Any], str]:
trace_text = str(payload.get("route_trace_json") or "")
if not trace_text:
@@ -659,6 +669,7 @@ def _formatter_issues(
issues.append(f"{name}.{formatter_name}: not_metadata_route:{method}")
issues.extend(_formatter_trace_issues(name, formats, target=target, row=row))
issues.extend(_caption_cast_descriptor_issues(name, row, caption_text))
issues.extend(_caption_expression_grammar_issues(name, caption_text))
for label, value in (
(f"{name}.krea_negative", krea.get("negative_prompt")),
+21
View File
@@ -4262,6 +4262,27 @@ def smoke_caption_metadata_routes() -> None:
caption_naturalizer._configured_cast_from_row,
"metadata(configured_cast)",
)
configured_character_expression = _fixture_hardcore_row(
character_expression_text="Woman A has flushed focus; Man A has concentrated stare",
)
character_expression_route = caption_metadata_routes.configured_cast_from_row_result(
caption_naturalizer._caption_metadata_route_request(configured_character_expression, "balanced", False),
caption_naturalizer._caption_metadata_route_dependencies(),
)
_expect(character_expression_route is not None, "Caption configured-cast character expression row did not match")
assert character_expression_route is not None
_expect(
"with Woman A has" not in character_expression_route.prose,
"Caption configured-cast prose kept old character-expression grammar",
)
_expect(
"Woman A with flushed focus" in character_expression_route.prose,
"Caption configured-cast prose did not naturalize Woman A expression",
)
_expect(
"Man A with concentrated stare" in character_expression_route.prose,
"Caption configured-cast prose did not naturalize Man A expression",
)
configured_axis_only = _fixture_hardcore_row(
item="generic configured adult action",
role_graph="",