Split SDXL sentence-boundary tags
This commit is contained in:
@@ -63,6 +63,7 @@ def split_tag_text(text: Any) -> list[str]:
|
|||||||
text,
|
text,
|
||||||
flags=re.IGNORECASE,
|
flags=re.IGNORECASE,
|
||||||
)
|
)
|
||||||
|
text = re.sub(r"(?<=[A-Za-z0-9)])\.\s+(?=[A-Za-z])", ", ", text)
|
||||||
text = re.sub(r"(?<!-)\b(?:and|with)\b(?!-)", ",", text, flags=re.IGNORECASE)
|
text = re.sub(r"(?<!-)\b(?:and|with)\b(?!-)", ",", text, flags=re.IGNORECASE)
|
||||||
text = re.sub(r"\b(woman|man),\s+(woman|man)\s+are\b", r"\1 and \2 are", text, flags=re.IGNORECASE)
|
text = re.sub(r"\b(woman|man),\s+(woman|man)\s+are\b", r"\1 and \2 are", text, flags=re.IGNORECASE)
|
||||||
parts = re.split(r"\s*[,;]\s*", text)
|
parts = re.split(r"\s*[,;]\s*", text)
|
||||||
|
|||||||
@@ -594,6 +594,12 @@ def _sdxl_character_pair_fragment_issues(name: str, sdxl_prompt: str) -> list[st
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def _sdxl_sentence_boundary_tag_issues(name: str, sdxl_prompt: str) -> list[str]:
|
||||||
|
if re.search(r"\b[a-z][^,.]{0,80}\.\s+(?:woman|man|the|keep|use)\b", sdxl_prompt, flags=re.IGNORECASE):
|
||||||
|
return [f"{name}.sdxl_prompt: sentence_boundary_tag"]
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
def _trace_dict(formatter_name: str, payload: dict[str, Any]) -> tuple[dict[str, Any], str]:
|
def _trace_dict(formatter_name: str, payload: dict[str, Any]) -> tuple[dict[str, Any], str]:
|
||||||
trace_text = str(payload.get("route_trace_json") or "")
|
trace_text = str(payload.get("route_trace_json") or "")
|
||||||
if not trace_text:
|
if not trace_text:
|
||||||
@@ -734,6 +740,7 @@ def _formatter_issues(
|
|||||||
issues.extend(_sdxl_expression_label_issues(name, sdxl_prompt))
|
issues.extend(_sdxl_expression_label_issues(name, sdxl_prompt))
|
||||||
issues.extend(_sdxl_hyphen_fragment_issues(name, sdxl_prompt))
|
issues.extend(_sdxl_hyphen_fragment_issues(name, sdxl_prompt))
|
||||||
issues.extend(_sdxl_character_pair_fragment_issues(name, sdxl_prompt))
|
issues.extend(_sdxl_character_pair_fragment_issues(name, sdxl_prompt))
|
||||||
|
issues.extend(_sdxl_sentence_boundary_tag_issues(name, sdxl_prompt))
|
||||||
|
|
||||||
for label, value in (
|
for label, value in (
|
||||||
(f"{name}.krea_negative", krea.get("negative_prompt")),
|
(f"{name}.krea_negative", krea.get("negative_prompt")),
|
||||||
|
|||||||
@@ -4683,6 +4683,14 @@ def smoke_sdxl_tag_policy() -> None:
|
|||||||
subject_pair_tags = sdxl_tag_policy.split_tag_text("Woman A, Man A are mid-transition with hands on hips")
|
subject_pair_tags = sdxl_tag_policy.split_tag_text("Woman A, Man A are mid-transition with hands on hips")
|
||||||
_expect("woman and man are mid-transition" in subject_pair_tags, "SDXL tag splitter broke paired character clause")
|
_expect("woman and man are mid-transition" in subject_pair_tags, "SDXL tag splitter broke paired character clause")
|
||||||
_expect("woman" not in subject_pair_tags and "man are mid-transition" not in subject_pair_tags, "SDXL tag splitter emitted broken paired character fragments")
|
_expect("woman" not in subject_pair_tags and "man are mid-transition" not in subject_pair_tags, "SDXL tag splitter emitted broken paired character fragments")
|
||||||
|
sentence_boundary_tags = sdxl_tag_policy.split_tag_text("keep hands on hips, breasts, thighs. Man watches close")
|
||||||
|
sentence_boundary_tags_lower = [tag.lower() for tag in sentence_boundary_tags]
|
||||||
|
_expect("thighs" in sentence_boundary_tags, "SDXL tag splitter lost pre-period tag")
|
||||||
|
_expect("man watches close" in sentence_boundary_tags_lower, "SDXL tag splitter did not split sentence-boundary tag")
|
||||||
|
_expect(
|
||||||
|
"thighs. man watches close" not in sentence_boundary_tags_lower,
|
||||||
|
"SDXL tag splitter kept sentence-boundary tag fragment",
|
||||||
|
)
|
||||||
_expect(
|
_expect(
|
||||||
sdxl_formatter._camera_tags(row) == sdxl_tag_policy.camera_tags(row),
|
sdxl_formatter._camera_tags(row) == sdxl_tag_policy.camera_tags(row),
|
||||||
"SDXL formatter camera helper should delegate to sdxl_tag_policy",
|
"SDXL formatter camera helper should delegate to sdxl_tag_policy",
|
||||||
|
|||||||
Reference in New Issue
Block a user