#!/usr/bin/env python3
"""FastH3 Omni shot jobs for The Argument (RestoreBunny Snaptoon, 9:16, 7 gens).
v2 - exaggerated acting: big open-mouth articulation, jaw/lip shaping, brow + eye work, head tilts and shoulder moves."""
import json, pathlib
HERE = pathlib.Path(__file__).parent
REMOTE = "/Users/sarthakrawool/omni-test/2026-12-07-the-argument-v2"
SHEETS = {'priya': 'priya_sheet.png', 'sam': 'sam_sheet.png', 'nan': 'nan_sheet.png'}
PLATES = {'kitchen': 'env_g01.png'}
PROPS = {'faded': 'prop_faded.png', 'stylised': 'prop_stylised.png'}
WHO = {'priya': ('Priya', 'a mature adult woman in her late thirties with a soft rounded face, warm brown skin, shoulder-length wavy black hair, a plain teal raincoat over a plain cream top, dark trousers, tall adult figure', 'a warm low-pitched American woman in her late thirties with a dry, quick voice'), 'sam': ('Sam', "a middle-aged adult man in his early fifties with a soft rounded face, light-brown skin, short grey-flecked hair, a plain olive jacket over a plain white shirt, dark jeans, an adult man's figure", 'a blunt American man in his early fifties with a quick, skeptical mid-low voice'), 'nan': ('Nan', 'an elderly 74-year-old grandmother with a soft rounded face, deep smile lines, warm brown skin, silver hair in a loose braid, a plain soft lavender cardigan over a plain grey dress, small elderly adult figure', 'a soft American grandmother in her seventies with a slow, warm, amused voice')}
STYLE = ('A stylised 3D animated feature film shot, vertical 9:16 frame: Pixar-style clean smooth cartoon grown-ups on adult proportions, '
         'soft rounded oval faces and big round eyes, natural moderately rich colour, warm skin against a softly blurred room, strong contrast with deep soft shadows. '
         'Big theatrical acting: wide mouths that open clearly on every stressed vowel, visible teeth and tongue shaping, strong jaw drops and lip rounds as each word lands, '
         'eyebrows that leap and knit, eyes that go wide then squint, heads that tilt and shoulders that swing with the beat. '
         'Each character moves in one or two quick sharp poses, then holds almost still. The characters look at each other while they talk, never into the camera. '
         'Everyone speaks fast in quick natural sentences, each speaker jumping in the moment the other finishes.')
SOUND = {'kitchen': 'A quiet kitchen in the evening: a fridge hum, a distant kettle, close natural voices.'}
GENS = [
 ('g01', 'kitchen', ['sam', 'priya'], ['faded'],
  "Medium two-shot in a plain kitchen at evening. Sam, in a plain olive jacket, leans over the counter squinting at the grey, blotchy photo print from <PROP faded> that Priya holds flat in both hands. Priya, in a plain teal raincoat, guards the print against her chest. The camera pushes in quickly at the start, then holds. Sam's mouth drops wide open on 'kept' and 'grey square', his eyebrows shoot up, then he squints hard and tips his head to the side.",
  [('sam', "You kept that? It's a grey square, Priya. Nan looks like a stranger.")]),
 ('g02', 'kitchen', ['nan', 'priya'], ['faded'],
  "Medium close-up favouring Nan: she comes into the kitchen in her soft lavender cardigan, silver hair in a loose braid, and stops beside Priya, looking down at the faded print from <PROP faded>. Priya turns the print toward her, her face softening. Slow push-in on Nan's face while she speaks. Priya's brows lift and her mouth opens round and wide on 'twenty' and 'before Dad left', her shoulders turning into the line.",
  [('priya', "It's her, Sam. She's twenty here, before Dad left.")]),
 ('g03', 'kitchen', ['sam', 'priya'], ['faded'],
  "Medium two-shot at the kitchen counter. Sam leans in closer, squinting at the faded print from <PROP faded> lying flat on the counter top right in front of Priya's hands. Priya keeps one hand over the print. The camera holds, then pushes in a little on Sam's face. Sam's jaw works hard and his mouth tears wide open on 'tell' and 'gone', he shakes his head slowly with his brows crushed together.",
  [('sam', "I can't even tell if that's her. Half the face is gone.")]),
 ('g04', 'kitchen', ['priya', 'sam'], ['stylised'],
  'Over-the-shoulder from behind a plain phone with a smooth blank back. Priya holds up the phone; its plain screen shows the stylised restored version from <PROP stylised>, sharp and clean, on one rigid flat surface that stays the same. Sam leans in, surprised. The camera holds on the screen, then nudges in. Priya grins with her mouth wide open on "RestoreBunny", her brows high, and Sam\'s eyes pop wide with his jaw hanging open.',
  [('priya', "RestoreBunny made a stylised version. Look, it's her face again.")]),
 ('g05', 'kitchen', ['nan', 'priya'], ['stylised'],
  "Medium close-up at the counter. Nan puts on plain glasses and leans close to the phone screen showing <PROP stylised> with the stylised face. Priya watches her reaction from the left, smiling a little. Slow push-in on Nan's face. Nan's mouth falls open in a big soft 'Oh', her brows lift high, her eyes glisten wide and her head tilts as she remembers.",
  [('nan', "Oh. That's me at the fair. I'd forgotten that ribbon.")]),
 ('g06', 'kitchen', ['sam', 'nan'], ['stylised'],
  "Medium two-shot. Sam's jaw drops and he points at the phone screen showing <PROP stylised>; Nan stands beside him with a small smile, holding the faded print from <PROP faded> in her other hand. The camera holds wide, then pushes in on Sam's face. Sam's whole face breaks open: mouth wide on 'Okay', eyes round and wide, brows to the top, a big shrug rolling through both shoulders as he admits it.",
  [('sam', "Okay, that's her. I was wrong, and I'm saying it.")]),
 ('g07', 'kitchen', ['priya', 'sam', 'nan'], ['stylised', 'faded'],
  'Medium three-shot at the kitchen counter in the evening. Priya turns the print to Sam, Nan smiles beside them, and the phone screen shows <PROP stylised> with the stylised face. Priya turns from the counter to Sam and speaks the last line. The camera holds wide, then nudges in on Priya. Priya beams with her mouth wide open on "Comment restore", her brows up and her shoulders turned to the lens line, then a quick bright nod on the last word.',
  [('priya', "Want yours fixed like this? Comment restore. I'll send the link.")]),
]
SEEDS = {}

def build(gen):
    gid, loc, people, props, action, lines = gen
    refs, n, tags, role_lines = {}, 0, {}, []
    for p in people:
        n += 1; refs[f"ref_picture_{n}"] = f"{REMOTE}/refs/{SHEETS[p]}"; tags[p] = n
        name, look, _ = WHO[p]
        role_lines.append(f"{name} is the character in <Picture {n}> (face close-up, then outfit from front, back and side): {look}.")
    n += 1; refs[f"ref_picture_{n}"] = f"{REMOTE}/env/{PLATES[loc]}"
    role_lines.append(f"The room and camera view are the ones shown in <Picture {n}>.")
    for pr in props:
        n += 1; refs[f"ref_picture_{n}"] = f"{REMOTE}/refs/{PROPS[pr]}"; tags["PROP " + pr] = n
        role_lines.append("The photo print is exactly the one in <Picture %d>." % n)
    act = action
    for k, v in tags.items():
        act = act.replace(f"<{k}>", f"<Picture {v}>")
    voices = " ".join(f"{WHO[p][0]} speaks with {WHO[p][2]}." for p in people if any(w == p for w, _ in lines))
    said = " ".join(f"({'S' + str(people.index(w) + 1)}) says: <d>[English] {t}</d>" for w, t in lines)
    speakers = " ".join(f"S{people.index(p) + 1} is {WHO[p][0]}." for p in people)
    prompt = (f"integrated_multimodal_description: [Shot 1] {STYLE} " + " ".join(role_lines) + f" {act} {speakers} {voices} {said}\n"
              f"overall_soundscape: {SOUND[loc]}\nnon_diegetic_music: N/A")
    return {"model": "fasth3-omni-8step-4bit", "prompt": prompt, "frames": 124, "seed": SEEDS.get(gid, 7), "inputs": refs,
            "output": f"{REMOTE}/clips/{gid}.mp4", "params": {"mode": "adaptive", "x2": False, "dense": True},
            "width": 704, "height": 1280}

out = HERE / "prompts" / "omni"; out.mkdir(parents=True, exist_ok=True)
for g in GENS:
    job = build(g)
    (out / f"{g[0]}.json").write_text(json.dumps(job, indent=1))
    (out / f"{g[0]}.txt").write_text(job["prompt"] + "\n\nrefs:\n" + "\n".join(f"{k}: {v}" for k, v in job["inputs"].items()) + "\n")
print(len(GENS), "jobs ->", out)
