Extract builder prompt route
This commit is contained in:
+65
-116
@@ -6,6 +6,7 @@ from typing import Any
|
||||
|
||||
try:
|
||||
from . import builder_config_route as builder_config_route_policy
|
||||
from . import builder_prompt_route as builder_prompt_route_policy
|
||||
from .category_library import (
|
||||
compatible_entries as _compatible_entries,
|
||||
compatible_entry as _compatible_entry,
|
||||
@@ -53,6 +54,7 @@ try:
|
||||
)
|
||||
except ImportError: # Allows local smoke tests with `python -c`.
|
||||
import builder_config_route as builder_config_route_policy
|
||||
import builder_prompt_route as builder_prompt_route_policy
|
||||
from category_library import (
|
||||
compatible_entries as _compatible_entries,
|
||||
compatible_entry as _compatible_entry,
|
||||
@@ -2460,6 +2462,35 @@ def _build_custom_row(
|
||||
return _assemble_custom_row(assembly_request)
|
||||
|
||||
|
||||
def _prompt_build_dependencies() -> builder_prompt_route_policy.PromptBuildDependencies:
|
||||
return builder_prompt_route_policy.PromptBuildDependencies(
|
||||
default_trigger=g.TRIGGER,
|
||||
default_negative=g.NEGATIVE_PROMPT,
|
||||
random_subcategory=RANDOM_SUBCATEGORY,
|
||||
apply_pool_extensions=apply_pool_extensions,
|
||||
normalize_ethnicity_filter=normalize_ethnicity_filter,
|
||||
is_false=_is_false,
|
||||
ratio_or_none=_ratio_or_none,
|
||||
parse_seed_config=_parse_seed_config,
|
||||
parse_location_config=_parse_location_config,
|
||||
parse_composition_config=_parse_composition_config,
|
||||
axis_rng=_axis_rng,
|
||||
pick_clothing_mode=_pick_clothing_mode,
|
||||
pick_pose_mode=_pick_pose_mode,
|
||||
pick_figure_bias=_pick_figure_bias,
|
||||
pick_expression_intensity=_pick_expression_intensity,
|
||||
auto_full_choice=_auto_full_choice,
|
||||
build_auto_weighted_row=_build_auto_weighted_row,
|
||||
build_direct_builtin_row=_build_direct_builtin_row,
|
||||
build_custom_row=_build_custom_row,
|
||||
apply_location_config_to_legacy_row=row_location_policy.apply_location_config_to_legacy_row,
|
||||
apply_composition_config_to_legacy_row=row_location_policy.apply_composition_config_to_legacy_row,
|
||||
disable_row_expression=_disable_row_expression,
|
||||
apply_camera_config=_apply_camera_config,
|
||||
normalize_prompt_row=row_policy.normalize_prompt_row,
|
||||
)
|
||||
|
||||
|
||||
def build_prompt(
|
||||
category: str,
|
||||
subcategory: str,
|
||||
@@ -2492,123 +2523,41 @@ def build_prompt(
|
||||
location_config: str | dict[str, Any] | None = None,
|
||||
composition_config: str | dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
apply_pool_extensions()
|
||||
row_number = max(1, int(row_number))
|
||||
start_index = max(1, int(start_index))
|
||||
seed = int(seed)
|
||||
ethnicity = normalize_ethnicity_filter(ethnicity, "any")
|
||||
expression_enabled = not _is_false(expression_enabled)
|
||||
minimal_ratio = _ratio_or_none(minimal_clothing_ratio)
|
||||
pose_ratio = _ratio_or_none(standard_pose_ratio)
|
||||
parsed_seed_config = _parse_seed_config(seed_config)
|
||||
parsed_location_config = _parse_location_config(location_config)
|
||||
parsed_composition_config = _parse_composition_config(composition_config)
|
||||
content_rng = _axis_rng(parsed_seed_config, "content", seed, row_number)
|
||||
pose_axis_rng = _axis_rng(parsed_seed_config, "pose", seed, row_number)
|
||||
person_rng = _axis_rng(parsed_seed_config, "person", seed, row_number)
|
||||
expression_rng = _axis_rng(parsed_seed_config, "expression", seed, row_number)
|
||||
clothing = clothing if clothing in ("full", "minimal", "random") else "full"
|
||||
poses = poses if poses in ("standard", "evocative", "random") else "standard"
|
||||
figure = figure if figure in ("curvy", "balanced", "bombshell", "random") else "curvy"
|
||||
clothing = _pick_clothing_mode(content_rng, clothing, minimal_ratio)
|
||||
poses = _pick_pose_mode(pose_axis_rng, poses, pose_ratio)
|
||||
figure = _pick_figure_bias(person_rng, figure)
|
||||
minimal_ratio = None
|
||||
pose_ratio = None
|
||||
expression_intensity, expression_intensity_source = _pick_expression_intensity(expression_rng, expression_intensity)
|
||||
|
||||
exact_custom_subcategory = bool(subcategory and subcategory != RANDOM_SUBCATEGORY and " / " in subcategory)
|
||||
|
||||
if category == "auto_full" and not exact_custom_subcategory:
|
||||
category = _auto_full_choice(parsed_seed_config, seed, row_number)
|
||||
|
||||
if category == "auto_weighted" and not exact_custom_subcategory:
|
||||
row = _build_auto_weighted_row(
|
||||
row_number,
|
||||
start_index,
|
||||
clothing,
|
||||
ethnicity,
|
||||
poses,
|
||||
float(backside_bias),
|
||||
figure,
|
||||
bool(no_plus_women),
|
||||
bool(no_black),
|
||||
minimal_ratio,
|
||||
pose_ratio,
|
||||
seed,
|
||||
)
|
||||
elif category in ("woman", "man", "couple", "group_or_layout") and not exact_custom_subcategory:
|
||||
row = _build_direct_builtin_row(
|
||||
category,
|
||||
row_number,
|
||||
start_index,
|
||||
clothing,
|
||||
ethnicity,
|
||||
poses,
|
||||
float(backside_bias),
|
||||
figure,
|
||||
bool(no_plus_women),
|
||||
bool(no_black),
|
||||
minimal_ratio,
|
||||
pose_ratio,
|
||||
seed,
|
||||
)
|
||||
else:
|
||||
row = _build_custom_row(
|
||||
category,
|
||||
subcategory,
|
||||
row_number,
|
||||
start_index,
|
||||
ethnicity,
|
||||
poses,
|
||||
figure,
|
||||
bool(no_plus_women),
|
||||
bool(no_black),
|
||||
int(women_count),
|
||||
int(men_count),
|
||||
seed,
|
||||
parsed_seed_config,
|
||||
expression_enabled,
|
||||
expression_intensity,
|
||||
expression_intensity_source,
|
||||
character_profile,
|
||||
character_cast,
|
||||
expression_phase,
|
||||
hardcore_position_config,
|
||||
parsed_location_config,
|
||||
parsed_composition_config,
|
||||
)
|
||||
|
||||
if row.get("source") == "built_in_generator":
|
||||
row = row_location_policy.apply_location_config_to_legacy_row(
|
||||
row,
|
||||
parsed_location_config,
|
||||
parsed_seed_config,
|
||||
seed,
|
||||
row_number,
|
||||
)
|
||||
row = row_location_policy.apply_composition_config_to_legacy_row(
|
||||
row,
|
||||
parsed_composition_config,
|
||||
parsed_seed_config,
|
||||
seed,
|
||||
row_number,
|
||||
)
|
||||
if not expression_enabled:
|
||||
row = _disable_row_expression(row, "disabled")
|
||||
row = _apply_camera_config(row, camera_config)
|
||||
active_trigger = trigger.strip() or g.TRIGGER
|
||||
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,
|
||||
return builder_prompt_route_policy.build_prompt(
|
||||
builder_prompt_route_policy.PromptBuildRequest(
|
||||
category=category,
|
||||
subcategory=subcategory,
|
||||
row_number=row_number,
|
||||
start_index=start_index,
|
||||
seed=seed,
|
||||
clothing=clothing,
|
||||
ethnicity=ethnicity,
|
||||
poses=poses,
|
||||
backside_bias=backside_bias,
|
||||
figure=figure,
|
||||
no_plus_women=no_plus_women,
|
||||
no_black=no_black,
|
||||
minimal_clothing_ratio=minimal_clothing_ratio,
|
||||
standard_pose_ratio=standard_pose_ratio,
|
||||
trigger=trigger,
|
||||
prepend_trigger_to_prompt=prepend_trigger_to_prompt,
|
||||
extra_positive=extra_positive,
|
||||
extra_negative=extra_negative,
|
||||
seed_config=seed_config,
|
||||
women_count=women_count,
|
||||
men_count=men_count,
|
||||
camera_config=camera_config,
|
||||
expression_intensity=expression_intensity,
|
||||
character_profile=character_profile,
|
||||
character_cast=character_cast,
|
||||
expression_enabled=expression_enabled,
|
||||
expression_phase=expression_phase,
|
||||
hardcore_position_config=hardcore_position_config,
|
||||
location_config=location_config,
|
||||
composition_config=composition_config,
|
||||
),
|
||||
_prompt_build_dependencies(),
|
||||
)
|
||||
row.setdefault("expression_intensity", expression_intensity)
|
||||
row.setdefault("expression_intensity_source", expression_intensity_source)
|
||||
return row
|
||||
|
||||
|
||||
def _prompt_from_configs_dependencies() -> builder_config_route_policy.PromptFromConfigsDependencies:
|
||||
|
||||
Reference in New Issue
Block a user