Extract row normalization policy
This commit is contained in:
+11
-26
@@ -38,6 +38,7 @@ try:
|
||||
from . import pair_output
|
||||
from . import pair_rows
|
||||
from . import pair_options
|
||||
from . import row_normalization as row_policy
|
||||
from . import scene_camera_adapters
|
||||
from . import seed_config as seed_policy
|
||||
from .hardcore_text_cleanup import (
|
||||
@@ -46,11 +47,6 @@ try:
|
||||
)
|
||||
from .hardcore_action_metadata import source_hardcore_action_family
|
||||
from .hardcore_role_graphs import build_hardcore_role_graph
|
||||
from .prompt_hygiene import (
|
||||
sanitize_caption_text,
|
||||
sanitize_negative_text,
|
||||
sanitize_prompt_text,
|
||||
)
|
||||
except ImportError: # Allows local smoke tests with `python -c`.
|
||||
from category_library import (
|
||||
category_json_files as _json_files,
|
||||
@@ -82,6 +78,7 @@ except ImportError: # Allows local smoke tests with `python -c`.
|
||||
import pair_output
|
||||
import pair_rows
|
||||
import pair_options
|
||||
import row_normalization as row_policy
|
||||
import scene_camera_adapters
|
||||
import seed_config as seed_policy
|
||||
from hardcore_text_cleanup import (
|
||||
@@ -90,11 +87,6 @@ except ImportError: # Allows local smoke tests with `python -c`.
|
||||
)
|
||||
from hardcore_action_metadata import source_hardcore_action_family
|
||||
from hardcore_role_graphs import build_hardcore_role_graph
|
||||
from prompt_hygiene import (
|
||||
sanitize_caption_text,
|
||||
sanitize_negative_text,
|
||||
sanitize_prompt_text,
|
||||
)
|
||||
|
||||
|
||||
ROOT_DIR = Path(__file__).resolve().parent
|
||||
@@ -1377,17 +1369,11 @@ def _disable_row_expression(row: dict[str, Any], source: str = "disabled") -> di
|
||||
|
||||
|
||||
def _prepend_trigger(prompt: str, trigger: str, enabled: bool) -> str:
|
||||
trigger = trigger.strip()
|
||||
if not enabled or not trigger:
|
||||
return prompt
|
||||
if prompt.lower().startswith(trigger.lower()):
|
||||
return prompt
|
||||
return f"{trigger}, {prompt}"
|
||||
return row_policy.prepend_trigger(prompt, trigger, enabled)
|
||||
|
||||
|
||||
def _combined_negative(base: str, extra: str) -> str:
|
||||
parts = [part.strip() for part in (base, extra) if part and part.strip()]
|
||||
return ", ".join(parts)
|
||||
return row_policy.combined_negative(base, extra)
|
||||
|
||||
|
||||
def camera_mode_choices() -> list[str]:
|
||||
@@ -4190,17 +4176,16 @@ def build_prompt(
|
||||
)
|
||||
if not expression_enabled:
|
||||
row = _disable_row_expression(row, "disabled")
|
||||
if extra_positive.strip():
|
||||
row["prompt"] = f"{row['prompt'].rstrip()} {extra_positive.strip()}"
|
||||
row = _apply_camera_config(row, camera_config)
|
||||
active_trigger = trigger.strip() or g.TRIGGER
|
||||
row["prompt"] = _prepend_trigger(row["prompt"], active_trigger, bool(prepend_trigger_to_prompt))
|
||||
row["prompt"] = sanitize_prompt_text(row["prompt"], triggers=(active_trigger,))
|
||||
row["caption"] = sanitize_caption_text(row.get("caption", ""), triggers=(active_trigger,))
|
||||
row["negative_prompt"] = sanitize_negative_text(
|
||||
_combined_negative(row.get("negative_prompt", g.NEGATIVE_PROMPT), extra_negative)
|
||||
row = row_policy.normalize_prompt_row(
|
||||
row,
|
||||
active_trigger=active_trigger,
|
||||
prepend_trigger_to_prompt=bool(prepend_trigger_to_prompt),
|
||||
extra_positive=extra_positive,
|
||||
extra_negative=extra_negative,
|
||||
default_negative=g.NEGATIVE_PROMPT,
|
||||
)
|
||||
row["trigger"] = active_trigger
|
||||
row.setdefault("expression_intensity", expression_intensity)
|
||||
row.setdefault("expression_intensity_source", expression_intensity_source)
|
||||
return row
|
||||
|
||||
Reference in New Issue
Block a user