Extract Krea normal row formatter route
This commit is contained in:
+51
-74
@@ -12,6 +12,7 @@ try:
|
||||
normalize_hardcore_detail_density as _normalize_hardcore_detail_density,
|
||||
)
|
||||
from . import krea_configured_cast_formatter
|
||||
from . import krea_normal_formatter
|
||||
from . import krea_pair_formatter
|
||||
from .hardcore_text_cleanup import (
|
||||
sanitize_hardcore_axis_values as _sanitize_hardcore_axis_values,
|
||||
@@ -45,6 +46,7 @@ except ImportError: # Allows local smoke tests with `python -c`.
|
||||
normalize_hardcore_detail_density as _normalize_hardcore_detail_density,
|
||||
)
|
||||
import krea_configured_cast_formatter
|
||||
import krea_normal_formatter
|
||||
import krea_pair_formatter
|
||||
from hardcore_text_cleanup import (
|
||||
sanitize_hardcore_axis_values as _sanitize_hardcore_axis_values,
|
||||
@@ -397,16 +399,51 @@ def _style_phrase(row: dict[str, Any], style_mode: str) -> str:
|
||||
return style or suffix
|
||||
|
||||
|
||||
def _couple_clothing_phrase(item: str) -> str:
|
||||
item = _clean(item)
|
||||
lower = item.lower()
|
||||
partner_text = re.sub(r"\bPartner ([AB]) wears\b", r"Partner \1 wearing", item)
|
||||
partner_text = re.sub(r"\bPartner ([AB]) has\b", r"Partner \1 with", partner_text)
|
||||
if lower.startswith("partner a "):
|
||||
return f"The outfits show {partner_text}"
|
||||
if lower.startswith(("two ", "paired ", "coordinated ")):
|
||||
return f"The outfits are {partner_text}"
|
||||
return f"The couple wears {item}"
|
||||
def _krea_normal_row_dependencies() -> krea_normal_formatter.KreaNormalRowDependencies:
|
||||
return krea_normal_formatter.KreaNormalRowDependencies(
|
||||
clean=_clean,
|
||||
row_value=_row_value,
|
||||
age_subject=_age_subject,
|
||||
age_detail_phrase=_age_detail_phrase,
|
||||
appearance_phrase=_appearance_phrase,
|
||||
with_indefinite_article=_with_indefinite_article,
|
||||
paragraph=_paragraph,
|
||||
)
|
||||
|
||||
|
||||
def _krea_normal_row_request_from_row(
|
||||
row: dict[str, Any],
|
||||
detail_level: str,
|
||||
style_mode: str,
|
||||
) -> krea_normal_formatter.KreaNormalRowRequest:
|
||||
subject_type = _clean(row.get("subject_type"))
|
||||
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)
|
||||
return krea_normal_formatter.KreaNormalRowRequest(
|
||||
row=row,
|
||||
detail_level=detail_level,
|
||||
style_mode=style_mode,
|
||||
subject_type=subject_type,
|
||||
primary=primary,
|
||||
item=item,
|
||||
scene=scene,
|
||||
pose=pose,
|
||||
expression=expression,
|
||||
composition=composition,
|
||||
camera=camera,
|
||||
camera_scene=camera_scene,
|
||||
style=style,
|
||||
)
|
||||
|
||||
|
||||
def _krea_configured_cast_dependencies() -> krea_configured_cast_formatter.KreaConfiguredCastDependencies:
|
||||
@@ -508,70 +545,10 @@ def _normal_row_to_krea(row: dict[str, Any], detail_level: str, style_mode: str)
|
||||
_krea_configured_cast_request_from_row(row, detail_level, style_mode),
|
||||
_krea_configured_cast_dependencies(),
|
||||
)
|
||||
|
||||
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")
|
||||
appearance = _appearance_phrase(row)
|
||||
parts = [
|
||||
_with_indefinite_article(subject),
|
||||
f"with {appearance}" if appearance else "",
|
||||
f"wearing {item}" if item else "",
|
||||
f"{pose}" if pose else "",
|
||||
f"with {expression}" if expression else "",
|
||||
f"in {scene}" if scene else "",
|
||||
camera_scene,
|
||||
f"framed as {composition}" if composition else "",
|
||||
camera,
|
||||
style if detail_level != "concise" else "",
|
||||
]
|
||||
return _paragraph([", ".join(part for part in parts[:6] if part), *parts[6:]]), "metadata(single)"
|
||||
|
||||
if subject_type == "couple" or primary in ("two women", "two men", "a woman and a man"):
|
||||
subject = _clean(row.get("subject_phrase") or primary or "adult couple")
|
||||
if subject == "woman and man":
|
||||
subject = "a woman and a man"
|
||||
ages = _age_detail_phrase(_row_value(row, "age", ("Ages",)) or row.get("age_band"))
|
||||
body = _row_value(row, "body", ("Body types",)) or _clean(row.get("body_type"))
|
||||
parts = [
|
||||
f"An adult couple: {subject}, all visibly adult",
|
||||
f"Age detail: {ages}" if ages else "",
|
||||
f"Body types: {body}" if body else "",
|
||||
_couple_clothing_phrase(item) if item else "",
|
||||
f"The pose is {pose}" if pose else "",
|
||||
f"The setting is {scene}" if scene else "",
|
||||
camera_scene,
|
||||
f"Facial expressions are {expression}" if expression else "",
|
||||
f"The image is framed as {composition}" if composition else "",
|
||||
camera,
|
||||
style if detail_level != "concise" else "",
|
||||
]
|
||||
return _paragraph(parts), "metadata(couple)"
|
||||
|
||||
subject = _age_subject(row, primary or "adult scene")
|
||||
parts = [
|
||||
f"{subject}",
|
||||
f"featuring {item}" if item else "",
|
||||
f"in {scene}" if scene else "",
|
||||
camera_scene,
|
||||
f"with {expression}" if expression else "",
|
||||
f"framed as {composition}" if composition else "",
|
||||
camera,
|
||||
style if detail_level != "concise" else "",
|
||||
]
|
||||
return _paragraph(parts), "metadata(generic)"
|
||||
return krea_normal_formatter.format_normal_row(
|
||||
_krea_normal_row_request_from_row(row, detail_level, style_mode),
|
||||
_krea_normal_row_dependencies(),
|
||||
)
|
||||
|
||||
|
||||
def _krea_pair_format_dependencies() -> krea_pair_formatter.KreaPairFormatDependencies:
|
||||
|
||||
Reference in New Issue
Block a user