feat: AI生图功能丰富
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
"""单张 AI 编辑提示词:一次图像模型调用完成编辑、翻译和排版。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from services.prompts.common import requirements_block, resolve_style
|
||||
|
||||
|
||||
LANGUAGES = {"ru": "Russian", "ar": "Arabic", "en": "English"}
|
||||
|
||||
BACKGROUNDS = {
|
||||
"auto": "Keep the original background unless the user's requirements ask to change it.",
|
||||
"white": "Replace only the background with clean pure white; retain natural contact shadows.",
|
||||
"solid": "Replace only the background with a clean solid color as described below.",
|
||||
"scene": "Replace only the background with the described realistic scene. Keep the product as the hero.",
|
||||
"reference": "Use Image 2 for background and lighting direction. Do not copy its product.",
|
||||
}
|
||||
|
||||
|
||||
def build_single_edit_prompt(
|
||||
*, requirements: str, config: dict, context: dict, style_set: int,
|
||||
style_prompt: str | None, ratio: str, is_size_chart: bool, reference_count: int,
|
||||
) -> str:
|
||||
"""Image 1 always supplies the product; following images are supporting references only."""
|
||||
language = LANGUAGES.get(config.get("target_language"), "Russian")
|
||||
background = config.get("background") or "auto"
|
||||
sections = [
|
||||
requirements_block(requirements),
|
||||
"Create exactly ONE finished e-commerce image. Image 1 is the fixed main product image. "
|
||||
"Preserve the product's shape, proportions, color, material, logo and distinguishing details. "
|
||||
"Do not replace it with products from any other image.",
|
||||
]
|
||||
if reference_count:
|
||||
sections.append(
|
||||
f"Images 2 through {reference_count + 1} are auxiliary references only. "
|
||||
"Use them for product detail, material, scene or lighting as appropriate; "
|
||||
"Image 1 remains the source of truth for the product."
|
||||
)
|
||||
sections.append("BACKGROUND: " + BACKGROUNDS.get(background, BACKGROUNDS["auto"]))
|
||||
if config.get("background_description"):
|
||||
sections.append("Background details: " + str(config["background_description"]).strip())
|
||||
if config.get("translate_text"):
|
||||
sections.append(
|
||||
f"In this same image-generation pass, read the visible marketing text in Image 1, "
|
||||
f"translate its meaning into {language}, replace the source-language marketing copy, "
|
||||
"and redesign the text layout for a polished, legible composition. "
|
||||
"For Arabic, use correct right-to-left typesetting. Keep factual values and units exact. "
|
||||
"Preserve text printed on the physical product and its branding unless the user explicitly asks to edit them. "
|
||||
"Do not add unsupported claims."
|
||||
)
|
||||
else:
|
||||
sections.append(
|
||||
"Do not invent marketing copy or translate existing image text. "
|
||||
"Preserve text printed on the physical product unless explicitly requested otherwise."
|
||||
)
|
||||
if is_size_chart:
|
||||
annotation = context.get("dimension_annotation_instruction")
|
||||
if annotation:
|
||||
sections.append(
|
||||
"Create a clean product measurement diagram with legible dimension arrows. "
|
||||
+ str(annotation)
|
||||
)
|
||||
style = resolve_style(style_set, style_prompt)
|
||||
sections.append("VISUAL STYLE: " + str(style["tone"]))
|
||||
sections.append(
|
||||
f"OUTPUT: exactly {ratio} portrait or square composition as specified. "
|
||||
"Apply the user's explicit background and text instructions before style preferences. "
|
||||
"Do not add a watermark or extra panels."
|
||||
)
|
||||
return "\n\n".join(part for part in sections if part)
|
||||
Reference in New Issue
Block a user