62 lines
2.5 KiB
Python
62 lines
2.5 KiB
Python
"""
|
|
Preset prompts for different image analysis and prompt generation tasks.
|
|
"""
|
|
|
|
PROMPT_PRESETS = {
|
|
"prompt": (
|
|
"Analyze this image and write a detailed, high-quality prompt suitable for text-to-image "
|
|
"generation (such as Midjourney, Flux, or Stable Diffusion). Describe the subject in detail, "
|
|
"the artistic medium and style, composition, camera framing, lighting, color palette, "
|
|
"atmosphere, and background details. Output only the prompt without conversational intro or outro."
|
|
),
|
|
"flux": (
|
|
"Generate a highly descriptive prompt for Flux / Midjourney to recreate this exact image. "
|
|
"Break down the subject, pose, attire, facial expression, artistic style, camera lens/lighting setup, "
|
|
"depth of field, background elements, and overall mood. Output only the prompt description."
|
|
),
|
|
"detailed": (
|
|
"Provide a comprehensive, dense visual description of this image. Describe all visible elements "
|
|
"including subjects, positioning, background, textures, lighting, colors, and subtle details. "
|
|
"Organize the description clearly."
|
|
),
|
|
"short": (
|
|
"Write a concise, accurate single-sentence caption describing the main subject and action in this image."
|
|
),
|
|
"ocr": (
|
|
"Extract and transcribe all visible text, letters, numbers, signs, labels, watermarks, or logos from this image. "
|
|
"If there is no text, reply 'No text detected'."
|
|
),
|
|
"tags": (
|
|
"Analyze this image and generate a comma-separated list of descriptive keywords/tags. "
|
|
"Include subject, clothing, colors, setting, art style, mood, and camera angle. "
|
|
"Format: tag1, tag2, tag3, ..."
|
|
),
|
|
"story": (
|
|
"Write an imaginative, vivid short paragraph telling the story or setting the narrative mood behind this image."
|
|
),
|
|
}
|
|
|
|
DEFAULT_MODE = "prompt"
|
|
|
|
|
|
def get_prompt(mode: str, custom_prompt: str | None = None) -> str:
|
|
"""
|
|
Get prompt text according to mode or custom user prompt.
|
|
|
|
Args:
|
|
mode: Preset key from PROMPT_PRESETS or 'custom'
|
|
custom_prompt: Explicit custom prompt text (overrides preset if provided)
|
|
|
|
Returns:
|
|
The prompt string to pass to the Vision-Language model.
|
|
"""
|
|
if custom_prompt and custom_prompt.strip():
|
|
return custom_prompt.strip()
|
|
|
|
mode_lower = mode.lower().strip()
|
|
if mode_lower in PROMPT_PRESETS:
|
|
return PROMPT_PRESETS[mode_lower]
|
|
|
|
# Fallback to default
|
|
return PROMPT_PRESETS[DEFAULT_MODE]
|