astrbot_plugin_imagestudio/engines/character_flow.py

145 行
4.6 KiB
Python

"""Canonical gradual-character workflow catalog.
The node id is the durable identity. ``node_key`` is a semantic label and
older installations already contain the v1 labels below, so callers must use
``canonical_gradual_node_key`` instead of open-coding aliases.
"""
from __future__ import annotations
from typing import Any
CHARACTER_GRADUAL_TEMPLATE_VERSION = "character_gradual_v2"
LEGACY_CHARACTER_GRADUAL_NODE_KEYS: dict[str, str] = {
"half_body": "upper_body",
"expression_sheet": "turnaround",
"pose_sheet": "design_sheet",
"final_pack": "profile_card",
}
CHARACTER_GRADUAL_STEPS: tuple[dict[str, Any], ...] = (
{
"node_key": "profile_brief",
"title": "拆解人设",
"step_name": "profile_brief",
"description": "Extract identity, personality, appearance, outfit, and consistency anchors.",
"node_type": "planning",
"sort_order": 10,
"stage_code": "RS",
},
{
"node_key": "prompt_plan",
"title": "提示词规划",
"step_name": "prompt_plan",
"description": "Plan prompts and inheritance rules for every downstream image stage.",
"node_type": "planning",
"sort_order": 20,
"stage_code": "TS",
},
{
"node_key": "material_bind",
"title": "预选素材",
"step_name": "material_bind",
"description": "Bind style, composition, clothing, shoes, accessory, and temporary references.",
"node_type": "reference_binding",
"sort_order": 30,
"stage_code": "SC",
},
{
"node_key": "headshot",
"title": "头像",
"step_name": "headshot",
"description": "Face, hair, eyes, expression, and the primary identity anchor.",
"sort_order": 40,
"stage_code": "TX",
},
{
"node_key": "upper_body",
"title": "上半身像",
"step_name": "upper_body",
"description": "Upper-body costume, posture, silhouette, and identity continuity.",
"sort_order": 50,
"stage_code": "SS",
},
{
"node_key": "lower_body",
"title": "下半身像",
"step_name": "lower_body",
"description": "Waist, hips, legs, footwear, proportions, and lower-body details.",
"sort_order": 60,
"stage_code": "XS",
},
{
"node_key": "full_body",
"title": "全身像",
"step_name": "full_body",
"description": "Complete outfit, body proportions, footwear, and full silhouette.",
"sort_order": 70,
"stage_code": "QS",
},
{
"node_key": "turnaround",
"title": "三视图",
"step_name": "turnaround",
"description": "Front, side, and back views with consistent proportions and costume structure.",
"sort_order": 80,
"stage_code": "ST",
},
{
"node_key": "design_sheet",
"title": "设定图",
"step_name": "design_sheet",
"description": "Expressions, poses, hands, accessories, and reusable design callouts.",
"sort_order": 90,
"stage_code": "SD",
},
{
"node_key": "style_lock",
"title": "高清修复",
"step_name": "style_lock",
"description": "High-resolution restoration and final identity/style consistency pass.",
"sort_order": 100,
"stage_code": "XF",
},
{
"node_key": "profile_card",
"title": "建立档案卡",
"step_name": "profile_card",
"description": "Validate required assets, create an immutable profile card, and archive the workflow.",
"node_type": "archive",
"sort_order": 110,
"stage_code": "DA",
},
)
def canonical_gradual_node_key(node_key: str | None) -> str:
normalized = str(node_key or "").strip()
return LEGACY_CHARACTER_GRADUAL_NODE_KEYS.get(normalized, normalized)
def gradual_stage_code(node_key: str | None) -> str:
canonical = canonical_gradual_node_key(node_key)
for step in CHARACTER_GRADUAL_STEPS:
if step["node_key"] == canonical:
return str(step["stage_code"])
return "RD"
def gradual_node_templates() -> list[dict[str, Any]]:
return [
{
**{key: value for key, value in step.items() if key != "stage_code"},
"node_type": step.get("node_type", "generation"),
"status": "draft",
"branch_name": "main",
"metadata": {
"template": CHARACTER_GRADUAL_TEMPLATE_VERSION,
"canonical_node_key": step["node_key"],
"stage_code": step["stage_code"],
},
}
for step in CHARACTER_GRADUAL_STEPS
]