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)
67 lines
2.7 KiB
Python
67 lines
2.7 KiB
Python
"""Mock 图像后端:Pillow 生成占位图。
|
|
|
|
无 OpenAI key 时也能端到端演示产品流水线(选品 → 底图 → "印花图" → "模特合成" 产物齐全)。
|
|
占位图 = 参考图尺寸 + 文字标注(提示词摘要),明确标识 [MOCK] 避免误用。
|
|
"""
|
|
from pathlib import Path
|
|
|
|
from PIL import Image, ImageDraw
|
|
|
|
from .base import ImageBackend
|
|
|
|
|
|
class MockImageBackend(ImageBackend):
|
|
name = "mock"
|
|
|
|
def __init__(self):
|
|
self._cfg: dict = {}
|
|
|
|
def bind_config(self, cfg: dict):
|
|
self._cfg = cfg or {}
|
|
|
|
def print(self, prompt: str, base_image: str, out_path: str, negative: str = "",
|
|
extra_images=None, size: str = "", seed: int = None) -> str:
|
|
size_px = (1024, 1024)
|
|
try:
|
|
with Image.open(base_image) as im:
|
|
size_px = im.size
|
|
except Exception:
|
|
pass
|
|
if size:
|
|
try:
|
|
w, h = (int(x) for x in str(size).lower().split("x"))
|
|
size_px = (w, h)
|
|
except Exception:
|
|
pass
|
|
img = Image.new("RGB", size_px, (240, 240, 248))
|
|
d = ImageDraw.Draw(img)
|
|
d.rectangle([0, 0, size_px[0] - 1, size_px[1] - 1], outline=(180, 180, 200))
|
|
d.text((24, 24), f"[MOCK] {Path(out_path).name}", fill=(50, 50, 80))
|
|
d.text((24, 56), "(未配置 OpenAI key,占位图演示流程)", fill=(120, 120, 150))
|
|
d.text((24, 96), (prompt or "")[:160], fill=(90, 90, 120))
|
|
if extra_images:
|
|
d.text((24, 136), f"参考图 {len(list(extra_images))} 张: " + ", ".join(Path(p).name[:24] for p in extra_images), fill=(90, 90, 120))
|
|
Path(out_path).parent.mkdir(parents=True, exist_ok=True)
|
|
img.save(out_path)
|
|
return out_path
|
|
|
|
def generate(self, prompt: str, out_path: str, negative: str = "", size: str = "",
|
|
seed: int = None) -> str:
|
|
"""纯文生图(mock):白底 + 文字标注,模拟纯印花设计稿。"""
|
|
size_px = (1024, 1024)
|
|
if size:
|
|
try:
|
|
w, h = (int(x) for x in str(size).lower().split("x"))
|
|
size_px = (w, h)
|
|
except Exception:
|
|
pass
|
|
img = Image.new("RGB", size_px, (252, 252, 252))
|
|
d = ImageDraw.Draw(img)
|
|
d.rectangle([0, 0, size_px[0] - 1, size_px[1] - 1], outline=(200, 200, 210))
|
|
d.text((24, 24), f"[MOCK DESIGN] {Path(out_path).name}", fill=(50, 50, 80))
|
|
d.text((24, 56), "(纯印花设计稿占位,白底)", fill=(120, 120, 150))
|
|
d.text((24, 96), (prompt or "")[:160], fill=(90, 90, 120))
|
|
Path(out_path).parent.mkdir(parents=True, exist_ok=True)
|
|
img.save(out_path)
|
|
return out_path
|