Add render_courtesans_doublepairs_fullynaked.py — pairs+singles baseline
BetterLeaks / scan (push) Successful in 52s
BetterLeaks / scan (push) Successful in 52s
This script renders both pair and individual courtesan images using the original FullyNaked recipe: - Pair renders: up to 3 successful scenes per pair - Individual renders: 2 scenes per NPC, drawn from successful pair settings - Used for Fidelity test [3] baseline to measure text-only face consistency vs current recipe.
This commit is contained in:
@@ -0,0 +1,924 @@
|
||||
#!/usr/bin/env python3
|
||||
import datetime as dt
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from collections import defaultdict
|
||||
from typing import Dict, List, Tuple
|
||||
|
||||
API_URL = "https://api.x.ai/v1/images/generations"
|
||||
MODEL = "grok-imagine-image-pro"
|
||||
ASPECT = "16:9"
|
||||
MAX_ATTEMPTS = 4
|
||||
|
||||
BASE_OUT = pathlib.Path("/home/rick/output/to-dnd-session/Grok-NPCs/Courtesans")
|
||||
MANIFEST_DIR = pathlib.Path("/home/rick/.openclaw/workspace/memory/npc-run-manifests")
|
||||
|
||||
V4_CLAUSE = (
|
||||
"brief partial glimpse near pubic region with pubic-hair edge (matching head-hair color), "
|
||||
"no direct whole-genitals view, total nudity clearly implied"
|
||||
)
|
||||
V1_CLAUSE = (
|
||||
"visible edge of pubic hair (matching head-hair color), "
|
||||
"no directly visible genitals, strongly implied total nudity without seeing genitals directly"
|
||||
)
|
||||
|
||||
NEGATIVE_TEXT = (
|
||||
"no text, no labels, no captions, no logos, no watermark, no signage, no letters, "
|
||||
"no symbols, no UI overlays"
|
||||
)
|
||||
|
||||
|
||||
def utc_now_iso() -> str:
|
||||
return dt.datetime.now(dt.timezone.utc).isoformat()
|
||||
|
||||
|
||||
def shell_capture(cmd: str) -> str:
|
||||
p = subprocess.run(["bash", "-lc", cmd], capture_output=True, text=True)
|
||||
if p.returncode != 0:
|
||||
raise RuntimeError(f"Command failed ({p.returncode}): {cmd}\n{p.stderr.strip()}")
|
||||
return p.stdout.strip()
|
||||
|
||||
|
||||
def safe_slug(s: str, max_len: int = 40) -> str:
|
||||
tok = re.sub(r"[^A-Za-z0-9_-]+", "", s)
|
||||
return tok[:max_len] if tok else "setting"
|
||||
|
||||
|
||||
def safe_name(s: str) -> str:
|
||||
return re.sub(r"\s+", "_", s.strip())
|
||||
|
||||
|
||||
def is_transient(msg: str) -> bool:
|
||||
m = (msg or "").lower()
|
||||
needles = [
|
||||
"temporarily unavailable",
|
||||
"try again",
|
||||
"timeout",
|
||||
"timed out",
|
||||
"rate limit",
|
||||
"too many requests",
|
||||
"internal server error",
|
||||
"bad gateway",
|
||||
"service unavailable",
|
||||
"gateway",
|
||||
"connection",
|
||||
"503",
|
||||
"502",
|
||||
"429",
|
||||
]
|
||||
return any(n in m for n in needles)
|
||||
|
||||
|
||||
def curl_json_with_code(api_key: str, payload: Dict) -> Tuple[int, Dict, str]:
|
||||
cmd = [
|
||||
"curl",
|
||||
"-sS",
|
||||
"-H",
|
||||
"Content-Type: application/json",
|
||||
"-H",
|
||||
f"Authorization: Bearer {api_key}",
|
||||
"-d",
|
||||
json.dumps(payload, ensure_ascii=False),
|
||||
"-w",
|
||||
"\nHTTP_CODE:%{http_code}",
|
||||
API_URL,
|
||||
]
|
||||
p = subprocess.run(cmd, capture_output=True, text=True)
|
||||
if p.returncode != 0:
|
||||
raise RuntimeError(f"generation curl failed rc={p.returncode}: {p.stderr.strip()}")
|
||||
raw = (p.stdout or "").strip()
|
||||
if "HTTP_CODE:" not in raw:
|
||||
raise RuntimeError(f"missing HTTP_CODE in response: {raw[:200]}")
|
||||
body, code_str = raw.rsplit("HTTP_CODE:", 1)
|
||||
try:
|
||||
http_code = int(code_str.strip())
|
||||
except Exception:
|
||||
http_code = 0
|
||||
body = body.strip()
|
||||
data: Dict = {}
|
||||
if body:
|
||||
try:
|
||||
data = json.loads(body)
|
||||
except Exception:
|
||||
data = {"_raw": body}
|
||||
return http_code, data, body
|
||||
|
||||
|
||||
def curl_download(url: str, out_path: pathlib.Path) -> None:
|
||||
out_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
tmp_path = out_path.with_suffix(out_path.suffix + ".part")
|
||||
cmd = ["curl", "-sS", "-L", url, "-o", str(tmp_path)]
|
||||
p = subprocess.run(cmd, capture_output=True, text=True)
|
||||
if p.returncode != 0:
|
||||
raise RuntimeError(f"download curl failed rc={p.returncode}: {p.stderr.strip()}")
|
||||
if not tmp_path.exists() or tmp_path.stat().st_size < 1024:
|
||||
size = tmp_path.stat().st_size if tmp_path.exists() else 0
|
||||
raise RuntimeError(f"downloaded file too small ({size} bytes)")
|
||||
tmp_path.replace(out_path)
|
||||
|
||||
|
||||
def error_snippet_from(data: Dict, raw: str) -> str:
|
||||
if isinstance(data, dict):
|
||||
if data.get("error"):
|
||||
err = data.get("error")
|
||||
if isinstance(err, dict):
|
||||
msg = err.get("message") or err.get("error") or str(err)
|
||||
else:
|
||||
msg = str(err)
|
||||
return msg[:240]
|
||||
return (raw or "")[:240]
|
||||
|
||||
|
||||
def is_moderation_reject(http_code: int, data: Dict, raw: str) -> bool:
|
||||
text = ""
|
||||
if isinstance(data, dict):
|
||||
if data.get("error"):
|
||||
err = data.get("error")
|
||||
if isinstance(err, dict):
|
||||
text = (err.get("message") or err.get("error") or "").lower()
|
||||
else:
|
||||
text = str(err).lower()
|
||||
if "moderation" in text or "content moderation" in text:
|
||||
return True
|
||||
if raw and "content moderation" in raw.lower():
|
||||
return True
|
||||
if http_code == 400 and "moderation" in (raw or "").lower():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
TIER_SETTINGS: Dict[str, List[Dict]] = {
|
||||
"Modest": [
|
||||
{"slug": "bathhouse", "desc": "simple timber bathhouse with warm steam, wooden benches, clean towels, modest rustic comfort"},
|
||||
{"slug": "furs", "desc": "rustic fur-covered pallet near a hearth, soft firelight, wool throws"},
|
||||
{"slug": "bedroom", "desc": "small private bedroom with linen sheets, wooden bedframe, oil-lamp glow"},
|
||||
{"slug": "sauna", "desc": "cedar sauna with plank benches and gentle steam"},
|
||||
{"slug": "washroom", "desc": "quiet washroom with a wooden tub and a single oil lamp"},
|
||||
{"slug": "loftnook", "desc": "loft nook with straw mattress, wool blankets, and lantern light"},
|
||||
{"slug": "hearthcorner", "desc": "hearthside alcove with wool throws and soft firelight"},
|
||||
],
|
||||
"Comfortable": [
|
||||
{"slug": "bathhouse", "desc": "cozy bathhouse with carved benches, copper basins, and warm steam"},
|
||||
{"slug": "furs", "desc": "soft furs on a low platform by the fire, warm hearth glow"},
|
||||
{"slug": "bedchamber", "desc": "private bedchamber with quilted linens and a carved headboard"},
|
||||
{"slug": "lanternlounge", "desc": "lantern-lit lounge with cushions, woven rugs, and intimate calm"},
|
||||
{"slug": "tub", "desc": "warm washroom with a copper tub, gentle steam, and candlelight"},
|
||||
{"slug": "alcove", "desc": "quiet alcove with wool throws, low table, and soft lanterns"},
|
||||
{"slug": "sauna", "desc": "stone-heated sauna room with cedar benches and mist"},
|
||||
],
|
||||
"Wealthy": [
|
||||
{"slug": "marblebath", "desc": "polished bathhouse with tiled pool, brass fixtures, and soft steam"},
|
||||
{"slug": "plushfurs", "desc": "plush furs on a raised daybed with velvet pillows"},
|
||||
{"slug": "canopybed", "desc": "private bedchamber with a canopy bed, linen drapes, and warm light"},
|
||||
{"slug": "silksalon", "desc": "lantern-lit salon with silk cushions, carved screens, and quiet luxury"},
|
||||
{"slug": "brasstub", "desc": "copper soaking tub with brass taps and gentle steam"},
|
||||
{"slug": "gildedlounge", "desc": "gilded lounge with velvet pillows, furs, and warm firelight"},
|
||||
{"slug": "balcony", "desc": "private balcony lounge with sheer curtains, furs, and lantern glow"},
|
||||
],
|
||||
"Elite": [
|
||||
{"slug": "marblebath", "desc": "marble bathhouse with mist, carved columns, and soft candlelight"},
|
||||
{"slug": "velvetdivan", "desc": "velvet-covered divan beside rich tapestries and carved wood"},
|
||||
{"slug": "opulentbed", "desc": "opulent bedchamber with a carved canopy bed and silk linens"},
|
||||
{"slug": "candlelounge", "desc": "candlelit lounge with layered furs and elaborate tapestries"},
|
||||
{"slug": "goldtub", "desc": "gold-rimmed soaking tub with steam, lanterns, and polished stone"},
|
||||
{"slug": "silkscreen", "desc": "private chamber with silk screens, plush cushions, and warm light"},
|
||||
{"slug": "firealcove", "desc": "firelit alcove with plush furs and carved wood"},
|
||||
],
|
||||
"Elite XL": [
|
||||
{"slug": "mosaicspa", "desc": "grand spa suite with mosaic pool, carved stone, and drifting steam"},
|
||||
{"slug": "silkfurs", "desc": "silken furs on a raised dais with velvet pillows"},
|
||||
{"slug": "royalbed", "desc": "royal bedchamber with a tall canopy, silk curtains, and warm glow"},
|
||||
{"slug": "lanterngallery", "desc": "lantern-lit gallery lounge with carved screens and soft cushions"},
|
||||
{"slug": "gildedbath", "desc": "gilded bath alcove with crystal decanters and mist"},
|
||||
{"slug": "wintergarden", "desc": "velveted winter-garden lounge with greenery, furs, and firelight"},
|
||||
{"slug": "moonlit", "desc": "private moonlit lounge with sheer drapes and plush cushions"},
|
||||
],
|
||||
"Elite XXL": [
|
||||
{"slug": "palatialbath", "desc": "palatial bath hall with marble pool, gold inlay, and drifting steam"},
|
||||
{"slug": "luxfurpavilion", "desc": "luxury fur pavilion with velvet canopies and rich textures"},
|
||||
{"slug": "imperialbed", "desc": "imperial bedchamber with a massive canopy bed and silk"},
|
||||
{"slug": "chandeliersalon", "desc": "chandelier-lit salon with velvet couches, furs, and gilded decor"},
|
||||
{"slug": "goldterrace", "desc": "gold-inlaid bath terrace with warm mist and lanterns"},
|
||||
{"slug": "skyboxlounge", "desc": "private skybox lounge with silk drapes and plush cushions"},
|
||||
{"slug": "crystalgrotto", "desc": "crystal-lit grotto lounge with warm mist and soft light"},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
PAIRS: List[Dict] = [
|
||||
# Modest
|
||||
{
|
||||
"pair_id": "ModestP1",
|
||||
"tier": "Modest",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Asta Redbrook",
|
||||
"age": 22,
|
||||
"identity": "long flax-blonde braid; ice-blue eyes; fair rosy skin; oval face with high cheekbones; faint freckles across the nose bridge",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Inga Pinewick",
|
||||
"age": 23,
|
||||
"identity": "dark honey-brown hair in a low braid; storm-gray eyes; light freckled skin; round face with soft cheeks; tiny scar near the right eyebrow",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pair_id": "ModestP2",
|
||||
"tier": "Modest",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Sigrun Foxmere",
|
||||
"age": 21,
|
||||
"identity": "auburn wavy hair tied back; green-hazel eyes; fair warm skin; heart-shaped face with a defined chin; small beauty mark near the left lip",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Elin Hollowfern",
|
||||
"age": 24,
|
||||
"identity": "straight black hair with a side braid; deep brown eyes; cool pale skin; long face with a straight jawline; faint scar at the chin",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pair_id": "ModestP3",
|
||||
"tier": "Modest",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Runa Mistvale",
|
||||
"age": 20,
|
||||
"identity": "strawberry-blonde hair in loose braids; sea-green eyes; light rosy skin; diamond-shaped face with sharp cheek lines; dimple on the left cheek",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Tova Bearcliff",
|
||||
"age": 25,
|
||||
"identity": "short chestnut curls; amber-brown eyes; fair skin with warm undertone; square jaw with broad cheekbones; thin pale mark near the hairline",
|
||||
},
|
||||
},
|
||||
# Comfortable
|
||||
{
|
||||
"pair_id": "ComfortableP1",
|
||||
"tier": "Comfortable",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Liv Hartsong",
|
||||
"age": 22,
|
||||
"identity": "long ash-blonde hair in twin braids; steel-blue eyes; fair cool skin; rectangular face with a blunt chin; small mole below the right eye",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Freya Oakstrand",
|
||||
"age": 24,
|
||||
"identity": "golden-brown hair in a braided bun; gray-green eyes; light sun-kissed skin; oval face with soft cheekbones; faint laugh lines at the eye corners",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pair_id": "ComfortableP2",
|
||||
"tier": "Comfortable",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Kara Dawnridge",
|
||||
"age": 21,
|
||||
"identity": "copper-red hair over one shoulder; ice-gray eyes; pale skin with freckles; heart-shaped face; tiny scar at the jaw corner",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Nora Elmwhisper",
|
||||
"age": 23,
|
||||
"identity": "dark auburn hair half-up; hazel-green eyes; warm beige skin; rounded face with sculpted cheekbones; small beauty mark near the right cheek",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pair_id": "ComfortableP3",
|
||||
"tier": "Comfortable",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Eira Snowfield",
|
||||
"age": 20,
|
||||
"identity": "platinum-blonde loose braid; blue-gray eyes; fair porcelain skin; narrow face with a tapered jaw; soft freckles across one cheek",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Milla Stonepetal",
|
||||
"age": 25,
|
||||
"identity": "deep brown hair in a low knot; smoky-gray eyes; light olive skin; softly triangular face with defined cheeks; subtle scar at the chin",
|
||||
},
|
||||
},
|
||||
# Wealthy
|
||||
{
|
||||
"pair_id": "WealthyP1",
|
||||
"tier": "Wealthy",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Solveig Goldleaf",
|
||||
"age": 23,
|
||||
"identity": "silvery-blonde hair in a braided crown; green-gold eyes; fair luminous skin; oval face; tiny beauty mark above the upper lip",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Ylva Brightwater",
|
||||
"age": 22,
|
||||
"identity": "long wheat-blonde hair with a side braid; sea-blue eyes; light rosy skin; wide face with a strong jaw corner; thin pale mark near the hairline",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pair_id": "WealthyP2",
|
||||
"tier": "Wealthy",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Thyra Roseglen",
|
||||
"age": 24,
|
||||
"identity": "warm chestnut waves pinned back; dark hazel eyes; soft peach skin; diamond-shaped face; faint scar through the left eyebrow",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Dagny Seabloom",
|
||||
"age": 21,
|
||||
"identity": "black hair in twin braids; olive-hazel eyes; light olive skin; rectangular face with a blunt chin; small mole below the left eye",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pair_id": "WealthyP3",
|
||||
"tier": "Wealthy",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Ingrid Amberfell",
|
||||
"age": 25,
|
||||
"identity": "honey-blonde hair in a braided ponytail; slate-blue eyes; fair skin with sun-kissed cheeks; heart-shaped face; slight dimple in the right cheek",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Signy Silverpool",
|
||||
"age": 20,
|
||||
"identity": "dark brown hair in a loose braid; amber-brown eyes; cool fair skin; long face with a straight jawline; small scar under the lower lip",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pair_id": "WealthyT1",
|
||||
"tier": "Wealthy",
|
||||
"is_twins": True,
|
||||
"npc1": {
|
||||
"name": "Helga Sunspire",
|
||||
"age": 22,
|
||||
"identity": "long golden-blonde hair in a thick braid; ice-blue eyes; fair rosy skin; oval face with high cheekbones; tiny beauty mark near the right cheek",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Hilda Sunspire",
|
||||
"age": 22,
|
||||
"identity": "long golden-blonde hair in a thick braid; ice-blue eyes; fair rosy skin; oval face with high cheekbones; tiny beauty mark near the right cheek",
|
||||
},
|
||||
},
|
||||
# Elite
|
||||
{
|
||||
"pair_id": "EliteP1",
|
||||
"tier": "Elite",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Brynhild Starweave",
|
||||
"age": 24,
|
||||
"identity": "raven-black hair in a braided updo; storm-gray eyes; cool fair skin; angular face with a pronounced brow ridge; faint nick at the right eyebrow",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Gudrun Moonbraid",
|
||||
"age": 23,
|
||||
"identity": "silver-blonde hair in a rope braid; sea-green eyes; light porcelain skin; softly triangular face with defined cheeks; small scar at the jaw corner",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pair_id": "EliteP2",
|
||||
"tier": "Elite",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Svala Ironlily",
|
||||
"age": 25,
|
||||
"identity": "dark copper hair in a braided coil; smoky-gray eyes; fair skin with warm undertone; square jaw with broad cheekbones; tiny mole below the left eye",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Alva Nightbloom",
|
||||
"age": 21,
|
||||
"identity": "deep brown hair with one side braid; green-hazel eyes; light olive skin; diamond-shaped face; faint freckles across the nose",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pair_id": "EliteP3",
|
||||
"tier": "Elite",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Kirsten Velvettear",
|
||||
"age": 22,
|
||||
"identity": "black-brown hair in a sleek low braid; steel-blue eyes; cool pale skin; rectangular face; thin pale mark near the temple",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Idunn Stormlace",
|
||||
"age": 20,
|
||||
"identity": "auburn hair in a braided bun; amber-brown eyes; warm fair skin; heart-shaped face; small dimple in the left cheek",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pair_id": "EliteT1",
|
||||
"tier": "Elite",
|
||||
"is_twins": True,
|
||||
"npc1": {
|
||||
"name": "Freydis Highfrost",
|
||||
"age": 23,
|
||||
"identity": "platinum-blonde hair in twin braids; ice-blue eyes; fair luminous skin; oval face with high cheekbones; faint beauty mark near the left lip",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Frida Highfrost",
|
||||
"age": 23,
|
||||
"identity": "platinum-blonde hair in twin braids; ice-blue eyes; fair luminous skin; oval face with high cheekbones; faint beauty mark near the left lip",
|
||||
},
|
||||
},
|
||||
# Elite XL
|
||||
{
|
||||
"pair_id": "EliteXLP1",
|
||||
"tier": "Elite XL",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Astrid Dawnspire",
|
||||
"age": 24,
|
||||
"identity": "long silver-blonde braid; storm-gray eyes; cool fair skin; oval face with sculpted cheekbones; small scar near the right temple",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Linnea Frostgild",
|
||||
"age": 21,
|
||||
"identity": "dark ash-brown hair in a braided crown; green-gold eyes; light olive skin; narrow face with a tapered jaw; soft freckles across the cheeks",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pair_id": "EliteXLP2",
|
||||
"tier": "Elite XL",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Eydis Ivoryglade",
|
||||
"age": 25,
|
||||
"identity": "raven-black hair with braided fringe; deep brown eyes; porcelain skin; angular face with a pronounced brow ridge; faint scar at the chin",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Katla Silkshore",
|
||||
"age": 22,
|
||||
"identity": "copper-red hair in a loose braid; hazel-green eyes; warm fair skin; heart-shaped face; tiny mole below the right eye",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pair_id": "EliteXLP3",
|
||||
"tier": "Elite XL",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Ragnhild Pearlweir",
|
||||
"age": 23,
|
||||
"identity": "wheat-blonde hair in a low knot; slate-blue eyes; fair skin with rosy cheeks; rectangular face; small beauty mark near the left cheek",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Sif Cloudglen",
|
||||
"age": 20,
|
||||
"identity": "dark chestnut hair in twin braids; smoky-gray eyes; light olive skin; rounded face with sculpted cheekbones; faint scar through the left eyebrow",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pair_id": "EliteXLT1",
|
||||
"tier": "Elite XL",
|
||||
"is_twins": True,
|
||||
"npc1": {
|
||||
"name": "Yrsa Glimmershade",
|
||||
"age": 24,
|
||||
"identity": "long golden-brown hair in a thick braid; sea-green eyes; warm fair skin; oval face with high cheekbones; tiny beauty mark above the upper lip",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Yngvild Glimmershade",
|
||||
"age": 24,
|
||||
"identity": "long golden-brown hair in a thick braid; sea-green eyes; warm fair skin; oval face with high cheekbones; tiny beauty mark above the upper lip",
|
||||
},
|
||||
},
|
||||
# Elite XXL
|
||||
{
|
||||
"pair_id": "EliteXXLP1",
|
||||
"tier": "Elite XXL",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Elvira Goldcrest",
|
||||
"age": 25,
|
||||
"identity": "silvery-ash hair in a braided updo; ice-blue eyes; cool fair skin; diamond-shaped face; small scar at the jaw corner",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Adalind Crownmere",
|
||||
"age": 23,
|
||||
"identity": "deep black hair in a sleek braid; dark hazel eyes; light olive skin; long face with a straight jawline; faint freckles across one cheek",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pair_id": "EliteXXLP2",
|
||||
"tier": "Elite XXL",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Brenna Silverquill",
|
||||
"age": 22,
|
||||
"identity": "auburn hair in a braided ponytail; amber-brown eyes; warm fair skin; square jaw with broad cheekbones; small dimple in the right cheek",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Celina Jadeveil",
|
||||
"age": 21,
|
||||
"identity": "platinum-blonde hair in a braided bun; steel-blue eyes; fair porcelain skin; heart-shaped face; tiny mole below the left eye",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pair_id": "EliteXXLP3",
|
||||
"tier": "Elite XXL",
|
||||
"is_twins": False,
|
||||
"npc1": {
|
||||
"name": "Jorunn Velvetcove",
|
||||
"age": 24,
|
||||
"identity": "dark brown hair in a low braided knot; olive-hazel eyes; light olive skin; rectangular face; thin pale mark near the hairline",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Lovisa Opalshade",
|
||||
"age": 20,
|
||||
"identity": "golden-blonde hair with a side braid; sea-blue eyes; fair rosy skin; oval face with soft cheekbones; faint laugh lines at the eye corners",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pair_id": "EliteXXLT1",
|
||||
"tier": "Elite XXL",
|
||||
"is_twins": True,
|
||||
"npc1": {
|
||||
"name": "Isolde Starcrown",
|
||||
"age": 23,
|
||||
"identity": "long white-blonde hair in twin braids; ice-blue eyes; cool fair skin; oval face with high cheekbones; tiny beauty mark near the right cheek",
|
||||
},
|
||||
"npc2": {
|
||||
"name": "Jovita Starcrown",
|
||||
"age": 23,
|
||||
"identity": "long white-blonde hair in twin braids; ice-blue eyes; cool fair skin; oval face with high cheekbones; tiny beauty mark near the right cheek",
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def build_pair_prompt(pair: Dict, setting_desc: str, variant_clause: str) -> str:
|
||||
n1 = pair["npc1"]["name"]
|
||||
n2 = pair["npc2"]["name"]
|
||||
a1 = pair["npc1"]["age"]
|
||||
a2 = pair["npc2"]["age"]
|
||||
id1 = pair["npc1"]["identity"]
|
||||
id2 = pair["npc2"]["identity"]
|
||||
if pair["is_twins"]:
|
||||
face_line = "They are identical twins with the same facial features, hair, and markings."
|
||||
else:
|
||||
face_line = "They have distinct faces and clearly different facial features."
|
||||
|
||||
prompt = f"""
|
||||
Two clearly adult women (ages {a1} and {a2}) in a cozy, intimate medieval Norse setting: {setting_desc}.
|
||||
|
||||
Woman A ({n1}): {id1}.
|
||||
Woman B ({n2}): {id2}.
|
||||
{face_line}
|
||||
|
||||
Both women are fully nude, visible and unobstructed nipples, {variant_clause}.
|
||||
No sexual acts, no porn framing, no arousal-focused posing.
|
||||
Full-body, head-to-toe composition showing both women; no waist-cropping; no clothing or drapery.
|
||||
Photorealistic, cinematic lighting, 16:9.
|
||||
{NEGATIVE_TEXT}.
|
||||
""".strip()
|
||||
return prompt
|
||||
|
||||
|
||||
def build_individual_prompt(npc: Dict, setting_desc: str, variant_clause: str) -> str:
|
||||
name = npc["name"]
|
||||
age = npc["age"]
|
||||
identity = npc["identity"]
|
||||
|
||||
prompt = f"""
|
||||
{name}, a clearly adult {age}-year-old woman, in a cozy, intimate medieval Norse setting: {setting_desc}.
|
||||
Identity: {identity}.
|
||||
|
||||
Fully nude, visible and unobstructed nipples, {variant_clause}.
|
||||
No sexual acts, no porn framing, no arousal-focused posing.
|
||||
Full-body, head-to-toe composition; no waist-cropping; no clothing or drapery.
|
||||
Photorealistic, cinematic lighting, 16:9.
|
||||
{NEGATIVE_TEXT}.
|
||||
""".strip()
|
||||
return prompt
|
||||
|
||||
|
||||
def render_with_workflow(
|
||||
api_key: str,
|
||||
prompt_builder,
|
||||
out_path: pathlib.Path,
|
||||
) -> Dict:
|
||||
attempts = []
|
||||
final_status = "failed"
|
||||
final_error = ""
|
||||
final_http_code = 0
|
||||
output_path = None
|
||||
|
||||
for attempt in range(1, MAX_ATTEMPTS + 1):
|
||||
variant = "V4" if attempt <= 2 else "V1"
|
||||
clause = V4_CLAUSE if variant == "V4" else V1_CLAUSE
|
||||
prompt = prompt_builder(clause)
|
||||
|
||||
payload = {
|
||||
"model": MODEL,
|
||||
"prompt": prompt,
|
||||
"aspect_ratio": ASPECT,
|
||||
}
|
||||
|
||||
http_code = 0
|
||||
status = "failed"
|
||||
err_snip = ""
|
||||
try:
|
||||
http_code, data, raw = curl_json_with_code(api_key, payload)
|
||||
final_http_code = http_code
|
||||
|
||||
if isinstance(data, dict) and data.get("error"):
|
||||
err_snip = error_snippet_from(data, raw)
|
||||
if is_moderation_reject(http_code, data, raw):
|
||||
status = "moderation_rejected"
|
||||
else:
|
||||
status = "failed"
|
||||
raise RuntimeError(err_snip)
|
||||
|
||||
data_list = data.get("data") if isinstance(data, dict) else None
|
||||
if not data_list or not isinstance(data_list, list) or not data_list[0].get("url"):
|
||||
err_snip = error_snippet_from(data, raw)
|
||||
status = "failed"
|
||||
raise RuntimeError(f"missing image URL: {err_snip}")
|
||||
|
||||
image_url = data_list[0]["url"]
|
||||
curl_download(image_url, out_path)
|
||||
output_path = str(out_path)
|
||||
status = "success"
|
||||
final_status = "success"
|
||||
final_error = ""
|
||||
attempts.append(
|
||||
{
|
||||
"attempt": attempt,
|
||||
"variant": variant,
|
||||
"http_code": http_code,
|
||||
"status": status,
|
||||
"error_snippet": err_snip,
|
||||
"output_path": output_path,
|
||||
}
|
||||
)
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
err_text = str(e)
|
||||
if not err_snip:
|
||||
err_snip = err_text[:240]
|
||||
if status == "failed" and is_moderation_reject(http_code, {}, err_snip):
|
||||
status = "moderation_rejected"
|
||||
attempts.append(
|
||||
{
|
||||
"attempt": attempt,
|
||||
"variant": variant,
|
||||
"http_code": http_code,
|
||||
"status": status,
|
||||
"error_snippet": err_snip,
|
||||
"output_path": str(out_path),
|
||||
}
|
||||
)
|
||||
final_status = status
|
||||
final_error = err_snip
|
||||
|
||||
if attempt >= MAX_ATTEMPTS:
|
||||
break
|
||||
|
||||
if is_transient(err_snip) or "missing image url" in err_snip.lower() or "invalid json" in err_snip.lower() or "download" in err_snip.lower() or "api_error" in err_snip.lower():
|
||||
time.sleep(min(10, 2 * attempt))
|
||||
continue
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
return {
|
||||
"status": final_status,
|
||||
"error": final_error,
|
||||
"http_code": final_http_code,
|
||||
"attempts": attempts,
|
||||
"output_path": output_path,
|
||||
}
|
||||
|
||||
|
||||
def save_manifest(path: pathlib.Path, data: Dict) -> None:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
BASE_OUT.mkdir(parents=True, exist_ok=True)
|
||||
MANIFEST_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
timestamp_file = dt.datetime.now(dt.timezone.utc).strftime("%Y%m%d-%H%M%S")
|
||||
runhex = os.urandom(4).hex()
|
||||
manifest_path = MANIFEST_DIR / f"courtesans-doublepairs-fullynaked-{timestamp_file}.json"
|
||||
|
||||
try:
|
||||
api_key = shell_capture("pass show x.ai/apikey | head -n1")
|
||||
except Exception as e:
|
||||
print(f"FATAL: unable to load API key: {e}")
|
||||
return 2
|
||||
|
||||
if not api_key:
|
||||
print("FATAL: empty API key")
|
||||
return 2
|
||||
|
||||
total_pairs = len(PAIRS)
|
||||
total_pair_images_target = total_pairs * 3
|
||||
total_individual_images_target = total_pairs * 2
|
||||
|
||||
manifest: Dict = {
|
||||
"run_label": "Courtesans Doublepairs FullyNaked",
|
||||
"created_at": utc_now_iso(),
|
||||
"model": MODEL,
|
||||
"endpoint": API_URL,
|
||||
"aspect_ratio": ASPECT,
|
||||
"runhex": runhex,
|
||||
"output_root": str(BASE_OUT),
|
||||
"total_pairs": total_pairs,
|
||||
"pair_image_target": total_pair_images_target,
|
||||
"individual_image_target": total_individual_images_target,
|
||||
"pairs": [],
|
||||
"pair_settings": {},
|
||||
"individual_assignments": {},
|
||||
"images": [],
|
||||
"summary": {
|
||||
"pair_images_success": 0,
|
||||
"pair_images_failed": 0,
|
||||
"individual_images_success": 0,
|
||||
"individual_images_failed": 0,
|
||||
"moderation_rejects": 0,
|
||||
"intent_failures": 0,
|
||||
"pairs_completed": 0,
|
||||
},
|
||||
"intent_review": "unreviewed",
|
||||
}
|
||||
save_manifest(manifest_path, manifest)
|
||||
|
||||
print(f"RUN_START pairs={total_pairs} runhex={runhex}")
|
||||
print(f"MANIFEST {manifest_path}")
|
||||
sys.stdout.flush()
|
||||
|
||||
# Build pair list
|
||||
for p in PAIRS:
|
||||
manifest["pairs"].append(
|
||||
{
|
||||
"pair_id": p["pair_id"],
|
||||
"tier": p["tier"],
|
||||
"is_twins": p["is_twins"],
|
||||
"npcs": [
|
||||
{
|
||||
"name": p["npc1"]["name"],
|
||||
"age": p["npc1"]["age"],
|
||||
"identity": p["npc1"]["identity"],
|
||||
},
|
||||
{
|
||||
"name": p["npc2"]["name"],
|
||||
"age": p["npc2"]["age"],
|
||||
"identity": p["npc2"]["identity"],
|
||||
},
|
||||
],
|
||||
}
|
||||
)
|
||||
save_manifest(manifest_path, manifest)
|
||||
|
||||
# Pair processing
|
||||
per_tier_index = defaultdict(int)
|
||||
|
||||
for pair_idx, pair in enumerate(PAIRS, start=1):
|
||||
tier = pair["tier"]
|
||||
tier_settings = TIER_SETTINGS[tier]
|
||||
tier_dir = BASE_OUT / tier / "FullyNaked"
|
||||
tier_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
idx_in_tier = per_tier_index[tier]
|
||||
per_tier_index[tier] += 1
|
||||
|
||||
# rotate settings pool by index for variety
|
||||
start = (idx_in_tier * 3) % len(tier_settings)
|
||||
settings_pool = tier_settings[start:] + tier_settings[:start]
|
||||
|
||||
successful_settings: List[Dict] = []
|
||||
attempted_settings: List[Dict] = []
|
||||
|
||||
print(f"PAIR_START {pair_idx}/{total_pairs} {pair['pair_id']} tier={tier}")
|
||||
sys.stdout.flush()
|
||||
|
||||
for setting in settings_pool:
|
||||
if len(successful_settings) >= 3:
|
||||
break
|
||||
|
||||
setting_slug = safe_slug(setting["slug"])
|
||||
out_file = f"Double_{pair['pair_id']}_{setting_slug}__{runhex}.jpg"
|
||||
out_path = tier_dir / out_file
|
||||
|
||||
prompt_builder = lambda clause, _p=pair, _s=setting["desc"]: build_pair_prompt(_p, _s, clause)
|
||||
|
||||
result = render_with_workflow(api_key, prompt_builder, out_path)
|
||||
|
||||
image_entry = {
|
||||
"type": "pair",
|
||||
"pair_id": pair["pair_id"],
|
||||
"tier": tier,
|
||||
"npcs": [pair["npc1"]["name"], pair["npc2"]["name"]],
|
||||
"setting": {"slug": setting_slug, "desc": setting["desc"]},
|
||||
"status": result["status"],
|
||||
"intent_status": "unreviewed",
|
||||
"attempts": result["attempts"],
|
||||
"output_path": result["output_path"],
|
||||
"error": result["error"],
|
||||
"updated_at": utc_now_iso(),
|
||||
}
|
||||
manifest["images"].append(image_entry)
|
||||
|
||||
if result["status"] == "success":
|
||||
successful_settings.append(setting)
|
||||
manifest["summary"]["pair_images_success"] += 1
|
||||
else:
|
||||
manifest["summary"]["pair_images_failed"] += 1
|
||||
# track moderation rejects
|
||||
if any(a.get("status") == "moderation_rejected" for a in result["attempts"]):
|
||||
manifest["summary"]["moderation_rejects"] += 1
|
||||
|
||||
attempted_settings.append(setting)
|
||||
save_manifest(manifest_path, manifest)
|
||||
|
||||
# record established settings
|
||||
manifest["pair_settings"][pair["pair_id"]] = [
|
||||
{"slug": safe_slug(s["slug"]), "desc": s["desc"]} for s in successful_settings
|
||||
]
|
||||
|
||||
# Assign individual settings
|
||||
if len(successful_settings) >= 2:
|
||||
npc1_setting = successful_settings[0]
|
||||
npc2_setting = successful_settings[1]
|
||||
elif len(successful_settings) == 1:
|
||||
npc1_setting = successful_settings[0]
|
||||
npc2_setting = successful_settings[0]
|
||||
else:
|
||||
# fallback to first attempted setting if none succeeded
|
||||
npc1_setting = attempted_settings[0] if attempted_settings else tier_settings[0]
|
||||
npc2_setting = npc1_setting
|
||||
|
||||
# Render individual images
|
||||
for npc, indiv_setting in [(pair["npc1"], npc1_setting), (pair["npc2"], npc2_setting)]:
|
||||
npc_name_token = safe_name(npc["name"])
|
||||
out_file = f"{npc_name_token}_Courtesan_{tier}_FullyNaked__{runhex}.jpg"
|
||||
out_path = tier_dir / out_file
|
||||
|
||||
prompt_builder = lambda clause, _n=npc, _s=indiv_setting["desc"]: build_individual_prompt(_n, _s, clause)
|
||||
result = render_with_workflow(api_key, prompt_builder, out_path)
|
||||
|
||||
image_entry = {
|
||||
"type": "individual",
|
||||
"pair_id": pair["pair_id"],
|
||||
"tier": tier,
|
||||
"npc": npc["name"],
|
||||
"setting": {"slug": safe_slug(indiv_setting["slug"]), "desc": indiv_setting["desc"]},
|
||||
"status": result["status"],
|
||||
"intent_status": "unreviewed",
|
||||
"attempts": result["attempts"],
|
||||
"output_path": result["output_path"],
|
||||
"error": result["error"],
|
||||
"updated_at": utc_now_iso(),
|
||||
}
|
||||
manifest["images"].append(image_entry)
|
||||
|
||||
if result["status"] == "success":
|
||||
manifest["summary"]["individual_images_success"] += 1
|
||||
else:
|
||||
manifest["summary"]["individual_images_failed"] += 1
|
||||
if any(a.get("status") == "moderation_rejected" for a in result["attempts"]):
|
||||
manifest["summary"]["moderation_rejects"] += 1
|
||||
|
||||
manifest["individual_assignments"][npc["name"]] = {
|
||||
"pair_id": pair["pair_id"],
|
||||
"setting_slug": safe_slug(indiv_setting["slug"]),
|
||||
"setting_desc": indiv_setting["desc"],
|
||||
}
|
||||
|
||||
save_manifest(manifest_path, manifest)
|
||||
|
||||
manifest["summary"]["pairs_completed"] += 1
|
||||
save_manifest(manifest_path, manifest)
|
||||
|
||||
print(
|
||||
f"PAIR_DONE {pair_idx}/{total_pairs} {pair['pair_id']} "
|
||||
f"pair_ok={manifest['summary']['pair_images_success']} "
|
||||
f"pair_fail={manifest['summary']['pair_images_failed']} "
|
||||
f"ind_ok={manifest['summary']['individual_images_success']} "
|
||||
f"ind_fail={manifest['summary']['individual_images_failed']}"
|
||||
)
|
||||
sys.stdout.flush()
|
||||
|
||||
manifest["completed_at"] = utc_now_iso()
|
||||
manifest["status"] = "success" if (manifest["summary"]["pair_images_failed"] + manifest["summary"]["individual_images_failed"]) == 0 else "partial_failure"
|
||||
save_manifest(manifest_path, manifest)
|
||||
|
||||
print(
|
||||
f"RUN_DONE status={manifest['status']} pair_ok={manifest['summary']['pair_images_success']} "
|
||||
f"pair_fail={manifest['summary']['pair_images_failed']} ind_ok={manifest['summary']['individual_images_success']} "
|
||||
f"ind_fail={manifest['summary']['individual_images_failed']} total_pairs={total_pairs}"
|
||||
)
|
||||
print(f"MANIFEST {manifest_path}")
|
||||
sys.stdout.flush()
|
||||
|
||||
return 0 if manifest["status"] == "success" else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user