"""240 additional adult identities with ten expressions, plus 100 special subjects.""" from collections import Counter import json import random from pathlib import Path from plan_character_production import (AGES, EMOTIONS, ETHNICITIES, HAIR_M, HAIR_F, seed, outfit, description, prompt, write) from vivarium_prompt_templates import CHARACTER_STYLE ROOT = Path(__file__).resolve().parents[1] STATE = ROOT / 'experiments/character-extension' # Four visibly different variants in every class. All humanoids are adults. # Creature palettes deliberately avoid green/teal so chroma keying retains them. SPECIALS = [ ('vampire', 'humanoid', [ 'an adult male classic Dracula-like vampire aristocrat, pale ivory skin, slick black hair, a black cape over a burgundy Victorian suit', 'an adult female gothic vampire, pale ivory skin, dark braided hair, a fully covering plum Victorian gown and black boots', 'an adult male contemporary vampire, pale warm skin, short ash hair, a charcoal urban coat over a navy shirt and trousers', 'an adult female contemporary vampire, pale olive skin, short black hair, a burgundy leather jacket and full-length charcoal trousers']), ('zombie', 'humanoid', [ 'an adult male non-graphic office zombie, ashen gray intact skin, rumpled brown hair, a charcoal business suit', 'an elderly female non-graphic zombie, intact pale gray skin, silver hair, a lavender cardigan and long navy skirt', 'an adult male non-graphic space-worker zombie, intact slate gray skin, a fully closed ochre protective work suit', 'an adult female non-graphic medieval farmer zombie, intact ivory gray skin, a brown tunic and full-length rust trousers']), ('western_dragon', 'quadruped', [ 'a compact ruby-red dragon, four legs, folded leathery wings, a curled tail and copper horns', 'a compact cobalt-blue dragon, four legs, folded wings, a coiled tail and silver horns', 'a compact gold dragon, four legs, folded cream wings, a curled tail and ivory horns', 'a compact silver-white dragon, four legs, folded blue-gray wings, a coiled tail and dark horns']), ('serpentine_dragon', 'serpentine', [ 'an amethyst serpentine Eastern dragon, a long body coiled vertically, four small clawed legs and ivory whiskers', 'an ivory serpentine Eastern dragon, a long body coiled vertically, four small clawed legs and a copper mane', 'a silver-blue serpentine Eastern dragon, a long body coiled vertically, four small clawed legs and white whiskers', 'a copper serpentine Eastern dragon, a long body coiled vertically, four small clawed legs and a dark red mane']), ('witch', 'humanoid', [ 'an elderly female woodland witch, silver hair, a pointed brown hat, a fully covering ochre dress and boots', 'an adult female contemporary witch, dark curly hair, a plum coat over a navy dress and opaque leggings', 'an adult male village witch, curly brown hair, a broad burgundy hat, a cream shirt and brown layered robes', 'an adult male lunar witch, silver hair, a pointed navy hat and fully covering midnight-blue robes']), ('wizard', 'humanoid', [ 'an elderly male wizard, a long silver beard, a tall indigo hat and fully covering navy embroidered robes', 'an adult female scholar wizard, gray braided hair, round glasses and fully covering burgundy academic robes', 'an adult male cosmic sorcerer, short black hair and fully covering violet robes with subtle gold stitching', 'an adult female travelling mage, short copper hair, a cream hooded cloak over full-length brown clothing']), ('dwarf', 'humanoid', [ 'a mature adult male fantasy dwarf miner, a broad bearded face, short stocky adult proportions, an ochre work tunic and boots', 'a mature adult female fantasy dwarf tinkerer, braided auburn hair, short stocky adult proportions, a navy work jacket and trousers', 'a mature adult male fantasy dwarf warrior, a braided silver beard, short stocky adult proportions and copper plated armor', 'a mature adult female fantasy dwarf traveller, silver braids, short stocky adult proportions, a burgundy cloak and brown trousers']), ('orc', 'humanoid', [ 'an adult male slate-gray orc, small tusks, a broad mature face, a brown leather vest over a cream shirt and trousers', 'an adult female ochre-brown orc, small tusks, braided dark hair and fully covering navy travelling clothes', 'an adult male copper-brown orc artisan, short hair, small tusks, a rust work coat and charcoal trousers', 'an adult female blue-gray orc guard, tied silver hair, small tusks and bronze armor over a navy tunic']), ('ogre', 'humanoid', [ 'an adult male copper-skinned ogre, a huge sturdy build, a brown wool coat and full-length charcoal trousers', 'an adult female slate-gray ogre, a huge sturdy build, a plum long-sleeved tunic and navy trousers', 'an adult male ochre-skinned ogre chef, a cream apron over a burgundy shirt and brown trousers', 'an adult female violet-gray ogre traveller, a cream cloak over a navy shirt and full-length brown trousers']), ('goblin', 'humanoid', [ 'an adult male copper goblin, a mature narrow face, long pointed ears, a navy waistcoat and brown trousers', 'an adult female indigo goblin, a mature narrow face, long pointed ears, a burgundy coat and charcoal trousers', 'an adult male brown goblin inventor, long pointed ears, an ochre work jacket and navy trousers', 'an adult female slate-gray goblin merchant, long pointed ears, a cream blouse and fully covering plum robes']), ('elf', 'humanoid', [ 'an adult male moon elf, silver hair, long pointed ears and fully covering indigo embroidered travelling clothes', 'an adult female forest elf, auburn braids, pointed ears, a brown cloak and fully covering cream linen clothing', 'an adult male city elf, dark skin, short black hair, pointed ears and a tailored burgundy coat with navy trousers', 'an adult female elder elf, warm brown skin, silver braids, pointed ears and fully covering ochre robes']), ('medieval_knight', 'humanoid', [ 'an adult male medieval knight, an uncovered mature face, silver plate armor and a navy tabard', 'an adult female medieval knight, an uncovered mature face, bronze plate armor and a burgundy tabard', 'an adult male desert knight, an uncovered mature brown face, cream cloth layers over copper armor', 'an adult female late-medieval knight, an uncovered mature dark face, charcoal plate armor and a plum cloak']), ('warrior', 'humanoid', [ 'an adult male northern warrior, a mature bearded face, a fully covering brown wool coat over chainmail and trousers', 'an adult female classical warrior, a mature face, bronze armor over a cream tunic and full-length navy trousers', 'an adult male desert warrior, warm brown skin and fully covering layered ochre cloth armor', 'an adult female feudal warrior, a mature face and fully covering indigo layered lamellar armor']), ('robot', 'mechanical', [ 'a classic retro brass robot, a rounded metal head, amber optical eyes and articulated mechanical arms and legs', 'a modern white ceramic robot, a compact rounded head, blue optical eyes and jointed mechanical arms and legs', 'an industrial charcoal robot, a square metal head, copper panels and amber optical eyes', 'a rounded cream companion robot, a small dome head, lavender optical eyes and compact mechanical limbs']), ('cyborg', 'humanoid', [ 'an adult male cyborg, a mature brown face, a clean mechanical forearm, a navy jacket and charcoal trousers', 'an adult female cyborg, a mature pale face, a small silver temple panel, a plum jacket and full-length navy trousers', 'an adult male elderly cyborg, silver hair, a clean brass prosthetic hand and a burgundy suit', 'an adult female cyborg engineer, a mature dark face, a clean titanium forearm and fully covering ochre workwear']), ('alien', 'humanoid', [ 'an adult male cobalt-blue alien, a mature oval face, subtle forehead ridges and fully covering cream spacewear', 'an adult female violet alien, a mature oval face, two short antennae and fully covering navy diplomatic robes', 'an adult male ochre alien, a broad mature face, small pointed ears and a burgundy expedition suit', 'an adult female gray alien, a mature proportionate face, small black eyes and a fully covering lavender flight suit']), ('insectoid', 'insectoid', [ 'a moth-like insectoid, ivory fuzzy head, folded purple wings, four articulated arms and two sturdy legs', 'a beetle-like insectoid, glossy copper shell, two antennae, four articulated arms and two sturdy legs', 'a crystalline blue insectoid, faceted shell, two antennae, four thin articulated arms and two sturdy legs', 'a bronze ant-like insectoid, segmented shell, two antennae, four articulated arms and two sturdy legs']), ('reptilian', 'humanoid', [ 'an adult male slate-blue reptilian alien, a mature lizard face, a small crest and fully covering navy travelling clothes', 'an adult female dark-red reptilian alien, a mature lizard face, a small crest and fully covering cream robes', 'an adult male amber reptilian alien, a mature lizard face and a fully covering charcoal mechanic suit', 'an adult female black-scaled reptilian alien, a mature lizard face and fully covering plum diplomatic robes']), ('android', 'humanoid', [ 'an adult male android, a mature ivory synthetic face, fine silver seam lines and a navy tailored coat', 'an adult female android, a mature warm-brown synthetic face, silver seam lines and a plum jacket with trousers', 'an adult male android, a mature charcoal ceramic face, amber eyes and a fully covering cream uniform', 'an adult female android, a mature pale ceramic face, short copper hair and a fully covering burgundy uniform']), ('astronaut', 'humanoid', [ 'an adult male astronaut, a mature pale face, short brown hair and a fully covering white spacesuit with navy panels, no helmet', 'an adult female astronaut, a mature dark face, cropped hair and a fully covering cream spacesuit with burgundy panels, no helmet', 'an adult male astronaut, a mature tan face, black hair and a fully covering charcoal spacesuit with copper panels, no helmet', 'an adult female astronaut, a mature warm-brown face, tied hair and a fully covering navy spacesuit with lavender panels, no helmet']), ('space_crew', 'humanoid', [ 'an adult male starship pilot, a mature tan face, short hair and a fully covering navy flight uniform', 'an adult female starship mechanic, a mature dark face, cropped hair and a fully covering ochre work suit', 'an adult male space ambassador, a mature brown face, silver hair and fully covering cream diplomatic robes', 'an adult female space detective, a mature pale face, short hair, a burgundy coat and full-length charcoal trousers']), ('lovecraftian', 'eldritch', [ 'a small Cthulhu-like violet cosmic creature, an octopus head with short tentacles, folded bat wings and stout clawed feet', 'a Mi-Go-like copper cosmic creature, a lobed alien head, folded wings and articulated crustacean limbs', 'a robed cosmic entity, an opaque indigo hood and fully covering robes, a pale mask with tiny calm eyes', 'a compact Shoggoth-like opaque purple amorphous creature, rounded folds and a few small gold eyes']), ('spirit', 'humanoid', [ 'an adult male opaque blue-gray Victorian ghost, a mature face and a fully covering charcoal frock coat', 'an adult female opaque lavender spirit, a mature face, silver hair and a fully covering plum gown', 'an elderly male opaque ivory spirit, a mature wrinkled face and fully covering cream robes', 'an adult female clockwork spirit, an opaque silver face, delicate brass seams and fully covering navy robes']), ('golem', 'mechanical', [ 'a clay golem, a compact rounded ochre body, a simple calm carved face and thick sculpted arms and legs', 'a stone golem, a compact slate-gray body, a simple calm carved face and thick angular arms and legs', 'a porcelain golem, an ivory body with cobalt patterns, a simple calm face and articulated sculpted limbs', 'a brass golem, a compact aged copper body, a simple calm metal face and thick mechanical arms and legs']), ('beastfolk', 'humanoid', [ 'an adult male wolf beastfolk, a mature charcoal wolf head, fully covering navy travelling clothes and brown boots', 'an adult female lion beastfolk, a mature tawny lion head, fully covering burgundy robes and brown shoes', 'an adult male raven beastfolk, a mature black-feathered raven head, a cream jacket and full-length charcoal trousers', 'an adult female fox beastfolk, a mature copper fox head, a plum coat and full-length navy trousers']), ] def build(): persons=[];other=0 cells=[('young_adult','male',50),('young_adult','female',50), ('middle_adult','male',50),('middle_adult','female',50), ('younger_senior','male',10),('younger_senior','female',10), ('older_senior','male',10),('older_senior','female',10)] age_ranges={a:(l,h) for a,l,h in AGES} for group,gender,n in cells: low,high=age_ranges[group] for j in range(n): ident=f'person-{501+len(persons):04d}';rng=random.Random(seed(ident)) eth=ETHNICITIES[0] if j%2==0 else ETHNICITIES[1+other%7] if j%2:other+=1 age=rng.randint(low,high) color=rng.choice(['dark brown','black','medium brown','chestnut']) if eth[0]=='white_caucasian':color=rng.choice(['dark brown','light brown','blond','auburn','black']) if age>=65:color=rng.choice(['silver','white','gray']) hair=color+' '+rng.choice(HAIR_M if gender=='male' else HAIR_F) style,clothes=outfit(age,gender,random.Random(seed(ident+'-outfit-color')),seed(ident+'-outfit-style')) p=dict(personality_id=ident,character_id=ident,record_type='human',production_phase='extension', age_group=group,age_years=age,age_months=0,gender=gender,ethnicity=eth[0],ethnicity_prompt_label=eth[1], skin_tone=rng.choice(eth[2]),hair=hair,build=rng.choice(['a slim build','an average build','a sturdy build','a compact build']), outfit_id='outfit-01',outfit_style=style,outfit=clothes,seed=seed(ident),default_emotion='neutral',lora_scale=1.0, special_class='',special_variant='',composition='standing head-to-thigh portrait') p['description']=description(p) neg='extra people, changed clothing, different hairstyle, text, logo, watermark, background scenery, oversized doll eyes, chibi proportions' p['expressions']=[dict(id=ident+'-'+e,emotion=e,prompt=prompt(p,e,e!='neutral'), negative_prompt=neg+(', exaggerated expression' if e=='neutral' else ''),seed=p['seed'], reference_id='' if e=='neutral' else ident+'-neutral') for e,_ in EMOTIONS] persons.append(p) assert len(persons)==240 specials=[] for kind,anatomy,variants in SPECIALS: for j,desc in enumerate(variants): ident=f'special-{len(specials)+1:04d}' gender=('female' if ' female ' in ' '+desc+' ' else 'male') if anatomy=='humanoid' else 'not_applicable' framing='Full-body character portrait, entire silhouette centered, generous margin around head, feet, wings and tail.' if anatomy in ['quadruped','serpentine']: framing+=' Natural dragon anatomy, no human torso or human hands, wings folded, tail coiled to fit inside the portrait.' elif anatomy=='humanoid':framing+=' Standing relaxed, face visible, fully clothed.' else:framing+=' One creature only, compact silhouette fitting entirely inside the portrait.' text=(f'vvar_char, one fictional {desc}. Calm neutral pose and a restrained slightly friendly expression. ' f'{framing} {CHARACTER_STYLE} Perfectly uniform solid bright chroma green background, ' 'no scenery, no shadow or gradient. No green or teal on the subject. No text, no logo, no watermark. Non-graphic.') neg='extra creatures, extra people, text, logo, watermark, scenery, cropped feet, cropped wings, gore, blood, wounds, chibi proportions' if anatomy in ['quadruped','serpentine']:neg+=', human face, human torso, human hands, humanoid anatomy' p=dict(personality_id=ident,character_id=ident,record_type='special',production_phase='extension', age_group='fictional_adult' if anatomy=='humanoid' else 'not_applicable',age_years=0,age_months=0, gender=gender,ethnicity='not_applicable',ethnicity_prompt_label='not_applicable',skin_tone='fictional palette specified in description', hair='specified in description',build=anatomy,outfit_id='outfit-01',outfit_style=kind,outfit='specified in description', seed=seed(ident),default_emotion='neutral',lora_scale=1.0,special_class=kind,special_variant=f'{kind}-{j+1:02d}', composition=framing,description=desc, expressions=[dict(id=ident+'-neutral',emotion='neutral',prompt=text,negative_prompt=neg,seed=seed(ident),reference_id='')]) specials.append(p) jobs=persons+specials assert len(specials)==100 and len({e['id'] for p in jobs for e in p['expressions']})==2500 assert Counter(p['gender'] for p in persons)==dict(male=120,female=120) assert sum(p['ethnicity']=='white_caucasian' for p in persons)==120 old=json.loads((ROOT/'experiments/character-production/person-plan.json').read_text()) assert not ({p['personality_id'] for p in old}&{p['personality_id'] for p in jobs}) write(STATE/'person-plan.json',jobs) write(STATE/'planning/allocation.json',dict(humans=240,specials=100,identities=340,images=2500,human_images=2400,special_images=100, combined_humans=740,combined_identities=840,combined_images=7500,human_gender_counts=dict(Counter(p['gender'] for p in persons)), human_ethnicity_counts=dict(Counter(p['ethnicity'] for p in persons)), by_age_and_gender={f'{a}/{g}':n for a,g,n in cells},special_class_counts=dict(Counter(p['special_class'] for p in specials)), human_emotions=10,special_emotions=1,default_emotion='neutral', demographic_labels_are_intended_prompt_attributes=True,senior_interpretation='40 total, 20 male and 20 female; half younger, half older seniors')) write(STATE/'planning/taxonomy.json',dict(age_groups=[dict(id=a,min_age=l,max_age=h) for a,l,h in AGES if a in {c[0] for c in cells}], emotions=[dict(id=e,expression=v) for e,v in EMOTIONS], ethnicity_groups=[dict(id=e,prompt_label=v) for e,v,_ in ETHNICITIES], special_classes=[dict(id=k,anatomy=a,variants=v) for k,a,v in SPECIALS], palette_policy='Green and teal subject colors avoided because they would be removed by chroma keying', reference_policy='Humans: default neutral resized416x624 for nine facial edits; specials: one default portrait, no reference or emotion variants')) print(json.dumps(json.loads((STATE/'planning/allocation.json').read_text()),indent=2)) if __name__=='__main__':build()