Chuyển đến nội dung chính

レッスン 7: ファッションのためのプロンプト エンジニアリング — プロンプトとデザインのバリエーションの最適化

ファッションデザイン用のプロンプトテンプレートシステムを構築します。 LLM による自動強化プロンプト。バイリンガルのサポート (EN/VI)。印刷品質のためのネガティブプロンプトの最適化。バリエーション生成戦略。

🧠 AI と ML — レッスン 6 レッスン 7: ファッションのための迅速なエンジニアリング — プロンプトとデザインのバリエーションを最適化

AI の活用: ファッションとプリント オン デマンド向けの AI プラットフォームの構築

パート 2: AI デザイン生成エンジン

xdev.asia

はじめに

プロンプトはユーザーと AI の間のインターフェイスです。良いプロンプトは優れたデザインを生み出しますが、悪いプロンプトはゴミを生み出します。この記事では、テンプレート、自動強化、ネガティブ最適化プロンプト、バイリンガル処理など、ファッションに特化した プロンプト エンジニアリング システム を構築します。


1. ファッションプロンプトの解剖学

T シャツ デザインの効果的なプロンプト構造

[Style] + [Subject] + [Details] + [Technical Quality] + [Print Spec]

Ví dụ:
"cyberpunk style, neon smiley face with sunglasses,
 glowing edges, holographic effect,
 high detail, vector art, clean lines,
 t-shirt design, transparent background, print-ready, 300 DPI"

プロンプトコンポーネント

PROMPT_COMPONENTS = {
    "styles": [
        "cyberpunk", "minimalist", "vintage retro", "gaming esports",
        "streetwear urban", "japanese typography", "graffiti art",
        "botanical nature", "abstract geometric", "pop art",
        "gothic dark", "kawaii cute", "vaporwave", "psychedelic",
    ],
    "techniques": [
        "vector art", "illustration", "watercolor", "line art",
        "pixel art", "3D render", "collage", "halftone",
        "screen print style", "embroidery style",
    ],
    "quality_boosters": [
        "high detail", "clean lines", "sharp edges",
        "professional quality", "studio quality",
        "crisp", "vibrant colors",
    ],
    "print_specs": [
        "t-shirt design", "isolated design element",
        "transparent background", "print-ready",
        "single color background", "centered composition",
    ],
}

2. 自動強化パイプライン

class PromptEnhancer:
    """Tự động nâng cấp user prompt cho fashion design"""

    def __init__(self):
        self.llm = openai.AsyncClient()

    async def enhance(self, user_prompt: str) -> EnhancedPrompt:
        # Step 1: Detect language
        lang = self._detect_language(user_prompt)

        # Step 2: Translate if Vietnamese
        if lang == "vi":
            user_prompt = await self._translate_vi_to_en(user_prompt)

        # Step 3: Analyze prompt completeness
        analysis = self._analyze_prompt(user_prompt)

        # Step 4: Enhance with missing components
        enhanced = await self._llm_enhance(user_prompt, analysis)

        # Step 5: Build negative prompt
        negative = self._build_negative_prompt(analysis)

        return EnhancedPrompt(
            original=user_prompt,
            enhanced=enhanced,
            negative=negative,
            detected_style=analysis.get("style"),
            detected_language=lang,
        )

    ENHANCE_SYSTEM_PROMPT = """
You are a fashion design prompt engineer for a t-shirt print-on-demand AI.

Given a user's design idea, create an optimized Stable Diffusion prompt.

Rules:
1. Keep the user's core concept intact
2. Add art style if missing (e.g., vector art, illustration)
3. Add "t-shirt design, isolated, transparent background, print-ready"
4. Add quality boosters: "high detail, clean lines, vibrant"
5. Maximum 77 tokens (CLIP limit)
6. Do NOT add: people, mannequins, mockups, backgrounds

Output only the enhanced prompt, nothing else.
"""

    FASHION_NEGATIVE_PROMPT = (
        "blurry, low quality, watermark, signature, text overlay, "
        "person wearing shirt, full body, mannequin, model, "
        "wrinkled fabric, photographic, photo, realistic background, "
        "busy background, multiple designs, border, frame, "
        "distorted, deformed, ugly, duplicate, morbid, "
        "low resolution, jpeg artifacts, out of frame"
    )

3. テンプレート システム

class PromptTemplateSystem:
    """Template-based prompt generation cho quick design"""

    TEMPLATES = {
        "meme": {
            "prompt": (
                "{subject}, meme style, bold text ready, "
                "humorous illustration, {color_scheme}, "
                "t-shirt design, transparent background"
            ),
            "negative_extra": "serious, realistic, photographic",
        },
        "gaming": {
            "prompt": (
                "{subject}, gaming esports style, "
                "glowing effects, neon lighting, {color_scheme}, "
                "dynamic composition, t-shirt design, "
                "transparent background"
            ),
            "negative_extra": "calm, peaceful, nature",
        },
        "minimal": {
            "prompt": (
                "{subject}, minimalist design, clean lines, "
                "simple composition, {color_scheme}, "
                "flat design, t-shirt design, transparent background"
            ),
            "negative_extra": "complex, detailed, busy, cluttered",
        },
        "streetwear": {
            "prompt": (
                "{subject}, streetwear urban style, bold graphics, "
                "{color_scheme}, grunge texture, "
                "t-shirt design, transparent background"
            ),
            "negative_extra": "elegant, formal, corporate",
        },
        "japanese": {
            "prompt": (
                "{subject}, Japanese aesthetic, kanji typography, "
                "{color_scheme}, ukiyo-e inspired, "
                "t-shirt design, transparent background"
            ),
            "negative_extra": "western, modern, corporate",
        },
    }

    def apply_template(
        self,
        template_name: str,
        subject: str,
        color_scheme: str = "vibrant colors",
    ) -> tuple[str, str]:
        template = self.TEMPLATES[template_name]
        prompt = template["prompt"].format(
            subject=subject,
            color_scheme=color_scheme,
        )
        negative = (
            PromptEnhancer.FASHION_NEGATIVE_PROMPT
            + ", " + template["negative_extra"]
        )
        return prompt, negative

4. バリエーション戦略

class VariationStrategy:
    """Tạo variations đa dạng từ 1 prompt"""

    def generate_diverse_variations(
        self, base_prompt: str, num_variations: int = 4
    ) -> list[dict]:
        strategies = [
            self._seed_variation,       # Cùng prompt, khác seed
            self._style_variation,      # Cùng subject, khác style
            self._color_variation,      # Cùng design, khác color
            self._composition_variation, # Cùng elements, khác layout
        ]

        variations = []
        for i in range(num_variations):
            strategy = strategies[i % len(strategies)]
            variation = strategy(base_prompt, i)
            variations.append(variation)

        return variations

    def _style_variation(
        self, prompt: str, index: int
    ) -> dict:
        """Thay đổi art style"""
        styles = [
            "vector art style",
            "watercolor illustration",
            "line art style",
            "screen print style",
        ]
        return {
            "prompt": f"{prompt}, {styles[index % len(styles)]}",
            "strategy": "style_variation",
        }

    def _color_variation(
        self, prompt: str, index: int
    ) -> dict:
        """Thay đổi color scheme"""
        schemes = [
            "vibrant neon colors",
            "monochrome black and white",
            "pastel soft colors",
            "earth tones warm colors",
        ]
        return {
            "prompt": f"{prompt}, {schemes[index % len(schemes)]}",
            "strategy": "color_variation",
        }

概要

ファッションのための迅速なエンジニアリングシステム:

  1. プロンプトの構造 — [スタイル] + [件名] + [詳細] + [品質] + [印刷] の構造
  2. 自動強化 — LLM はプロンプトを自動的にアップグレードし、ファッション固有のキーワードを追加します
  3. テンプレート システム — ミーム、ゲーム、ミニマル、ストリートウェア、日本語のテンプレート
  4. ネガティブプロンプト — 印刷品質を最適化し、不要な要素を削除します
  5. バリエーション戦略 — 種子、スタイル、色、組成のバリエーション

次の記事は パート 3: AI デザインの最適化と編集 から始まり、デザインをリアルに印刷できるようにします。