Extract SDXL format dispatch route
This commit is contained in:
+42
-81
@@ -4,12 +4,14 @@ from typing import Any
|
||||
|
||||
try:
|
||||
from . import formatter_input as input_policy
|
||||
from . import sdxl_format_route
|
||||
from . import sdxl_tag_policy
|
||||
from . import sdxl_tag_routes
|
||||
from . import sdxl_presets as sdxl_policy
|
||||
from .prompt_hygiene import sanitize_negative_text, sanitize_tag_prompt
|
||||
except ImportError: # Allows local smoke tests with `python -c`.
|
||||
import formatter_input as input_policy
|
||||
import sdxl_format_route
|
||||
import sdxl_tag_policy
|
||||
import sdxl_tag_routes
|
||||
import sdxl_presets as sdxl_policy
|
||||
@@ -203,6 +205,26 @@ def _fallback_text_to_sdxl(
|
||||
return tags, negative, "text(fallback)"
|
||||
|
||||
|
||||
def _sdxl_format_dependencies() -> sdxl_format_route.SDXLFormatDependencies:
|
||||
return sdxl_format_route.SDXLFormatDependencies(
|
||||
default_negative=SDXL_DEFAULT_NEGATIVE,
|
||||
apply_formatter_profile=lambda profile, style, quality: sdxl_policy.apply_formatter_profile(
|
||||
profile,
|
||||
style_preset=style,
|
||||
quality_preset=quality,
|
||||
),
|
||||
clean=_clean,
|
||||
row_from_inputs=_row_from_inputs,
|
||||
row_core_tags=_row_core_tags,
|
||||
soft_tags=_soft_tags,
|
||||
hard_tags=_hard_tags,
|
||||
fallback_text_to_sdxl=_fallback_text_to_sdxl,
|
||||
assemble_prompt=_assemble_prompt,
|
||||
combine_negative=_combine_negative,
|
||||
sanitize_negative_text=sanitize_negative_text,
|
||||
)
|
||||
|
||||
|
||||
def format_sdxl_prompt(
|
||||
source_text: str,
|
||||
metadata_json: str = "",
|
||||
@@ -221,85 +243,24 @@ def format_sdxl_prompt(
|
||||
extra_negative: str = "",
|
||||
formatter_profile: str = "manual_controls",
|
||||
) -> dict[str, str]:
|
||||
style_preset, quality_preset = sdxl_policy.apply_formatter_profile(
|
||||
formatter_profile,
|
||||
style_preset=style_preset,
|
||||
quality_preset=quality_preset,
|
||||
)
|
||||
target = target if target in ("auto", "single", "softcore", "hardcore") else "auto"
|
||||
nude_weight = max(0.1, min(3.0, float(nude_weight)))
|
||||
row, method = _row_from_inputs(source_text, metadata_json, input_hint)
|
||||
|
||||
if row and row.get("mode") == "Insta/OF":
|
||||
soft_row = row.get("softcore_row") if isinstance(row.get("softcore_row"), dict) else {}
|
||||
hard_row = row.get("hardcore_row") if isinstance(row.get("hardcore_row"), dict) else {}
|
||||
soft_body = _soft_tags(soft_row, row, nude_weight)
|
||||
hard_body = _hard_tags(hard_row, row, nude_weight)
|
||||
soft_prompt = _assemble_prompt(
|
||||
soft_body,
|
||||
style_preset,
|
||||
quality_preset,
|
||||
trigger,
|
||||
prepend_trigger,
|
||||
custom_style,
|
||||
custom_quality,
|
||||
extra_positive,
|
||||
)
|
||||
hard_prompt = _assemble_prompt(
|
||||
hard_body,
|
||||
style_preset,
|
||||
quality_preset,
|
||||
trigger,
|
||||
prepend_trigger,
|
||||
custom_style,
|
||||
custom_quality,
|
||||
extra_positive,
|
||||
)
|
||||
selected = hard_prompt if target == "hardcore" else soft_prompt
|
||||
selected_negative = (
|
||||
row.get("hardcore_negative_prompt") if target == "hardcore" else row.get("softcore_negative_prompt")
|
||||
)
|
||||
return {
|
||||
"sdxl_prompt": selected,
|
||||
"negative_prompt": sanitize_negative_text(
|
||||
_combine_negative(SDXL_DEFAULT_NEGATIVE, selected_negative, negative_prompt, extra_negative)
|
||||
),
|
||||
"sdxl_softcore_prompt": soft_prompt,
|
||||
"sdxl_hardcore_prompt": hard_prompt,
|
||||
"softcore_negative_prompt": sanitize_negative_text(
|
||||
_combine_negative(SDXL_DEFAULT_NEGATIVE, row.get("softcore_negative_prompt"), extra_negative)
|
||||
),
|
||||
"hardcore_negative_prompt": sanitize_negative_text(
|
||||
_combine_negative(SDXL_DEFAULT_NEGATIVE, row.get("hardcore_negative_prompt"), extra_negative)
|
||||
),
|
||||
"method": f"{method}:sdxl(insta_of_pair)",
|
||||
}
|
||||
|
||||
if row:
|
||||
body = ", ".join(_row_core_tags(row, nude_weight))
|
||||
extracted_negative = _clean(row.get("negative_prompt"))
|
||||
method = f"{method}:sdxl(metadata)"
|
||||
else:
|
||||
body, extracted_negative, method = _fallback_text_to_sdxl(source_text, preserve_trigger, nude_weight)
|
||||
|
||||
prompt = _assemble_prompt(
|
||||
body,
|
||||
style_preset,
|
||||
quality_preset,
|
||||
trigger,
|
||||
prepend_trigger,
|
||||
custom_style,
|
||||
custom_quality,
|
||||
extra_positive,
|
||||
)
|
||||
return {
|
||||
"sdxl_prompt": prompt,
|
||||
"negative_prompt": sanitize_negative_text(
|
||||
_combine_negative(SDXL_DEFAULT_NEGATIVE, extracted_negative, negative_prompt, extra_negative)
|
||||
return sdxl_format_route.format_sdxl_prompt(
|
||||
sdxl_format_route.SDXLFormatRequest(
|
||||
source_text=source_text,
|
||||
metadata_json=metadata_json,
|
||||
negative_prompt=negative_prompt,
|
||||
input_hint=input_hint,
|
||||
target=target,
|
||||
style_preset=style_preset,
|
||||
quality_preset=quality_preset,
|
||||
trigger=trigger,
|
||||
prepend_trigger=prepend_trigger,
|
||||
preserve_trigger=preserve_trigger,
|
||||
nude_weight=nude_weight,
|
||||
custom_style=custom_style,
|
||||
custom_quality=custom_quality,
|
||||
extra_positive=extra_positive,
|
||||
extra_negative=extra_negative,
|
||||
formatter_profile=formatter_profile,
|
||||
),
|
||||
"sdxl_softcore_prompt": "",
|
||||
"sdxl_hardcore_prompt": "",
|
||||
"softcore_negative_prompt": "",
|
||||
"hardcore_negative_prompt": "",
|
||||
"method": method,
|
||||
}
|
||||
_sdxl_format_dependencies(),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user