Files
Dolon (Agent) c48868a6e4
BetterLeaks / scan (push) Successful in 55s
Add tier-independent Teasing A-E renderer
Handles singles, doubles, and double-twins automatically.
Auto-discovers NPCs from Dressed folder.
Skips NPCs that already have Teasing images.

Usage:
  python3 scripts/render_teasing_ae.py --tier Wealthy --workers 25
2026-03-26 13:04:42 +00:00

239 lines
9.7 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Tier-independent Teasing A-E renderer.
Usage: python3 render_teasing_ae.py --tier Wealthy [--workers 25]
"""
import argparse, base64, json, subprocess, os
from pathlib import Path
from concurrent.futures import ThreadPoolExecutor, as_completed
import requests
NEGATIVE_TEXT = "no text, no labels, no captions, no logos, no watermark, no signage, no letters, no symbols, no UI overlays"
ANTI_MODERN = (
"Strict medieval Norse look: no bathrobes, no knit sweaters/cardigans, no modern trousers/pants, "
"no lace-up modern boots, no tufted upholstery, no modern cushions/pillows, no folded towels, "
"no modern plumbing/fixtures, no contemporary fabrics or cuts."
)
POSE_VARIANTS = {
'A': 'standing relaxed, hands at sides',
'B': 'seated on a cushioned bench, relaxed posture',
'C': 'leaning lightly against a carved post, one hand on the bodice',
'D': 'walking slowly with a small step, fabric swaying',
'E': 'adjusting the neckline with one hand',
}
def load_identities(manifest_dir):
identity_map = {}
for p in sorted([p for p in manifest_dir.glob('*.json') if 'payloads' not in p.name],
key=lambda p: p.stat().st_mtime, reverse=True):
try:
data = json.load(p.open())
for npc in data.get('individuals', []):
n = npc.get('name')
if n and n not in identity_map:
identity_map[n] = npc
for pair in data.get('pairs', []):
for npc in pair.get('npcs', []):
n = npc.get('name')
if n and n not in identity_map:
identity_map[n] = npc
for n, npc in data.get('npc_profiles', {}).items():
if n not in identity_map:
identity_map[n] = npc
except Exception:
continue
return identity_map
def data_url(path: Path):
return "data:image/jpeg;base64," + base64.b64encode(path.read_bytes()).decode()
def extract_eye(identity: str):
for part in identity.split(';'):
if 'eye' in part.lower():
return part.strip()
return None
def build_prompt_single(name, identity, tag, tier):
eye = extract_eye(identity) or 'eyes'
pose = POSE_VARIANTS[tag]
return f"""
Single adult, character name reference: {name}.
Identity: {identity}.
Eye color: {eye}. Eye color must match the reference exactly.
Use ONLY the provided reference image as the exact outfit source.
Keep the same garment, colors, fabrics, patterns, and accessory placement; pattern placement must match the reference.
Garments remain intact with no tears, rips, holes, fraying, or cuts.
Teasing stage: garment loosened, shoulder off; exactly one nipple visible and unobstructed; remaining nipple covered by garment; no nudity below the waist.
Pose: {pose}.
Same setting as reference image, consistent architecture and lighting.
Keep the same face/likeness as the reference; preserve facial marks exactly; no airbrushing.
Smiling warmly with playful, inviting expression and direct eye contact.
Cinematic 16:9, photorealistic, warm intimate lighting.
No facial scars or injuries.
{ANTI_MODERN}
{NEGATIVE_TEXT}
""".strip()
def build_prompt_pair(names, identities, tag, twin, tier):
name1, name2 = names
id1, id2 = identities
pose = POSE_VARIANTS[tag]
if twin:
twin_clause = "They are identical twins with the same face, same features, same marks."
id_clause = f"Identity for both: {id1}."
else:
twin_clause = "They have distinct faces and clearly different facial features."
id_clause = f"Identity {name1}: {id1}. Identity {name2}: {id2}."
return f"""
Two adult women, character name references: {name1} and {name2}.
{twin_clause}
{id_clause}
Use ONLY the provided reference image as the exact outfit source.
Keep the same garment, colors, fabrics, patterns, and accessory placement; pattern placement must match the reference.
Garments remain intact with no tears, rips, holes, fraying, or cuts.
Teasing stage: garments loosened, shoulder off on each; exactly one or two nipples visible and unobstructed with anatomically correct lateral placement; remaining nipples covered by garment; no nudity below the waist.
Pose: {pose}.
Same setting as reference image, consistent architecture and lighting.
Keep the same face/likeness as the reference; preserve facial marks exactly; no airbrushing.
Smiling warmly with inviting expression and direct eye contact.
Cinematic 16:9, photorealistic, warm intimate lighting.
No facial scars or injuries.
{ANTI_MODERN}
{NEGATIVE_TEXT}
""".strip()
def render_job(ref_path, name_info, tag, runhex, identity_map, tier, out_dir, api_url, headers):
npc_type, base_name, is_twin = name_info
out_file = f"{base_name}_Teasing_{tag}__{runhex}.jpg"
out_path = out_dir / out_file
if out_path.exists():
return {"status": "skip"}
if npc_type == "single":
name_display = base_name.replace('_', ' ')
npc_data = identity_map.get(base_name, {})
identity = npc_data.get('identity', '')
prompt = build_prompt_single(name_display, identity, tag, tier)
else: # pair
parts = base_name.replace('DoubleTwin_', '').replace('Double_', '').split('_')
name1 = f"{parts[0]} {parts[1]}"
name2 = f"{parts[2]} {parts[3]}"
id1 = identity_map.get(f"{parts[0]}_{parts[1]}", {}).get('identity', '')
id2 = identity_map.get(f"{parts[2]}_{parts[3]}", {}).get('identity', '')
prompt = build_prompt_pair((name1, name2), (id1, id2), tag, is_twin, tier)
payload = {
"model": "grok-imagine-image",
"prompt": prompt,
"image": {"url": data_url(ref_path)},
"aspect_ratio": "16:9",
}
try:
r = requests.post(api_url, headers=headers, data=json.dumps(payload), timeout=90)
if r.status_code == 200:
url = r.json()["data"][0]["url"]
subprocess.run(["curl", "-sS", "-L", url, "-o", str(out_path)], check=True, timeout=60)
return {"status": "success"}
else:
return {"status": "failed", "error": f"HTTP {r.status_code}"}
except Exception as e:
return {"status": "exception", "error": str(e)}
def main():
parser = argparse.ArgumentParser(description='Render Teasing A-E for a courtesan tier')
parser.add_argument('--tier', required=True)
parser.add_argument('--workers', type=int, default=25)
parser.add_argument('--output-base', default='/home/rick/output/to-dnd-session-rclone/Grok-NPCs/Courtesans')
parser.add_argument('--skip-tier-subfolder', action='store_true')
args = parser.parse_args()
tier_dir = Path(args.output_base) if args.skip_tier_subfolder else Path(args.output_base) / args.tier
dressed_dir = tier_dir / 'Dressed'
out_dir = tier_dir / 'Teasing'
out_dir.mkdir(parents=True, exist_ok=True)
# Load identities
identity_map = load_identities(Path('/home/rick/.openclaw/workspace/memory/npc-run-manifests'))
# Get API key
key = subprocess.check_output(['bash', '-lc', 'pass show x.ai/apikey | head -n1']).decode().strip()
headers = {"Authorization": f"Bearer {key}", "Content-Type": "application/json"}
api_url = "https://api.x.ai/v1/images/edits"
runhex = os.urandom(4).hex()
print(f"{'='*60}")
print(f"{args.tier} Teasing A-E (runhex={runhex})")
print(f"{'='*60}\n")
# Build job list from Dressed keepers
jobs = []
# Singles
for p in dressed_dir.glob('*_Dressed__*.jpg'):
if p.name.startswith(('Double_', 'DoubleTwin_', 'Triple_')):
continue
base = p.stem.split('_Dressed__')[0]
# Skip if Teasing already exists
if list(out_dir.glob(f"{base}_Teasing_*__*.jpg")):
continue
jobs.extend([(p, ("single", base, False), tag, runhex, identity_map, args.tier, out_dir, api_url, headers)
for tag in ['A','B','C','D','E']])
# Doubles
for p in dressed_dir.glob('Double_*__*.jpg'):
base = p.stem.split('__')[0]
if list(out_dir.glob(f"{base}_*_Teasing_*__*.jpg")):
continue
jobs.extend([(p, ("pair", base, False), tag, runhex, identity_map, args.tier, out_dir, api_url, headers)
for tag in ['A','B','C','D','E']])
# DoubleTwins
for p in dressed_dir.glob('DoubleTwin_*__*.jpg'):
base = p.stem.split('__')[0]
if list(out_dir.glob(f"{base}_*_Teasing_*__*.jpg")):
continue
jobs.extend([(p, ("pair", base, True), tag, runhex, identity_map, args.tier, out_dir, api_url, headers)
for tag in ['A','B','C','D','E']])
# Triples
for p in dressed_dir.glob('Triple_*__*.jpg'):
base = p.stem.split('__')[0]
if list(out_dir.glob(f"{base}_*_Teasing_*__*.jpg")):
continue
# Triples need special handling - skip for now or add triple prompt builder
pass
print(f"Total jobs: {len(jobs)}\n")
success, failed, skip = 0, 0, 0
with ThreadPoolExecutor(max_workers=args.workers) as ex:
futures = {ex.submit(render_job, *j): j for j in jobs}
for future in as_completed(futures):
result = future.result()
if result["status"] == "success":
success += 1
if success % 20 == 0:
print(f"Progress: {success}/{len(jobs)}")
elif result["status"] == "skip":
skip += 1
else:
failed += 1
if failed <= 5:
print(f"FAIL: {result.get('error', '?')[:100]}")
print(f"\n{'='*60}")
print(f"DONE: ok={success} fail={failed} skip={skip}")
print(f"{'='*60}")
if __name__ == "__main__":
main()