Use item axis details in captions
This commit is contained in:
@@ -97,6 +97,52 @@ def metadata_action_label(row: dict[str, Any], default: str = "sexual pose") ->
|
||||
return caption_policy.metadata_action_label(row, default)
|
||||
|
||||
|
||||
def _axis_value_texts(value: Any) -> list[str]:
|
||||
if isinstance(value, str):
|
||||
text = clean_text(value).strip(" .")
|
||||
return [text] if text and text.lower() not in ("any", "auto", "random", "none") else []
|
||||
if isinstance(value, (int, float, bool)) or value is None:
|
||||
return []
|
||||
if isinstance(value, list):
|
||||
texts: list[str] = []
|
||||
for item in value:
|
||||
texts.extend(_axis_value_texts(item))
|
||||
return texts
|
||||
if isinstance(value, dict):
|
||||
for preferred in ("text", "prompt", "template", "value", "name"):
|
||||
preferred_texts = _axis_value_texts(value.get(preferred))
|
||||
if preferred_texts:
|
||||
return preferred_texts
|
||||
texts: list[str] = []
|
||||
for item in value.values():
|
||||
texts.extend(_axis_value_texts(item))
|
||||
return texts
|
||||
return []
|
||||
|
||||
|
||||
def item_axis_detail_text(row: dict[str, Any], existing_text: str = "") -> str:
|
||||
if not isinstance(row, dict):
|
||||
return ""
|
||||
axis_values = row.get("item_axis_values")
|
||||
if not isinstance(axis_values, dict):
|
||||
return ""
|
||||
existing = clean_text(existing_text).lower()
|
||||
details: list[str] = []
|
||||
seen: set[str] = set()
|
||||
skipped_keys = {"action_family", "position_family", "position_key", "position_keys"}
|
||||
for key, value in axis_values.items():
|
||||
if str(key) in skipped_keys:
|
||||
continue
|
||||
for text in _axis_value_texts(value):
|
||||
normalized = clean_text(text).strip(" .")
|
||||
lower = normalized.lower()
|
||||
if not normalized or lower in seen or lower in existing:
|
||||
continue
|
||||
details.append(normalized)
|
||||
seen.add(lower)
|
||||
return human_join(details)
|
||||
|
||||
|
||||
def prompt_cast_descriptors(text: str) -> str:
|
||||
return cast_policy.prompt_cast_descriptors(text)
|
||||
|
||||
@@ -299,6 +345,7 @@ def metadata_route_dependencies(
|
||||
subject_phrase_from_counts=subject_phrase_from_counts,
|
||||
verb_for_row=verb_for_row,
|
||||
metadata_action_label=metadata_action_label,
|
||||
item_axis_detail_text=item_axis_detail_text,
|
||||
natural_cast_descriptor_text=natural_cast_descriptor_text,
|
||||
cast_labels=cast_labels,
|
||||
natural_label_text=natural_label_text,
|
||||
|
||||
Reference in New Issue
Block a user