Add prompt hygiene architecture pass
This commit is contained in:
+14
-7
@@ -4,6 +4,11 @@ import json
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
try:
|
||||
from .prompt_hygiene import sanitize_negative_text, sanitize_prose_text
|
||||
except ImportError: # Allows local smoke tests with `python -c`.
|
||||
from prompt_hygiene import sanitize_negative_text, sanitize_prose_text
|
||||
|
||||
|
||||
TRIGGER_CANDIDATES = (
|
||||
"sxcpinup_coloredpencil",
|
||||
@@ -2678,20 +2683,21 @@ def format_krea2_prompt(
|
||||
|
||||
if row and row.get("mode") == "Insta/OF":
|
||||
soft_prompt, soft_negative, hard_prompt, hard_negative = _insta_pair_to_krea(row, detail_level, style_mode)
|
||||
selected = hard_prompt if target == "hardcore" else soft_prompt if target == "softcore" else soft_prompt
|
||||
selected_negative = hard_negative if target == "hardcore" else soft_negative
|
||||
if extra_positive.strip():
|
||||
selected = f"{selected.rstrip()} {extra_positive.strip()}"
|
||||
soft_prompt = f"{soft_prompt.rstrip()} {extra_positive.strip()}"
|
||||
hard_prompt = f"{hard_prompt.rstrip()} {extra_positive.strip()}"
|
||||
negative = _combine_negative(selected_negative, negative_prompt, extra_negative)
|
||||
soft_prompt = sanitize_prose_text(soft_prompt, triggers=TRIGGER_CANDIDATES)
|
||||
hard_prompt = sanitize_prose_text(hard_prompt, triggers=TRIGGER_CANDIDATES)
|
||||
selected = hard_prompt if target == "hardcore" else soft_prompt if target == "softcore" else soft_prompt
|
||||
selected_negative = hard_negative if target == "hardcore" else soft_negative
|
||||
negative = sanitize_negative_text(_combine_negative(selected_negative, negative_prompt, extra_negative))
|
||||
return {
|
||||
"krea_prompt": selected,
|
||||
"negative_prompt": negative,
|
||||
"krea_softcore_prompt": soft_prompt,
|
||||
"krea_hardcore_prompt": hard_prompt,
|
||||
"softcore_negative_prompt": _combine_negative(soft_negative, extra_negative),
|
||||
"hardcore_negative_prompt": _combine_negative(hard_negative, extra_negative),
|
||||
"softcore_negative_prompt": sanitize_negative_text(_combine_negative(soft_negative, extra_negative)),
|
||||
"hardcore_negative_prompt": sanitize_negative_text(_combine_negative(hard_negative, extra_negative)),
|
||||
"method": f"{method}:krea2(insta_of_pair)",
|
||||
}
|
||||
|
||||
@@ -2704,7 +2710,8 @@ def format_krea2_prompt(
|
||||
|
||||
if extra_positive.strip():
|
||||
prompt = f"{prompt.rstrip()} {extra_positive.strip()}"
|
||||
negative = _combine_negative(extracted_negative, negative_prompt, extra_negative)
|
||||
prompt = sanitize_prose_text(prompt, triggers=TRIGGER_CANDIDATES)
|
||||
negative = sanitize_negative_text(_combine_negative(extracted_negative, negative_prompt, extra_negative))
|
||||
return {
|
||||
"krea_prompt": prompt,
|
||||
"negative_prompt": negative,
|
||||
|
||||
Reference in New Issue
Block a user