153 lines
7.6 KiB
Python
153 lines
7.6 KiB
Python
"""Reference-image prompt helper for reusable image references."""
|
||
|
||
from __future__ import annotations
|
||
|
||
|
||
REFERENCE_TYPES = ("Character", "Object", "Scene", "Creature", "Vehicle")
|
||
REFERENCE_IDS = tuple(str(index) for index in range(1, 10))
|
||
|
||
|
||
def reference_token(reference_id: str | int) -> str:
|
||
"""Return the Continuum reference token for a user-facing ID."""
|
||
|
||
try:
|
||
index = int(reference_id)
|
||
except (TypeError, ValueError) as exc:
|
||
raise ValueError("reference_id must be an integer from 1 to 9") from exc
|
||
if index < 1 or index > 9:
|
||
raise ValueError("reference_id must be an integer from 1 to 9")
|
||
return f"@R{index}"
|
||
|
||
|
||
_TEMPLATES = {
|
||
"Character": (
|
||
"Describe the character in exquisite detail. Include clothing, accessories, body type, proportions, and size. "
|
||
"The character will be referred to as {token} and should be treated as a photographic representation of a real person, so start the description with {token}. "
|
||
"Do not refer to individual shots; treat this as a visual description of the character. "
|
||
"Please provide a comprehensive, well-organized, and formatted description that includes:"
|
||
"Age: Exact or approximate age (e.g., 28, young adult, elderly, etc.),"
|
||
"Ethnicity: Specify ethnicity (e.g., Caucasian, African American, Asian, Hispanic, Indigenous, Middle Eastern, etc.) — include any distinguishing physical traits if relevant,"
|
||
"Body Type & Proportions: Overall build (e.g., athletic, slender, curvy, tall, short, petite, stocky), limb length, facial structure, torso shape, and general body symmetry,"
|
||
"Size Metrics (where applicable):"
|
||
"- Height (in cm or ft/inches),"
|
||
"- Bust, waist, hips (if visible or inferred)"
|
||
"- Arm span / leg length (if relevant),"
|
||
"- Head size / facial features (e.g., chin, jawline, nose, brow shape),"
|
||
"Body Part Details:"
|
||
"Head: Hair color, texture, style, facial hair (if any), skin tone, facial features,"
|
||
"Eyes: Color, shape, size, expression,"
|
||
"Nose: Shape, size, prominence,"
|
||
"Lips: Shape, color, fullness,"
|
||
"Ears: Size, shape, earlobe detail,"
|
||
"Skin: Tone, texture, blemishes, scars, freckles, or other markings,"
|
||
"Torso: Chest, shoulders, neck, back, spine curvature,"
|
||
"Arms: Forearm thickness, bicep size, shoulder width, hand size and shape,"
|
||
"Legs: Thigh, calf, knee, ankle, foot size and shape,"
|
||
"Buttocks: Shape, size, muscle definition,"
|
||
"Intimate Areas** (include all where applicable based on gender):"
|
||
"Tits: Size, shape, firmness, areola color, nipple visibility,"
|
||
"Pussy**: Size, shape, labia, vaginal opening, surrounding skin tone and texture,"
|
||
"Cock: Length, girth, shape, pubic hair, surrounding skin, base size"
|
||
"Clothing & Accessories:"
|
||
"Type, color, fabric, fit, style (e.g., tight, loose, formal, casual, athletic)"
|
||
"Visible patterns, logos, stitching"
|
||
"Footwear, jewelry, headwear, bags, gloves, belts, or other accessories"
|
||
"Posture & Expression**: Body orientation, stance, facial expression, gaze direction"
|
||
|
||
"Format your response as follows:"
|
||
"{token}: [Detailed description here]"
|
||
"Example:"
|
||
"Token: A 32-year-old African American woman, 5'7\", athletic build with slim legs and hourglass figure. "
|
||
"Wearing black high-waisted leggings and a cropped tank top revealing toned abs. Her skin is medium-toned with faint freckles across cheeks. "
|
||
"Eyes are almond-shaped and dark brown, lips full and pink. Hair is curly, shoulder-length, and dark brown. "
|
||
"Bust 34D, waist 26\", hips 38\". "
|
||
"Titted slightly forward, nipples visible through thin fabric. Pussy is small, labia majora small, natural pink skin tone. "
|
||
"Cock is medium-length, girth around 10cm, erect with pubic hair neatly trimmed. Standing in a studio with soft backlighting."
|
||
"Let’s begin with: "
|
||
"{token}:"
|
||
),
|
||
"Object": (
|
||
"Describe the object in the image in exquisite detail. Include its shape, "
|
||
"size, materials, colours, construction, surface detail, condition, and "
|
||
"distinctive features. The object will be referred to as {token}. Do not "
|
||
"refer to individual shots; treat this as a visual description of the object."
|
||
),
|
||
"Scene": (
|
||
"Describe the scene in the image in exquisite detail. Include the "
|
||
"environment, architecture, spatial layout, lighting, atmosphere, colours, "
|
||
"perspective, and important background elements. The scene will be referred "
|
||
"to as {token}. Do not refer to individual shots; treat this as a visual "
|
||
"description of the scene."
|
||
),
|
||
"Creature": (
|
||
"Describe the creature in the image in exquisite detail. Include its anatomy, "
|
||
"body structure, size, proportions, skin, fur, scales, colouring, distinctive "
|
||
"features, expression, and physical condition. The creature will be referred "
|
||
"to as {token}. Do not refer to individual shots; treat this as a visual "
|
||
"description of the creature."
|
||
),
|
||
"Vehicle": (
|
||
"Describe the vehicle in the image in exquisite detail. Include its type, "
|
||
"dimensions, shape, materials, colours, design, mechanical features, "
|
||
"condition, markings, and distinctive details. The vehicle will be referred "
|
||
"to as {token}. Do not refer to individual shots; treat this as a visual "
|
||
"description of the vehicle."
|
||
),
|
||
}
|
||
|
||
|
||
def build_reference_prompt(reference_type: str, reference_id: str | int, description: str = "") -> str:
|
||
"""Build the editable prompt shown by the node."""
|
||
|
||
if reference_type not in _TEMPLATES:
|
||
raise ValueError(f"reference_type must be one of: {', '.join(REFERENCE_TYPES)}")
|
||
token = reference_token(reference_id)
|
||
prompt = _TEMPLATES[reference_type].format(token=token)
|
||
extra = str(description or "").strip()
|
||
if extra:
|
||
prompt += f'\n\nAdditional information about the {reference_type.lower()}: "{extra}"'
|
||
return prompt
|
||
|
||
|
||
class DumasReferenceImagePreprocessor:
|
||
"""Keep an image unchanged and generate an editable reference prompt."""
|
||
|
||
CATEGORY = "Dumas/Reference"
|
||
DESCRIPTION = (
|
||
"Pass through a reference image and create an editable @R1–@R9 prompt "
|
||
"for a Character, Object, Scene, Creature, or Vehicle."
|
||
)
|
||
RETURN_TYPES = ("IMAGE", "STRING")
|
||
RETURN_NAMES = ("image", "reference_prompt")
|
||
FUNCTION = "process"
|
||
|
||
@classmethod
|
||
def INPUT_TYPES(cls):
|
||
return {
|
||
"required": {
|
||
"image": ("IMAGE",),
|
||
"reference_type": (list(REFERENCE_TYPES), {"default": "Character"}),
|
||
"reference_id": (list(REFERENCE_IDS), {"default": "1"}),
|
||
"description": ("STRING", {"default": "", "multiline": True}),
|
||
"generated_prompt": (
|
||
"STRING",
|
||
{
|
||
"default": build_reference_prompt("Character", "1"),
|
||
"multiline": True,
|
||
},
|
||
),
|
||
}
|
||
}
|
||
|
||
def process(self, image, reference_type, reference_id, description, generated_prompt):
|
||
prompt = str(generated_prompt or "").strip()
|
||
if not prompt:
|
||
prompt = build_reference_prompt(reference_type, reference_id, description)
|
||
return (image, prompt)
|
||
|
||
|
||
NODE_CLASS_MAPPINGS = {"DumasReferenceImagePreprocessor": DumasReferenceImagePreprocessor}
|
||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||
"DumasReferenceImagePreprocessor": "DUMAS Reference Image Preprocessor",
|
||
}
|