Files
3218485270 b7f429db89 模板导出增强 + 模特性别分组 + 三合一提示词精简
1) 模板导出:识别「基码表-胸围」填 sku.bust(多个胸围列都填);申报价格模糊匹配多列统一按加价后价格填写;详情图文不再拼接 img_url_2;SPU 款式来源统一填「现货款」;商品产地国家简称映射(沙特→沙特阿拉伯)
2) 模特性别分组:model_features 按男女分组,按模板类目含男/女固定取对应性别模特(含 Pinterest 模式 pipeline)
3) 三合一提示词:去掉 DESIGN CONTENT 四要素描述(设计已由设计稿提供)
4) 生图尺寸:全部改为读 config 不再硬编码(设计图 compose.design_size / 合成图 compose.size / 种草图 seed_shot.size)
2026-08-26 18:05:11 +08:00

144 lines
7.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""固定提示词模板(规则写死,保证每条一致)+ 装配函数。
所有最终提示词都由四要素(motif / art_style / color_palette / composition
用下面的模板确定性拼出,LLM 不再自由发挥,因此结构永远一致、可复用于 img2img。
v3:模板按国家区分(COUNTRY_TEMPLATES),每国有自己的设计风格引导段;
顶层 DEFAULT_TEMPLATES 作为兜底。文字规则统一:英文可加可不加、适配印花即可,
任何文字严禁政治/宗教/仇恨/暴力/性/品牌/商标/真实人物等敏感内容。
"""
from typing import Any, Dict, Optional
# —— 通用固定段(所有国家共用,保证结构一致)——
# 尺寸规则:印花必须「小且居中、四周大量留白」,禁止满幅/自带背景(防模型默认出满幅大图)
SIZE_RULE = (
"size: the print artwork must be SMALL and CENTERED with clearly larger white margins "
"around it, print area between about 15x18 cm and 26x32 cm, keep proportions, "
"scale naturally to the content, do NOT stretch, do NOT fill the entire canvas, "
"do NOT force full-bleed, leave wide balanced white margins around the artwork"
)
# 排除段:纯白底/无背景/无衣服/模特/场景/水印
NEG_FIXED = (
"isolated on pure white background, no background, no scene, no texture, no frame, no border, "
"no garment, no shirt, no model, no mannequin, no watermark"
)
# 文字规则(v3):可加可不加、适配印花即可;任何文字严禁敏感内容
# 注意:正向提示词不写敏感词(no politics/no hate/no violence/no sexual…会被图像审核误判),
# 负向约束统一由 negative_prompt 承担
TEXT_RULE = (
"text: optional - add short original English words or a small slogan ONLY if they fit "
"the print, or keep it text-free; any text must be safe, short and original; "
"no brand names, no logos, no trademarked phrases, no real people names"
)
# —— 国家风格引导段(每国不同:US 大胆高对比 / GB 英式自嘲与复古 / JP 卡哇伊极简 / AU 海滨户外)——
COUNTRY_STYLE_HINT: Dict[str, str] = {
"US": "US-market aesthetic: bold confident statement graphic, high contrast, "
"clean modern vector, sporty or humorous mood",
"GB": "UK-market aesthetic: witty understated British charm, heritage-inspired motifs, "
"retro sportswear or punk-zine mood",
"JP": "JP-market aesthetic: kawaii cute or clean minimal, soft pastel-friendly, "
"polished neat lines, small cute mascot mood",
"AU": "AU-market aesthetic: laid-back coastal and outdoor vibe, nature-inspired, "
"bright fresh energy",
"MX": "MX-market aesthetic: vibrant mexican folk art, sugar skull / loteria / aztec motifs, "
"fiesta colors, festive cultural pride mood",
}
def _image_prompt_for(country: str) -> str:
hint = COUNTRY_STYLE_HINT.get(country, COUNTRY_STYLE_HINT["US"])
return (
"{motif}, {art_style}, {color_palette}, {composition}, "
"standalone pure print design, print-ready artwork, "
"isolated on pure white background, flat vector-like graphic, "
"crisp clean edges, high resolution, ultra sharp, high contrast, "
f"{hint}, {SIZE_RULE}, "
f"{NEG_FIXED}, {TEXT_RULE}"
)
# 顶层默认(兜底:国家未配置时使用,内容等同 US 风格基线)
DEFAULT_TEMPLATES: Dict[str, str] = {
"image_prompt": _image_prompt_for("US"),
# 预览图:直接印在平铺白T上(无真人),用于快速看效果
"wearable_prompt": (
"{motif}, {art_style}, {color_palette}, {composition}, "
"printed centered on the chest of a flat-lay plain white t-shirt, "
"print sized freely between about 15x18 cm and a max of 26x32 cm, "
"scaled naturally to the artwork, not stretched, not full-bleed, "
"studio lighting, e-commerce product photo, no human model"
),
# 复合提示词(三图模特合成):图1=模特 / 图2=纯印花设计稿 / 图3=平铺底图 → 模特穿着成品
# 设计已由图2提供,不再附加 DESIGN CONTENT 四要素描述
"composite_prompt": (
"【图片角色,按提交顺序】图1=模特实拍图(基底);图2=纯印花设计稿;"
"图3=平铺衣服底图(颜色/面料来源)。\n"
"TASK: 把图2的印花设计印到图3底色的衣服上,并让图1的模特穿上"
"“图3底色+图2印花”的衣服。\n"
"RULES:\n"
"1.底色锁定:从图3提取衣服底色与面料,最终合成中必须100%保持不变,严禁偏色。\n"
"2.印花提取:从图2精准提取纯印花图案(线条/色号/比例),叠加到图3底色上形成合成面料。\n"
"3.主体遮罩:识别图1模特服装穿着区域(忽略皮肤/头发/背景/配饰),"
"用合成面料完整覆盖,清除原衣服颜色与图案。\n"
"4.精准贴合:合成面料严格跟随图1衣服立体结构,褶皱/扭转处印花相应变形,"
"杜绝“贴纸感”与“平面涂色感”。\n"
"5.光影融合:按图1环境光方向调整亮度/对比度,印花受光影响产生明暗变化但色号不偏移。\n"
"6.纯净输出:仅输出一张最终合成图;图1背景/人物/构图/光影100%不变,"
"仅替换衣服印花与底色。"
),
# 复合负向(印图专用)
"composite_negative": (
"garment changed, wrong color, distorted print, blurry, low-res, "
"human model, body, extra objects, watermark, glow, 3d render, "
"text unless part of design"
),
}
# —— 按国家覆盖:目前仅 image_prompt 有国家差异化;wearable/composite 共用顶层默认 ——
COUNTRY_TEMPLATES: Dict[str, Dict[str, str]] = {
cc: {"image_prompt": _image_prompt_for(cc)} for cc in COUNTRY_STYLE_HINT
}
def resolve_templates(tpls: Optional[Dict[str, Any]], country: Optional[str] = None) -> Dict[str, str]:
"""解析最终模板:DEFAULT_TEMPLATES 兜底 → config 顶层覆盖 → config countries.<country> 覆盖。
config 结构示例:
prompt_templates:
image_prompt: "..." # 顶层默认
countries:
GB:
image_prompt: "..." # 国家专属
"""
t = dict(DEFAULT_TEMPLATES)
if tpls:
t.update({k: v for k, v in tpls.items() if k in DEFAULT_TEMPLATES})
countries = tpls.get("countries") or {}
if country and isinstance(countries, dict):
cc_tpls = countries.get(country) or {}
if isinstance(cc_tpls, dict):
t.update({k: v for k, v in cc_tpls.items() if k in DEFAULT_TEMPLATES})
elif country and country in COUNTRY_TEMPLATES:
t.update(COUNTRY_TEMPLATES[country])
return t
def assemble_prompts(
motif: str,
art_style: str,
palette: str,
composition: str,
tpls: Optional[Dict[str, Any]] = None,
country: Optional[str] = None,
) -> Dict[str, str]:
"""用固定模板确定性装配三种提示词。tpls 可来自 config 覆盖(按国家优先)。"""
t = resolve_templates(tpls, country)
out = {}
for key in ("image_prompt", "wearable_prompt", "composite_prompt"):
out[key] = t[key].format(
motif=motif, art_style=art_style, color_palette=palette, composition=composition
)
out["composite_negative"] = t["composite_negative"]
return out