Centralize item axis value flattening
This commit is contained in:
+7
-42
@@ -7,6 +7,7 @@ try:
|
||||
from . import caption_metadata_routes
|
||||
from . import caption_policy
|
||||
from . import formatter_input as input_policy
|
||||
from . import item_axis_policy
|
||||
from . import krea_cast as cast_policy
|
||||
from . import route_metadata as route_metadata_policy
|
||||
from . import softcore_text_policy
|
||||
@@ -14,6 +15,7 @@ except ImportError: # Allows local smoke tests with `python -c`.
|
||||
import caption_metadata_routes
|
||||
import caption_policy
|
||||
import formatter_input as input_policy
|
||||
import item_axis_policy
|
||||
import krea_cast as cast_policy
|
||||
import route_metadata as route_metadata_policy
|
||||
import softcore_text_policy
|
||||
@@ -97,49 +99,12 @@ 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)
|
||||
details = item_axis_policy.row_axis_value_texts(
|
||||
row,
|
||||
skip_keys=item_axis_policy.METADATA_AXIS_KEYS,
|
||||
existing_text=existing_text,
|
||||
)
|
||||
return human_join(details)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user