prompts.py 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. """Prompt builders for pet generation.
  2. Two prompt shapes: a *base* prompt (prompt-only, produces the canonical look the
  3. user picks between) and per-*state* *row* prompts (grounded on the chosen base,
  4. produce one horizontal strip of N poses). The identity lock and "one transparent
  5. row" framing matter more than flowery description. We generate the full
  6. petdex/Codex nine-state set (:data:`agent.pet.generate.atlas.ROW_SPECS`) so a
  7. hatched pet is a valid ``petdex submit`` spritesheet.
  8. """
  9. from __future__ import annotations
  10. # What each state depicts, phrased to avoid sprite-gen failure modes (detached
  11. # effects, motion lines, shadows). ``running`` = working in place; ``-right/-left`` = walk.
  12. STATE_ACTIONS: dict[str, str] = {
  13. "idle": "a calm idle loop: subtle breathing, a tiny blink or gentle bob, no big gestures",
  14. "running-right": (
  15. "a sideways walk/run locomotion cycle moving to the RIGHT: the character "
  16. "faces and travels right with clear directional steps, a smooth gait loop"
  17. ),
  18. "running-left": (
  19. "a sideways walk/run locomotion cycle moving to the LEFT: the character "
  20. "faces and travels left with clear directional steps (the mirror of the "
  21. "right-facing run)"
  22. ),
  23. "waving": "a friendly greeting: raising a paw/hand/limb to wave, clear up-and-down gesture",
  24. "jumping": "a happy celebration jump: anticipation, lift off the ground, peak, and land",
  25. "failed": "a sad or deflated reaction: slumped, dejected, small frown — readable but not noisy",
  26. "waiting": (
  27. "an expectant 'waiting on you' pose: looking up/out as if asking for input "
  28. "or approval — distinct from idle and review"
  29. ),
  30. "running": (
  31. "focused active work, staying IN PLACE (NOT walking or foot-running): "
  32. "leaning in, concentrating, busy 'thinking / processing / typing' energy"
  33. ),
  34. "review": "careful inspection: a focused lean, head tilt, studying something intently",
  35. }
  36. _STYLE_HINTS: dict[str, str] = {
  37. # Default to the popular petdex look: crisp 16-bit PIXEL ART, not the smooth
  38. # 2D illustration (let alone 3D render) gpt-image reaches for by default.
  39. "auto": (
  40. " Style: crisp 16-bit PIXEL-ART game sprite — visible square pixels, a small "
  41. "limited palette, clean dark outline, flat cel shading, chunky chibi "
  42. "proportions, like a classic SNES/JRPG party member or a petdex.dev mascot. "
  43. "Absolutely NOT 3D-rendered, NOT a smooth painted or vector illustration, "
  44. "NOT photorealistic — no soft gradients, no realistic lighting, no figurine look."
  45. ),
  46. "pixel": " Render in clean 16-bit pixel-art style with visible square pixels and a limited palette.",
  47. "plush": " Render as a soft plush toy.",
  48. "clay": " Render as a claymation / soft 3D clay figure.",
  49. "sticker": " Render as a glossy die-cut sticker.",
  50. "flat-vector": " Render in flat vector mascot style.",
  51. "3d-toy": " Render as a glossy 3D toy.",
  52. "painterly": " Render in a soft painterly style.",
  53. }
  54. _BACKGROUND = (
  55. "Center the character on a SINGLE flat, uniform, high-contrast chroma-key "
  56. "background — pure hot magenta #FF00FF (only if magenta appears on the "
  57. "character, use pure green #00FF00 instead). The background is ONE continuous "
  58. "even color that completely surrounds the character with NO gradient, "
  59. "vignette, texture, pattern, scenery, shadow, ground line, frame, border, "
  60. "panel, comic cell, gutter line, grid, or divider of any kind, so it keys out "
  61. "cleanly. The background color must not appear anywhere on the character. "
  62. "No text, no labels, no speech bubbles, no UI."
  63. )
  64. def style_hint(style: str | None) -> str:
  65. return _STYLE_HINTS.get((style or "auto").strip().lower(), "")
  66. _ASSUMED_STRIP_WIDTH = 1536 # landscape row canvas; used only to cite concrete pixel numbers
  67. def _spacing_spec(frame_count: int) -> tuple[int, int]:
  68. """(per-pose width px, gap px) for a row of *frame_count* poses.
  69. Pixel counts alone don't hold — the model fills each slot edge-to-edge. The lever
  70. that works is proportional containment: equal cells, whole silhouette inside,
  71. ~70% occupancy (still a generous gutter on 1536px, no shrinking).
  72. """
  73. slots = max(1, frame_count)
  74. slot_w = _ASSUMED_STRIP_WIDTH / slots
  75. return round(slot_w * 0.7), max(48, round(slot_w * 0.3))
  76. # Per-draft nudges so base options are distinct (gpt-image near-duplicates one
  77. # prompt). Vary the *look*, NOT the pose, so the base still grounds consistent rows.
  78. BASE_VARIATIONS: tuple[str, ...] = (
  79. "",
  80. "a distinctly different colour palette and markings",
  81. "a heavier, broader silhouette with sturdier proportions",
  82. "a different facial structure and expression matching the concept tone, with unique accent/accessory details",
  83. "a leaner, taller build and an alternate colour scheme",
  84. "bolder, more saturated colours and a stronger expression matching the concept tone",
  85. )
  86. def build_base_prompt(concept: str, *, style: str | None = "auto", variation: str = "") -> str:
  87. """The base look: a single, clean, centered full-body mascot; *variation* differentiates drafts."""
  88. concept = (concept or "a distinctive mascot creature").strip()
  89. nudge = f" Make this design distinct: {variation}." if variation else ""
  90. return (
  91. f"A stylized mascot pet character: {concept}. "
  92. "Honor the requested tone and mood exactly (cute, eerie, scary, menacing, whimsical, etc.) "
  93. "while staying non-graphic. "
  94. "Compact, whole-body silhouette that reads clearly at small size, "
  95. "clear readable facial features, simple consistent palette. "
  96. # A neutral, symmetric, at-rest stance makes the cleanest identity anchor
  97. "Neutral front-facing standing pose, upright and symmetric, arms/limbs "
  98. "relaxed at the sides, feet together on the ground, any cape/accessories "
  99. "hanging straight and still."
  100. f"{nudge} "
  101. f"{_BACKGROUND}{style_hint(style)}"
  102. )
  103. def build_row_prompt(state: str, frame_count: int, concept: str, *, style: str | None = "auto") -> str:
  104. """A row strip: *frame_count* poses of the SAME character, left→right, identity locked to the attached base image."""
  105. action = STATE_ACTIONS.get(state, "a simple idle pose")
  106. concept = (concept or "the mascot").strip()
  107. pose_px, gap_px = _spacing_spec(frame_count)
  108. return (
  109. f"Using the attached reference image as the exact same character "
  110. f"(same species, face, colors, markings, proportions, and props), "
  111. "preserving the same emotional tone/mood (e.g., scary stays scary, cute stays cute), "
  112. f"draw a single WIDE horizontal strip of {frame_count} animation frames showing {action}. "
  113. f"LAYOUT: arrange {frame_count} poses in ONE horizontal row at equal spacing, "
  114. "each pose centered in its own imaginary equal region. Draw NO panel borders, "
  115. "NO comic cells, NO boxes, NO vertical divider/gutter lines, NO grid, NO frame "
  116. "outlines between poses — the backdrop is one unbroken flat field behind all of them. "
  117. "Fill the WHOLE strip with the SAME single flat chroma-key color as the attached "
  118. "reference image's background (identical hue in every frame, no per-pose color shifts). "
  119. f"SPACING (critical): draw each pose at a consistent, healthy, clearly "
  120. f"visible size (roughly {pose_px}px wide on a {_ASSUMED_STRIP_WIDTH}px "
  121. f"strip) — do NOT shrink it tiny — but keep its ENTIRE silhouette "
  122. f"(wings, tail, halo, horns, cape, every appendage) fully INSIDE its own "
  123. f"cell. Leave at least {gap_px}px of empty chroma-key background between "
  124. f"neighboring silhouettes at their closest point (wingtip to wingtip), and "
  125. f"the same empty margin before the first pose and after the last. If a wing, "
  126. f"cape, or tail would reach into a neighbor, FOLD or angle it inward rather "
  127. f"than letting it cross the gap. Silhouettes must NEVER touch, overlap, "
  128. f"share a shadow, share a ground line, share motion trails, or merge into "
  129. f"one connected shape. "
  130. # Registration: a clean sprite sheet keeps the character locked in place
  131. # so only the action moves — this is what stops the loop sliding/pulsing.
  132. "REGISTRATION (critical): the character is the SAME height and SAME width "
  133. "in every frame, drawn at the SAME scale, centered over the SAME point, "
  134. "with all feet aligned to the SAME invisible horizontal baseline across the "
  135. "whole strip — this baseline is conceptual ONLY: draw NO ground line, floor, "
  136. "platform, horizon, or contact shadow beneath the feet. Keep the body's center, size, and stance fixed frame to "
  137. "frame — ONLY the limbs/features the action needs may move. Capes, cloaks, "
  138. "bags, and scarves stay in the SAME place and shape every frame (no "
  139. "swinging, flowing, or drifting) unless the action itself requires it. No "
  140. "pose is cropped at the strip edges. "
  141. f"{_BACKGROUND}{style_hint(style)}"
  142. )