← back to Paul Conrad Cartoons Shadowman
generator/retry_briefs.py
55 lines
#!/usr/bin/env python3
"""Write a retry batch for briefs whose render failed the gag-adherence review (TK-12241).
python3 generator/retry_briefs.py <tag> <nnn,nnn,...> -> generator/out/batch-<tag>.json
Each retry keeps theme/era/caption but swaps in a SIMPLIFIED prompt that leads with the 1-2 key
objects of the gag (no era props / background clutter) and a new deterministic seed per tag.
"""
import json, random
b = json.load(open('generator/out/batch.json'))
STYLE = 'bold black ink editorial cartoon, heavy brush line, crosshatching, stark black and white, single panel satire'
SIMPLE_R1 = {
'001': 'one small white pill resting on a velvet cushion under a glass dome with a huge price tag, pharmacy counter',
'002': 'a frightened politician hiding under his office desk while a smiling lobbyist in a suit pats his head like a dog',
'003': 'a giant eraser the size of a man rubbing out the headline of a huge newspaper',
'004': 'a stern judge in black robes holding up a gavel shaped like a giant price tag',
'006': 'a politician raising his right hand to take an oath while his left hand reaches into a rich man\'s coat pocket',
'007': 'an empty speaker\'s podium on a bare stage with a single lit candle and a folded flag resting on it',
'010': 'a small schoolhouse sinking into quicksand next to a giant shiny sports stadium',
'012': 'an elephant and a donkey arm-wrestling on a table, a tiny ordinary man squashed flat under the table',
'014': 'a stone statue of Lady Justice holding scales, lifting the edge of her blindfold with one finger to peek',
'015': 'a ballot box built like a slot machine with a big lever, a politician in a suit pulling the lever',
'016': 'the White House drawn as a sinking ship in a stormy sea, men in suits bailing water out with teacups',
'017': 'a smiling politician kissing a baby on the cheek while his other hand lifts the wallet from the mother\'s purse',
'018': 'a gigantic rubber stamp crashing down on top of a small Capitol dome, cracking it',
'019': 'a politician tied up inside a giant twisted pretzel shaped like a map',
}
# r2: second retry for briefs whose r1 still failed. Avoids objects SDXL fills with fake lettering
# (headlines, price tags, slot-machine reels) and leads with one unmistakable action.
SIMPLE_R2 = {
'001': 'a single tiny pill displayed on a plush velvet pillow inside a jewelry store glass case, a jeweler peering at it through a loupe',
'003': 'a smug official using a huge eraser to rub people out of a large group photograph pinned to a wall',
'004': 'a judge in black robes at the courtroom bench acting as an auctioneer, rich men in the gallery holding up bags of money',
'006': 'a politician swearing an oath with one hand raised while a fat rich man behind him slips cash into his back pocket',
'007': 'an empty wooden podium alone on a dark stage with a single burning candle on top and a folded flag beside it',
'010': 'a tiny crumbling one-room schoolhouse dwarfed by a colossal gleaming football stadium right next to it',
'014': 'a statue of Lady Justice wearing a blindfold, pushing the blindfold up with one finger to peek at the viewer',
'015': 'a politician in a suit yanking the big lever on the side of a giant ballot box, coins spilling out of it',
'018': 'a gigantic wooden rubber stamp smashing down onto the dome of the Capitol building',
}
NEG_R2 = {'007': 'person, man, woman, speaker, crowd'}
import sys
tag = sys.argv[1]
SIMPLE = {'r1': SIMPLE_R1, 'r2': SIMPLE_R2}[tag]; rng = random.Random(tag)
todo = sys.argv[2].split(',')
items = []
for it in b['items']:
n = it['id'][-3:]
if n not in todo: continue
rec = {**it, 'id': f"{it['id']}-{tag}", 'retry_of': it['id'], 'prompt': f"{SIMPLE[n]}. {STYLE}", 'seed': rng.randrange(2**31)}
if tag == 'r2' and n in NEG_R2: rec['negative_extra'] = NEG_R2[n]
items.append(rec)
json.dump({'generated_at': b['generated_at'], 'retry': tag, 'items': items}, open(f'generator/out/batch-{tag}.json', 'w'), indent=2)
print(len(items), 'retry briefs ->', f'generator/out/batch-{tag}.json')