Centralize formatter target policy
This commit is contained in:
+11
-3
@@ -3,6 +3,11 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Callable
|
||||
|
||||
try:
|
||||
from . import formatter_target as target_policy
|
||||
except ImportError: # pragma: no cover - plain-script smoke tests
|
||||
import formatter_target as target_policy
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SDXLFormatRequest:
|
||||
@@ -56,11 +61,12 @@ def format_sdxl_prompt_result(request: SDXLFormatRequest, deps: SDXLFormatDepend
|
||||
request.style_preset,
|
||||
request.quality_preset,
|
||||
)
|
||||
target = request.target if request.target in ("auto", "single", "softcore", "hardcore") else "auto"
|
||||
target = target_policy.normalize_target(request.target)
|
||||
nude_weight = max(0.1, min(3.0, float(request.nude_weight)))
|
||||
row, method = deps.row_from_inputs(request.source_text, request.metadata_json, request.input_hint)
|
||||
|
||||
if row and row.get("mode") == "Insta/OF":
|
||||
pair_target = target_policy.pair_policy(target)
|
||||
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 = deps.soft_tags(soft_row, row, nude_weight)
|
||||
@@ -85,9 +91,11 @@ def format_sdxl_prompt_result(request: SDXLFormatRequest, deps: SDXLFormatDepend
|
||||
request.custom_quality,
|
||||
request.extra_positive,
|
||||
)
|
||||
selected = hard_prompt if target == "hardcore" else soft_prompt
|
||||
selected = hard_prompt if pair_target.selected_side == "hardcore" else soft_prompt
|
||||
selected_negative = (
|
||||
row.get("hardcore_negative_prompt") if target == "hardcore" else row.get("softcore_negative_prompt")
|
||||
row.get("hardcore_negative_prompt")
|
||||
if pair_target.selected_side == "hardcore"
|
||||
else row.get("softcore_negative_prompt")
|
||||
)
|
||||
output = {
|
||||
"sdxl_prompt": selected,
|
||||
|
||||
Reference in New Issue
Block a user