POD 趋势感知 Agent:缓存热点模式 + 三图合成 + 热点去重/风格去重 + review 兜底
- 缓存热点批量流程(有采集缓存不触发 Google) - 简报不足直接从采集缓存生成(轻量补齐) - 三图合成(模特/印花/底图)+ 底图压缩 <2MB - 热点去重→风格去重自动切换 + 不适合类目 review 兜底 - 透明背景(background=transparent)+ 提示词清洗(敏感词/背景描述) - 任务前 basemap 校验 + 模板国家校验 + 模特任务级分配
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
"""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 = "") -> 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 = "") -> 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
|
||||
Reference in New Issue
Block a user