Extract Krea configured cast formatter route

This commit is contained in:
2026-06-27 11:16:08 +02:00
parent 176d4c9257
commit 5ec17df1a4
5 changed files with 249 additions and 59 deletions
+94 -58
View File
@@ -11,6 +11,7 @@ try:
is_outercourse_text as _is_outercourse_text,
normalize_hardcore_detail_density as _normalize_hardcore_detail_density,
)
from . import krea_configured_cast_formatter
from . import krea_pair_formatter
from .hardcore_text_cleanup import (
sanitize_hardcore_axis_values as _sanitize_hardcore_axis_values,
@@ -43,6 +44,7 @@ except ImportError: # Allows local smoke tests with `python -c`.
is_outercourse_text as _is_outercourse_text,
normalize_hardcore_detail_density as _normalize_hardcore_detail_density,
)
import krea_configured_cast_formatter
import krea_pair_formatter
from hardcore_text_cleanup import (
sanitize_hardcore_axis_values as _sanitize_hardcore_axis_values,
@@ -407,13 +409,69 @@ def _couple_clothing_phrase(item: str) -> str:
return f"The couple wears {item}"
def _normal_row_to_krea(row: dict[str, Any], detail_level: str, style_mode: str) -> tuple[str, str]:
subject_type = _clean(row.get("subject_type"))
def _krea_configured_cast_dependencies() -> krea_configured_cast_formatter.KreaConfiguredCastDependencies:
return krea_configured_cast_formatter.KreaConfiguredCastDependencies(
clean=_clean,
prompt_field=_prompt_field,
sanitize_hardcore_environment_anchors=_sanitize_hardcore_environment_anchors,
sanitize_hardcore_axis_values=_sanitize_hardcore_axis_values,
sanitize_scene_text_for_cast=_sanitize_scene_text_for_cast,
normalize_hardcore_detail_density=_normalize_hardcore_detail_density,
row_action_family=route_metadata_policy.row_action_family,
hardcore_action_sentence=_hardcore_action_sentence,
pov_action_phrase=_pov_action_phrase,
pov_labels_from_value=_pov_labels_from_value,
merge_labels=_merge_labels,
cast_prose_omit=lambda text, omit_labels: _cast_prose(text, omit_labels=omit_labels),
filter_pov_labeled_clauses=_filter_pov_labeled_clauses,
natural_label_text=_natural_label_text,
pov_composition_text=_pov_composition_text,
pov_camera_phrase=lambda labels: _pov_camera_phrase(labels),
expression_phrase=_expression_phrase,
composition_phrase=_composition_phrase,
paragraph=_paragraph,
)
def _krea_configured_cast_request(
row: dict[str, Any],
detail_level: str,
style_mode: str,
primary: str,
item: str,
scene: str,
expression: str,
composition: str,
source_composition: str,
camera: str,
camera_scene: str,
style: str,
) -> krea_configured_cast_formatter.KreaConfiguredCastRequest:
return krea_configured_cast_formatter.KreaConfiguredCastRequest(
row=row,
detail_level=detail_level,
style_mode=style_mode,
primary=primary,
item=item,
scene=scene,
expression=expression,
composition=composition,
source_composition=source_composition,
camera=camera,
camera_scene=camera_scene,
style=style,
)
def _krea_configured_cast_request_from_row(
row: dict[str, Any],
detail_level: str,
style_mode: str,
) -> krea_configured_cast_formatter.KreaConfiguredCastRequest:
primary = _clean(row.get("primary_subject"))
item = _row_value(row, "item", ("Sexual pose", "Erotic outfit", "Clothing")) or _clean(row.get("custom_item"))
item = re.sub(r",?\s*(fashion editorial|resort) styling$", "", item, flags=re.IGNORECASE)
scene = _row_value(row, "scene_text", ("Setting", "Scene")) or _clean(row.get("scene"))
pose = _row_value(row, "pose", ("Sexual pose", "Pose"))
expression = ""
if not _expression_disabled(row):
expression = _row_value(row, "character_expression_text") or _row_value(row, "expression", ("Facial expressions", "Facial expression"))
@@ -427,64 +485,42 @@ def _normal_row_to_krea(row: dict[str, Any], detail_level: str, style_mode: str)
camera = _camera_phrase(row)
camera_scene = _camera_scene_phrase(row)
style = _style_phrase(row, style_mode)
return _krea_configured_cast_request(
row,
detail_level,
style_mode,
primary,
item,
scene,
expression,
composition,
source_composition,
camera,
camera_scene,
style,
)
def _normal_row_to_krea(row: dict[str, Any], detail_level: str, style_mode: str) -> tuple[str, str]:
subject_type = _clean(row.get("subject_type"))
if subject_type == "configured_cast" or _clean(row.get("cast_summary")):
subject = _clean(row.get("subject_phrase") or primary or "adult sexual scene")
cast = _clean(row.get("cast_summary"))
try:
women_count = int(row.get("women_count") or 0)
men_count = int(row.get("men_count") or 0)
except (TypeError, ValueError):
women_count = men_count = 0
cast_descriptor_text = (
_clean(row.get("cast_descriptor_text"))
or _prompt_field(_clean(row.get("prompt")), "Characters")
or _prompt_field(_clean(row.get("prompt")), "Cast descriptors")
return krea_configured_cast_formatter.format_configured_cast(
_krea_configured_cast_request_from_row(row, detail_level, style_mode),
_krea_configured_cast_dependencies(),
)
pov_labels = _pov_labels_from_value(row.get("pov_character_labels"))
if pov_labels:
camera = ""
cast_prose, cast_labels = _cast_prose(cast_descriptor_text, omit_labels=pov_labels)
if not cast_labels and women_count == 1 and men_count == 1:
cast_labels = ["Woman A", "Man A"]
cast_labels = _merge_labels(cast_labels, pov_labels)
expression = _filter_pov_labeled_clauses(expression, pov_labels)
expression = _natural_label_text(expression, cast_labels)
composition = _sanitize_hardcore_environment_anchors(composition)
source_composition = _sanitize_hardcore_environment_anchors(source_composition)
role_graph = _sanitize_scene_text_for_cast(
_sanitize_hardcore_environment_anchors(row.get("source_role_graph") or row.get("role_graph")),
cast_labels,
)
item = _sanitize_scene_text_for_cast(_sanitize_hardcore_environment_anchors(item), cast_labels)
role_graph = _natural_label_text(role_graph, cast_labels)
item = _natural_label_text(item, cast_labels)
axis_values = _sanitize_hardcore_axis_values(row.get("item_axis_values"))
detail_density = _normalize_hardcore_detail_density(row.get("hardcore_detail_density"))
action = _hardcore_action_sentence(
role_graph,
item,
source_composition,
axis_values,
detail_density,
route_metadata_policy.row_action_family(row),
)
action = _pov_action_phrase(action, pov_labels, role_graph, item, source_composition, axis_values, detail_density)
output_composition = _pov_composition_text(composition, pov_labels)
parts = [
action,
_pov_camera_phrase(pov_labels),
cast_prose,
f"A consensual explicit adult scene with {subject}" if not action else "",
f"The cast includes {cast}" if cast and not cast_prose and not (women_count == 1 and men_count == 1) else "",
f"The setting is {scene}" if scene else "",
camera_scene,
_expression_phrase(expression),
_composition_phrase(output_composition, action, "The image is framed as", detail_density),
camera,
style if detail_level != "concise" else "",
]
return _paragraph(parts), "metadata(configured_cast)"
primary = _clean(row.get("primary_subject"))
item = _row_value(row, "item", ("Sexual pose", "Erotic outfit", "Clothing")) or _clean(row.get("custom_item"))
item = re.sub(r",?\s*(fashion editorial|resort) styling$", "", item, flags=re.IGNORECASE)
scene = _row_value(row, "scene_text", ("Setting", "Scene")) or _clean(row.get("scene"))
pose = _row_value(row, "pose", ("Sexual pose", "Pose"))
expression = ""
if not _expression_disabled(row):
expression = _row_value(row, "character_expression_text") or _row_value(row, "expression", ("Facial expressions", "Facial expression"))
composition = re.sub(r"^vertical\s+", "", _row_value(row, "composition", ("Composition",)), flags=re.IGNORECASE)
camera = _camera_phrase(row)
camera_scene = _camera_scene_phrase(row)
style = _style_phrase(row, style_mode)
if primary in ("woman", "man") or subject_type in ("woman", "man", "single_any"):
subject = _age_subject(row, "adult woman")