Make POV prompt restore affect Krea output
This commit is contained in:
@@ -100,6 +100,101 @@ class CategoryItemRoute:
|
||||
}
|
||||
|
||||
|
||||
def _unique_texts(values: list[Any]) -> list[str]:
|
||||
selected: list[str] = []
|
||||
seen: set[str] = set()
|
||||
for value in values:
|
||||
text = row_item_policy.entry_text(value).strip(" .;")
|
||||
lower = text.lower()
|
||||
if not text or lower in seen:
|
||||
continue
|
||||
selected.append(text)
|
||||
seen.add(lower)
|
||||
return selected
|
||||
|
||||
|
||||
def _restore_axis_values_for_context(
|
||||
values: list[Any],
|
||||
*,
|
||||
subcategory_slug: str,
|
||||
axis_name: str,
|
||||
item_axis_values: dict[str, Any],
|
||||
women_count: int,
|
||||
men_count: int,
|
||||
) -> list[Any]:
|
||||
values = category_policy.compatible_entries(values, women_count, men_count)
|
||||
if subcategory_slug == "oral_sex":
|
||||
return row_item_policy.oral_axis_values_for_context(
|
||||
values,
|
||||
str(item_axis_values.get("position") or ""),
|
||||
str(item_axis_values.get("oral_act") or ""),
|
||||
axis_name,
|
||||
)
|
||||
if subcategory_slug == "outercourse_sex":
|
||||
return row_item_policy.outercourse_axis_values_for_position(
|
||||
values,
|
||||
str(item_axis_values.get("position") or ""),
|
||||
axis_name,
|
||||
)
|
||||
if subcategory_slug == "anal_double_penetration":
|
||||
return row_item_policy.anal_axis_values_for_position(
|
||||
values,
|
||||
str(item_axis_values.get("position") or ""),
|
||||
axis_name,
|
||||
)
|
||||
return values
|
||||
|
||||
|
||||
def _restored_prompt_axis_values(
|
||||
rng: Any,
|
||||
subcategory: dict[str, Any],
|
||||
item_axis_values: dict[str, Any],
|
||||
hardcore_position_config: dict[str, Any],
|
||||
women_count: int,
|
||||
men_count: int,
|
||||
) -> dict[str, str]:
|
||||
restore_axes = hardcore_position_policy.normalize_restore_prompt_axes(
|
||||
hardcore_position_config.get("restore_prompt_axes") if isinstance(hardcore_position_config, dict) else []
|
||||
)
|
||||
raw_axes = subcategory.get("item_axes")
|
||||
if not restore_axes or not isinstance(raw_axes, dict):
|
||||
return {}
|
||||
|
||||
restored: dict[str, str] = {}
|
||||
subcategory_slug = str(subcategory.get("slug") or "").lower()
|
||||
for axis_name in restore_axes:
|
||||
existing = ""
|
||||
if axis_name in item_axis_values and item_axis_values.get(axis_name) is not None:
|
||||
existing = row_item_policy.entry_text(item_axis_values.get(axis_name)).strip(" .;")
|
||||
if existing:
|
||||
restored[axis_name] = existing
|
||||
continue
|
||||
values = _list_from(raw_axes.get(axis_name))
|
||||
if not values:
|
||||
continue
|
||||
values = _restore_axis_values_for_context(
|
||||
values,
|
||||
subcategory_slug=subcategory_slug,
|
||||
axis_name=axis_name,
|
||||
item_axis_values=item_axis_values,
|
||||
women_count=women_count,
|
||||
men_count=men_count,
|
||||
)
|
||||
if not values:
|
||||
continue
|
||||
restored[axis_name] = row_item_policy.entry_text(row_item_policy.weighted_choice(rng, values)).strip(" .;")
|
||||
return {axis: value for axis, value in restored.items() if value}
|
||||
|
||||
|
||||
def _append_restored_prompt_details(item_text: str, details: list[str]) -> str:
|
||||
details = [detail for detail in _unique_texts(details) if detail.lower() not in str(item_text or "").lower()]
|
||||
if not details:
|
||||
return item_text
|
||||
if not item_text:
|
||||
return "; ".join(details)
|
||||
return f"{str(item_text).rstrip(' .')}, with {'; '.join(details)}"
|
||||
|
||||
|
||||
def select_category_item_route_result(
|
||||
*,
|
||||
category_choice: str,
|
||||
@@ -159,6 +254,23 @@ def select_category_item_route_result(
|
||||
women_count,
|
||||
men_count,
|
||||
)
|
||||
restored_axis_values = _restored_prompt_axis_values(
|
||||
content_rng,
|
||||
subcategory,
|
||||
item_axis_values,
|
||||
parsed_hardcore_position_config,
|
||||
women_count,
|
||||
men_count,
|
||||
)
|
||||
if restored_axis_values:
|
||||
restored_details = _unique_texts(list(restored_axis_values.values()))
|
||||
item_axis_values = {
|
||||
**item_axis_values,
|
||||
**restored_axis_values,
|
||||
"restored_prompt_axes": list(restored_axis_values.keys()),
|
||||
"restored_prompt_details": restored_details,
|
||||
}
|
||||
item_text = _append_restored_prompt_details(item_text, restored_details)
|
||||
if is_pose_category:
|
||||
item_text = sanitize_hardcore_environment_anchors(item_text)
|
||||
item_axis_values = sanitize_hardcore_axis_values(item_axis_values)
|
||||
|
||||
Reference in New Issue
Block a user