"""Ten balanced professional outfits for each existing adult human identity.""" from collections import Counter, defaultdict import csv import hashlib import json from pathlib import Path import random from background_production import dump from vivarium_prompt_templates import CHARACTER_STYLE ROOT=Path(__file__).resolve().parents[1] STATE=ROOT/'experiments/job-outfits' ADULT_GROUPS={'young_adult','middle_adult','older_adult','younger_senior','older_senior'} JOBS='''health|physician|Arzt/Ärztin|physician|a white medical coat over a pale blue closed shirt and navy trousers, plain dark shoes health|surgeon|Chirurg/Chirurgin|surgeon|a clean cobalt-blue long-sleeved scrub top and matching full-length scrub trousers, white medical shoes, no mask health|nurse|Pflegefachkraft|nurse|a lavender clinical tunic over a white long-sleeved undershirt and navy scrub trousers, white shoes health|paramedic|Rettungssanitäter/in|paramedic|a burgundy emergency-service jacket with silver reflective bands and matching trousers, black boots health|pharmacist|Apotheker/in|pharmacist|a cream pharmacy coat over a plum closed shirt and charcoal trousers, dark shoes health|dentist|Zahnarzt/Zahnärztin|dentist|a white dental tunic over a pale blue long-sleeved undershirt and navy trousers, white shoes, no mask health|laboratory_technician|Medizinische Laborfachkraft|medical laboratory technician|a knee-length white laboratory coat over a burgundy closed shirt and charcoal trousers, dark shoes health|radiographer|Radiologie-Fachkraft|radiographer|a navy clinical tunic with plain pale blue trim, full-length navy trousers and white medical shoes health|physiotherapist|Physiotherapeut/in|physiotherapist|a pale blue professional polo over white long sleeves, navy straight trousers and supportive white shoes health|psychologist|Psychologe/Psychologin|psychologist|a soft taupe blazer over a cream closed shirt, charcoal tailored trousers and brown shoes emergency|firefighter|Feuerwehrkraft|firefighter|a closed charcoal fire-service coat and full-length protective trousers with yellow and silver reflective bands, black protective boots, no helmet emergency|police_officer|Polizeikraft|police officer|a navy police-style long-sleeved uniform with plain shoulder tabs and an unlettered silver badge, navy trousers and black shoes, empty belt emergency|detective|Kriminalermittler/in|detective|a tan detective trench coat over a white closed shirt and burgundy tie, charcoal trousers and brown shoes emergency|security_guard|Sicherheitskraft|security guard|a charcoal security jacket with an unlettered white badge patch, navy trousers and black shoes, empty belt emergency|coast_guard|Küstenwache|coast guard officer|a navy maritime utility jacket with an orange flotation vest worn open at the neck over full clothing, navy trousers and boots emergency|lifeguard|Rettungsschwimmer/in|lifeguard|a red long-sleeved rescue top and full-length navy rescue trousers, white closed shoes emergency|search_rescue|Bergungs- und Suchrettungskraft|search and rescue worker|an orange rescue jacket with silver reflective bands, charcoal cargo trousers and sturdy black boots emergency|civil_defense|Katastrophenschutzkraft|civil defense worker|a royal-blue utility jacket and matching full-length trousers with silver reflective bands, sturdy black boots emergency|park_ranger|Park-Ranger/in|park ranger|a tan long-sleeved field shirt with plain brown shoulder tabs, brown utility trousers and sturdy boots, no hat emergency|corrections_officer|Justizvollzugskraft|corrections officer|a slate-blue long-sleeved uniform shirt, charcoal straight trousers and black shoes, plain unlettered badge, empty belt retail_hospitality|cashier|Kassierer/in|cashier|a burgundy retail vest over a white long-sleeved shirt, charcoal trousers and black shoes, blank name badge retail_hospitality|supermarket_worker|Supermarktmitarbeiter/in|supermarket worker|an orange supermarket waistcoat over a navy long-sleeved shirt, charcoal work trousers and black shoes, blank badge retail_hospitality|baker|Bäcker/in|baker|a closed white bakery jacket and white apron over navy trousers, white closed shoes retail_hospitality|butcher|Fleischer/in|butcher|a clean burgundy-and-white striped apron over a white long-sleeved coat, charcoal trousers and black shoes retail_hospitality|fishmonger|Fischhändler/in|fishmonger|a navy waterproof apron over a pale blue long-sleeved shirt, navy trousers and clean white rubber boots retail_hospitality|florist|Florist/in|florist|an ochre canvas apron over a plum long-sleeved shirt, navy trousers and brown closed shoes retail_hospitality|restaurant_server|Servicekraft im Restaurant|restaurant server|a black waistcoat over a closed white long-sleeved shirt, black trousers and polished black shoes retail_hospitality|bartender|Barmann/Barfrau|bartender|a dark burgundy waistcoat over a white long-sleeved shirt with sleeves neatly rolled to the forearm, black trousers and shoes retail_hospitality|barista|Barista|barista|a tan full apron over a navy long-sleeved shirt, charcoal trousers and dark closed shoes retail_hospitality|hotel_receptionist|Hotel-Rezeptionist/in|hotel receptionist|a navy tailored blazer over a cream closed shirt, navy trousers and black shoes, blank brass name badge construction|electrician|Elektriker/in|electrician|a royal-blue utility jacket with orange piping, charcoal work trousers with reinforced knees and sturdy black boots construction|plumber|Installateur/in|plumber|a navy zip-front work jacket, rust utility trousers with reinforced knees and brown work boots construction|carpenter|Zimmerer/Zimmerin|carpenter|brown canvas overalls over a cream long-sleeved shirt, sturdy brown boots construction|bricklayer|Maurer/in|bricklayer|an orange high-visibility vest over a navy long-sleeved shirt, charcoal reinforced trousers and sturdy boots construction|painter|Maler/in|painter|clean white painter overalls over a lavender long-sleeved shirt, dark work shoes, no paint stains construction|roofer|Dachdecker/in|roofer|a charcoal closed work jacket and reinforced trousers, brown sturdy boots and an empty brown utility belt construction|tiler|Fliesenleger/in|tiler|navy canvas overalls over a cream long-sleeved shirt, padded knees and dark work boots construction|glazier|Glaser/in|glazier|a blue-gray protective work jacket over a white closed shirt, charcoal trousers and black safety shoes construction|locksmith|Schlosser/in|locksmith|a burgundy shop coat over a navy closed shirt, charcoal utility trousers and black work shoes construction|construction_foreman|Bauleiter/in|construction foreman|an orange reflective waistcoat over a pale blue closed shirt, navy work trousers and brown safety boots, no helmet industrial_logistics|machinist|Zerspanungsmechaniker/in|machinist|a steel-blue factory jacket and matching full-length work trousers, sturdy black safety shoes industrial_logistics|welder|Schweißer/in|welder|a heavy brown leather welding jacket, navy work trousers and black boots, face uncovered, no helmet industrial_logistics|auto_mechanic|Kfz-Mechaniker/in|auto mechanic|navy zip-front mechanic coveralls with red shoulder panels, black work boots industrial_logistics|hvac_technician|Klima- und Heizungstechniker/in|HVAC technician|a charcoal utility jacket with royal-blue panels, navy work trousers and black safety shoes industrial_logistics|warehouse_worker|Lagerfachkraft|warehouse worker|an orange reflective vest over a cream long-sleeved shirt, charcoal cargo trousers and sturdy boots industrial_logistics|forklift_operator|Gabelstaplerfahrer/in|forklift operator|an orange reflective vest over navy long sleeves, brown reinforced work trousers and black safety shoes industrial_logistics|truck_driver|Lkw-Fahrer/in|truck driver|a burgundy utility jacket over a charcoal closed shirt, navy work trousers and brown work boots industrial_logistics|delivery_courier|Paketzusteller/in|delivery courier|a royal-blue weatherproof delivery jacket with orange cuffs, charcoal cargo trousers and sturdy black shoes industrial_logistics|sanitation_worker|Abfallwirtschaftskraft|sanitation worker|a closed orange high-visibility jacket and matching full-length trousers with silver reflective bands, black work boots industrial_logistics|rail_mechanic|Bahn-Instandhaltungskraft|railway maintenance mechanic|an orange safety jacket over a navy long-sleeved shirt, navy reinforced trousers and sturdy boots civic_transport|postal_worker|Postzusteller/in|postal worker|a mustard-yellow delivery jacket with navy trim, navy trousers and sturdy black shoes civic_transport|bus_driver|Busfahrer/in|bus driver|a pale blue long-sleeved uniform shirt with a burgundy tie, navy trousers and black shoes civic_transport|train_driver|Lokführer/in|train driver|a navy uniform blazer over a white closed shirt and dark tie, navy trousers and polished black shoes civic_transport|taxi_driver|Taxifahrer/in|taxi driver|a charcoal casual blazer over a pale blue closed shirt, navy trousers and brown shoes civic_transport|flight_attendant|Flugbegleiter/in|flight attendant|a navy airline-style blazer over a cream closed shirt with a small burgundy neck scarf, navy trousers and black shoes civic_transport|airline_pilot|Linienpilot/in|airline pilot|a navy double-breasted pilot jacket with plain gold sleeve bands over a white shirt, navy trousers and black shoes, no hat civic_transport|municipal_maintenance|Kommunale Instandhaltungskraft|municipal maintenance worker|an orange reflective waistcoat over a burgundy work jacket, charcoal trousers and safety boots civic_transport|street_cleaner|Straßenreinigungskraft|street cleaner|an orange weatherproof reflective jacket over full clothing, navy utility trousers and black work boots civic_transport|traffic_warden|Verkehrsüberwachungskraft|traffic warden|a royal-blue uniform jacket with plain silver trim, navy trousers and black shoes, blank badge civic_transport|municipal_clerk|Verwaltungsangestellte/r|municipal clerk|a navy cardigan over a cream closed shirt, charcoal tailored trousers and black shoes office_finance|bank_teller|Bankangestellte/r|bank teller|a navy tailored waistcoat over a white closed shirt, charcoal trousers and black shoes, blank name badge office_finance|accountant|Buchhalter/in|accountant|a charcoal blazer over a pale blue closed shirt, navy tailored trousers and brown shoes office_finance|debt_collector|Geldeintreiber/in|debt collection agent|a brown leather jacket over a charcoal closed shirt, dark navy trousers and brown shoes, calm professional appearance office_finance|insurance_agent|Versicherungsberater/in|insurance agent|a burgundy business blazer over a cream closed shirt, charcoal trousers and polished black shoes office_finance|real_estate_agent|Immobilienmakler/in|real estate agent|a taupe tailored blazer over a white closed shirt, navy trousers and brown shoes office_finance|lawyer|Rechtsanwalt/Rechtsanwältin|lawyer|a charcoal business suit over a white closed shirt and plain burgundy tie, polished black shoes office_finance|judge|Richter/in|judge|an opaque full-length black judicial robe with a plain cream collar over full formal clothing, black shoes office_finance|financial_adviser|Finanzberater/in|financial adviser|a navy suit over a pale blue closed shirt and muted gold tie, polished brown shoes office_finance|office_manager|Büroleiter/in|office manager|a plum blazer over a cream closed shirt, charcoal straight trousers and black shoes office_finance|translator|Übersetzer/in|translator|a brown knit cardigan over a pale blue closed shirt, navy tailored trousers and brown shoes outdoors_animals|farmer|Landwirt/in|farmer|brown canvas overalls over a burgundy long-sleeved shirt, sturdy brown boots outdoors_animals|gardener|Gärtner/in|gardener|a tan canvas work jacket over a navy long-sleeved shirt, brown reinforced trousers and sturdy boots outdoors_animals|forester|Forstwirt/in|forester|an orange field jacket with charcoal panels, brown protective work trousers and sturdy black boots outdoors_animals|fishery_worker|Fischereifachkraft|fishery worker|an ochre waterproof fishing jacket and full-length navy waterproof trousers, clean white rubber boots outdoors_animals|animal_caretaker|Tierpfleger/in|animal caretaker|a cream utility jacket over a lavender closed shirt, brown cargo trousers and sturdy shoes outdoors_animals|veterinarian|Tierarzt/Tierärztin|veterinarian|a white veterinary coat over a burgundy scrub top and full-length navy scrub trousers, white shoes outdoors_animals|landscaper|Landschaftsgärtner/in|landscape contractor|a navy canvas jacket over an ochre long-sleeved shirt, brown reinforced work trousers and safety boots outdoors_animals|viticulturist|Winzer/in|viticulturist|a tan field waistcoat over a cream long-sleeved shirt, burgundy work trousers and brown sturdy boots outdoors_animals|beekeeper|Imker/in|beekeeper|a fully closed cream protective beekeeper coverall and white boots, no veil or hood, face and hair visible outdoors_animals|marine_biologist|Meeresbiologe/Meeresbiologin|marine biologist|a navy field jacket over a pale blue closed shirt, tan utility trousers and sturdy brown shoes science_education|school_teacher|Lehrer/in|school teacher|a burgundy cardigan over a cream closed shirt, navy tailored trousers and brown shoes science_education|university_lecturer|Hochschuldozent/in|university lecturer|a taupe tweed blazer over a pale blue closed shirt, charcoal trousers and brown shoes science_education|research_scientist|Forschungswissenschaftler/in|research scientist|a white research lab coat over a lavender closed shirt and navy trousers, dark closed shoes science_education|astronomer|Astronom/in|astronomer|a navy observatory fleece jacket over a cream closed shirt, charcoal trousers and brown shoes science_education|archaeologist|Archäologe/Archäologin|archaeologist|a tan field vest over a cream long-sleeved shirt, brown cargo trousers and sturdy brown boots science_education|surveyor|Vermessungstechniker/in|surveyor|an orange reflective field vest over a pale blue long-sleeved shirt, charcoal work trousers and brown boots science_education|architect|Architekt/in|architect|a charcoal tailored jacket over a black closed shirt, navy straight trousers and dark shoes science_education|software_developer|Softwareentwickler/in|software developer|a navy zip-front hoodie over a burgundy closed shirt, charcoal trousers and clean dark sneakers science_education|journalist|Journalist/in|journalist|a tan casual jacket over a white closed shirt, navy trousers and sturdy brown shoes science_education|librarian|Bibliothekar/in|librarian|a plum cardigan over a cream closed shirt, charcoal straight trousers and brown shoes creative_culture|chef|Koch/Köchin|chef|a closed white double-breasted chef jacket with burgundy piping, charcoal trousers and black kitchen shoes, no hat creative_culture|hairdresser|Friseur/in|hairdresser|a black salon tunic over a cream long-sleeved undershirt, black full-length trousers and dark shoes creative_culture|barber|Barbier/in|barber|a burgundy barber waistcoat over a white long-sleeved shirt, charcoal trousers and black shoes creative_culture|tailor|Schneider/in|tailor|a brown craft apron over a lavender long-sleeved shirt, navy trousers and dark shoes creative_culture|shoe_repairer|Schuhmacher/in|shoe repairer|a tan leather craft apron over a burgundy long-sleeved shirt, charcoal trousers and brown shoes creative_culture|photographer|Fotograf/in|photographer|a charcoal photographer vest over a pale blue closed shirt, navy trousers and sturdy black shoes creative_culture|sound_technician|Tontechniker/in|sound technician|a navy technical jacket over a charcoal closed shirt, black utility trousers and dark work shoes creative_culture|stage_technician|Bühnentechniker/in|stage technician|a black long-sleeved crew jacket and black reinforced utility trousers, sturdy black boots creative_culture|museum_curator|Museumskurator/in|museum curator|a plum tailored blazer over a cream closed shirt, navy trousers and brown shoes creative_culture|music_teacher|Musiklehrer/in|music teacher|a brown cardigan over a white closed shirt, charcoal tailored trousers and brown shoes''' def stable_seed(text):return int.from_bytes(hashlib.sha256(text.encode()).digest()[:4],'big') def build(): jobs=[] for i,line in enumerate(JOBS.splitlines(),1): family,key,de,en,outfit=line.split('|') jobs.append(dict(job_id=f'job-{i:03d}',job_key=key,profession_family=family,job_title_de=de,job_title_en=en,job_outfit=outfit)) assert len(jobs)==100 and len({j['job_key'] for j in jobs})==100 assert set(Counter(j['profession_family'] for j in jobs).values())=={10} base=[] for phase in ['character-production','character-extension']: for p in json.loads((ROOT/f'experiments/{phase}/person-plan.json').read_text()): if p.get('record_type','human')=='human' and p['age_group'] in ADULT_GROUPS: base.append((p,phase)) assert len(base)==464 and all(p['age_years']>=19 for p,_ in base) cells=defaultdict(list) for p,phase in base:cells[p['age_group']+'/'+p['gender']].append((p,phase)) assignments=defaultdict(list) for family in dict.fromkeys(j['profession_family'] for j in jobs): choices=[j for j in jobs if j['profession_family']==family] rng=random.Random(stable_seed('vivarium-jobs-family:'+family));rng.shuffle(choices) cursor=0 for cell in sorted(cells): persons=list(cells[cell]);rng.shuffle(persons);n=len(persons) quota=[n//10]*10 for r in range(n%10):quota[(cursor+r)%10]+=1 cursor=(cursor+n%10)%10 allocated=[j for j,k in zip(choices,quota) for _ in range(k)];rng.shuffle(allocated) for (p,phase),job in zip(persons,allocated):assignments[p['personality_id']].append(job) plan=[] negative='extra people, changed face, changed hairstyle, changed skin tone, infant, child, text, logos, scenery, weapons, blood, injury, nudity, revealing clothing, green clothing, teal clothing' for p,phase in base: for index,job in enumerate(assignments[p['personality_id']],1): ident=p['personality_id']+'-'+job['job_id'];seed=stable_seed('vivarium-job-outfits-2026-10-06:'+ident) prompt=(f'vvar_char, edit the reference portrait of this same {p["age_years"]}-year-old adult. ' f'Change only the clothing to a fully clothed professional {job["job_title_en"]} outfit: {job["job_outfit"]}. ' f'Keep the exact face, {p["skin_tone"]} skin tone, hairstyle, body proportions, pose, framing and lighting. ' f'Relaxed neutral expression with a slight friendly smile. Face and hair clearly visible, hands empty. ' f'{CHARACTER_STYLE} Uniform bright chroma green background. No scenery, text or logos. No green or teal clothing.') record={k:v for k,v in p.items() if k!='expressions'} record.update(job);record.update(id=ident,record_type='job_outfit',production_phase='job_outfits', base_outfit_id=p['outfit_id'],base_outfit_style=p['outfit_style'],base_outfit=p['outfit'], base_description=p['description'],outfit_id=ident,outfit_style='professional_'+job['profession_family'], outfit=job['job_outfit'],description=f'The same reference identity in the {job["job_title_en"]} outfit.', job_outfit_index=index,emotion='neutral',default_emotion='neutral',reference_id=p['personality_id']+'-neutral', reference_source_phase=phase,reference_source_repo_path='data/' if phase=='character-production' else 'extension-data/', prompt=prompt,negative_prompt=negative,seed=seed,lora_scale=1.0) plan.append(record) grouped=Counter(r['personality_id'] for r in plan);counts=Counter(r['job_id'] for r in plan) assert len(plan)==4640 and len(grouped)==464 and set(grouped.values())=={10} assert len({r['id'] for r in plan})==4640 and set(counts.values())=={46,47} assert Counter(counts.values())=={46:60,47:40} for pid in grouped:assert len({r['job_id'] for r in plan if r['personality_id']==pid})==10 cell_counts=defaultdict(Counter) for r in plan:cell_counts[r['age_group']+'/'+r['gender']][r['job_id']]+=1 assert all(len(v)==100 and max(v.values())-min(v.values())<=1 for v in cell_counts.values()) if (STATE/'image-plan.json').exists(): assert json.loads((STATE/'image-plan.json').read_text())==plan,'Refusing to mutate a frozen outfit plan' dump(STATE/'image-plan.json',plan);dump(STATE/'planning/jobs.json',jobs) allocation=dict(adult_identities=464,images=4640,jobs=100,outfits_per_identity=10, jobs_with46images=60,jobs_with47images=40,job_counts=dict(counts), by_age_and_gender=dict(Counter(p['age_group']+'/'+p['gender'] for p,_ in base)), job_counts_per_age_gender={k:dict(v) for k,v in cell_counts.items()}, rationale='One job from each of ten families per adult; cyclic remainder quotas guarantee global46/47 balance and within-cell floor/ceiling balance; deterministic independent shuffles avoid demographic/job-index correlation', excluded='All teen,child and special-character categories; adults are19–95. These are fictional role outfits,not claims about actual employment.') dump(STATE/'planning/allocation.json',allocation) STATE.mkdir(parents=True,exist_ok=True) for name,rows in [('jobs.csv',jobs),('outfits.csv',[{k:r[k] for k in ['id','personality_id','age_group','age_years','gender','ethnicity','job_id','job_title_de','job_title_en','profession_family','outfit','seed','reference_id']} for r in plan])]: with (STATE/'planning'/name).open('w',newline='') as f: w=csv.DictWriter(f,fieldnames=list(rows[0]));w.writeheader();w.writerows(rows) from transformers import AutoTokenizer tok=AutoTokenizer.from_pretrained('/tmp/vivarium-flux2-models/FLUX.2-klein-base-9B/tokenizer') texts=[tok.apply_chat_template([dict(role='user',content=r['prompt'])],tokenize=False,add_generation_prompt=True,enable_thinking=False) for r in plan] lengths=[len(ids) for ids in tok(texts,padding=False,truncation=False)['input_ids']] assert min(lengths)>100,'Audit actual input IDs rather than the keys of a tokenizer result' assert max(lengths)<=256,(max(lengths),plan[lengths.index(max(lengths))]['id']) result=dict(status='passed',images=len(plan),identities=len(grouped),jobs=100,min_tokens=min(lengths),max_tokens=max(lengths), token_limit=256,no_truncation=True,chat_template=True,age_gender_job_balance='Each job count differs by at most1 within every age/gender cell', plan_sha256=hashlib.sha256((STATE/'image-plan.json').read_bytes()).hexdigest()) dump(STATE/'plan-validation.json',result);print(json.dumps(result,indent=2)) if __name__=='__main__':build()