from pathlib import Path
import json, os

p = Path('/data/video-pipeline/StickerMan/project/002-Vi-Sao-Nao-Bo-Khien-Ban-Nho-Nhung-Dieu-Chua-Tung-Xay-Ra')
timeline = json.loads((p / 'asr/timeline.json').read_text())['scenes']
prefix = 'Hand-drawn 2D doodle cartoon animation, flat colors, bold black outlines, slightly imperfect sketchy marker lines,'
required = 'simple expressive stick-figure characters with large circular white heads, dot eyes, thick eyebrow lines, information-rich educational doodle scene, layered visual storytelling, flat solid color blocks, bold black marker outlines, no storybook painting, no realistic anatomy, no paper texture'
suffix = 'no gradients, no shadows, no textures, no photorealism, no 3D, 16:9 aspect ratio, educational YouTube explainer doodle style.'
scenes = [
('A worried recurring stick-figure protagonist in the foreground holds a vivid framed memory of a family dinner while a sibling points to an empty photo album page proving it never happened; midground table with overturned blue cup, red chair, wall clock and family photo; background split into a bright remembered room and a blank evidence archive; torn-film strips and floating sensory icons connect the contradiction; bold title at top exactly “KÝ ỨC CÓ THẬT?”', ['KÝ ỨC CÓ THẬT?']),
('Inside a large open memory workshop shaped like a brain, the protagonist assembles a past event from separate puzzle pieces showing a face, sound waves, a red heart, a book, a speech bubble and a prediction arrow; midground conveyor belt replaces a camera reel with a reconstruction table; background shelves hold labeled memory boxes and one completed but incorrect scene glows behind glass; yellow arrows show fragments becoming one coherent story; top label exactly “NÃO TÁI DỰNG QUÁ KHỨ”', ['NÃO TÁI DỰNG QUÁ KHỨ']),
('A 1974 laboratory scene with two researcher stick figures beside a projector showing two cars colliding; foreground participants hold speed estimate cards while a question bubble changes the remembered crash; midground road model, stopwatch, clipboard, intact windshield and a false broken-glass memory inset; background comparison panel contrasts gentle collision and dramatic collision; red arrow label exactly “THÔNG TIN SAU SỰ KIỆN” and title “HIỆU ỨNG THÔNG TIN SAI LỆCH”', ['THÔNG TIN SAU SỰ KIỆN','HIỆU ỨNG THÔNG TIN SAI LỆCH']),
('Split evolutionary landscape: foreground modern protagonist chooses a safe path using a simplified danger map; midground ancient stick figures avoid a predator, reject spoiled berries and recognize a trusted face near a campfire; background contains countless faded leaves, wind marks and light changes discarded like unnecessary film frames; a giant balance scale compares useful meaning against perfect recording; top text exactly “Ý NGHĨA QUAN TRỌNG HƠN CHI TIẾT”', ['Ý NGHĨA QUAN TRỌNG HƠN CHI TIẾT']),
('A lively dinner scene repeated as a two-panel comparison: foreground protagonist remembers a friend being upset but cannot place exact words or dishes; midground table carries plates, cup, chair positions and expressive family stick figures; background memory cloud preserves a large red emotional face while small object details fade and swap positions; arrows separate central meaning from missing details; labels exactly “Ý CHÍNH” and “CHI TIẾT”', ['Ý CHÍNH','CHI TIẾT']),
('A classroom DRM experiment with a researcher presenting word cards illustrated by a bed, blanket, dream cloud, tired face, alarm clock and resting figure; foreground participant confidently selects an extra card marked “NGỦ” although it was absent; midground checklist shows the original six concepts; background brain-shaped web connects every card toward the invented central word; red title exactly “NÃO TỰ ĐIỀN TỪ CÒN THIẾU”', ['NGỦ','NÃO TỰ ĐIỀN TỪ CÒN THIẾU']),
('A memory-source control room where the protagonist sorts identical information cards into four channels: an eye for direct sight, an ear for heard speech, a phone for online reading and a thought cloud for imagination; midground conveyor accidentally sends the phone comment into the expert folder and an imagined locked door into the lived-event folder; background source map has crossed arrows and warning lights; title exactly “LỖI GIÁM SÁT NGUỒN”', ['LỖI GIÁM SÁT NGUỒN']),
('A detailed shopping mall memory grows across three connected panels: first the protagonist merely imagines being lost, second repeated thought bubbles add a store sign, relative face, food stall and red balloon, third the adult protagonist treats the richly colored scene as childhood history; midground escalator, benches, map kiosk and crowd provide context; background arrows show repetition increasing familiarity; title exactly “TƯỞNG TƯỢNG THÀNH KÝ ỨC”', ['TƯỞNG TƯỢNG THÀNH KÝ ỨC']),
('A neuroscience laboratory metaphor: foreground protagonist pulls an old fear-memory file from a brain-shaped cabinet; the file becomes soft puzzle pieces on a workbench where new red and blue fragments can enter; midground two researcher stick figures observe a simple animal fear-maze diagram, bell icon and measurement chart; background sequence shows stable memory, recalled flexible memory and restored memory; labels exactly “GỢI LẠI”, “LINH HOẠT”, “TÁI CỦNG CỐ”', ['GỢI LẠI','LINH HOẠT','TÁI CỦNG CỐ']),
('A grand memory museum with seven crooked doorways around the protagonist, each doorway visualizing a different failure: fading photograph, intrusive arrow, biased mirror, wrong source tag, blocked lock, persistent storm cloud and misplaced object; midground guide figure resembling a researcher points at a large brain map; background shelves mix lost details and painfully persistent red memories; title exactly “BẢY LỖI CỦA KÝ ỨC”', ['BẢY LỖI CỦA KÝ ỨC']),
('Courtroom split-screen: foreground left witness hesitates while holding an accurate small scene card, foreground right witness speaks confidently while holding an incorrect vivid card; midground judge, jury, microphone, evidence table and confidence meter; background scales of justice compare a tall red confidence bar with a separate blue accuracy bar; bold equation at top exactly “TỰ TIN ≠ CHÍNH XÁC”', ['TỰ TIN ≠ CHÍNH XÁC']),
('A police interview room rich with context: foreground sincere witness studies a fair lineup while an investigator uses neutral posture; midground alternate inset shows a leading question bubble, confirming thumbs-up and two witnesses contaminating each other; background evidence board contains camera footage, timestamp, map and fingerprints independent of memory; green procedure arrows lead from first identification to recorded confidence; title exactly “LỜI KHAI CẦN KIỂM CHỨNG”', ['LỜI KHAI CẦN KIỂM CHỨNG']),
('A modern phone-filled room where the protagonist is surrounded by a doctored photo, cropped video, wrongly captioned old image and repeated group-chat story; midground algorithm conveyor sends similar cards back again and again; background gradually transforms a gray unfamiliar claim into a bright familiar memory mural; arrows show repetition becoming familiarity and familiarity masquerading as truth; title exactly “QUEN THUỘC KHÔNG PHẢI SỰ THẬT”', ['QUEN THUỘC KHÔNG PHẢI SỰ THẬT']),
('At a kitchen doorway immediately after an argument, the protagonist writes observations in a notebook while the other figure speaks loudly and closes a door; foreground notebook has two columns with icons for direct sight and interpretation; midground clock, phone recorder, tipped chair and closed door anchor the event; background later gossip clouds remain outside a protective boundary; label exactly “GHI LẠI SỚM” and comparison text “QUAN SÁT” versus “SUY LUẬN”', ['GHI LẠI SỚM','QUAN SÁT','SUY LUẬN']),
('A two-lane interview diagram inside the same investigation setting: left lane uses an open question bubble and lets several possible event cards remain; right lane uses a leading accusation bubble that forces one red threat card into memory; foreground protagonist attaches source tags shaped like eye, ear, phone and thought cloud; midground notebook records who, where and when; background yellow arrows trace every claim back to its origin; title exactly “HỎI MỞ, GHI NGUỒN”', ['HỎI MỞ, GHI NGUỒN']),
('A chronological archive desk with the protagonist preserving an original message, dated diary, raw photo and voice recording in transparent folders; midground a later interpretation is added on a new dated sheet instead of overwriting the old page; background timeline separates “LÚC XẢY RA” from “HIỂU VỀ SAU”, with locks protecting original files and an edited page crossed out; top text exactly “GIỮ PHIÊN BẢN BAN ĐẦU”', ['LÚC XẢY RA','HIỂU VỀ SAU','GIỮ PHIÊN BẢN BAN ĐẦU']),
('An evidence investigation table where one repeated story splits into ten echo bubbles but all arrows return to one source; foreground protagonist compares these echoes against independent clock data, location map, original photo, document and separately recorded witness; midground three agreeing people are linked by a conversation line showing non-independence; background balance scale favors independent evidence; title exactly “TÌM BẰNG CHỨNG ĐỘC LẬP”', ['TÌM BẰNG CHỨNG ĐỘC LẬP']),
('A calm conversation scene where the protagonist uses four labeled cards to grade certainty: a clear eye memory, a vague feeling cloud, a speech card received from another person and a deduction puzzle; midground two disagreeing figures lower defensive shields as room for correction opens between them; background branching path allows evidence to update the story; top text exactly “KHÔNG CHẮC CŨNG LÀ CHÍNH XÁC”', ['KHÔNG CHẮC CŨNG LÀ CHÍNH XÁC']),
('A balanced library of personal memories: foreground protagonist carries a valuable memory book toward a verification desk rather than throwing it away; midground three consequence windows show a courtroom verdict, a strained relationship and a large belief monument; background librarian compares the memory narrative with documents, images and timelines; a scale balances trust and checking; title exactly “TIN, NHƯNG PHẢI KIỂM CHỨNG”', ['TIN, NHƯNG PHẢI KIỂM CHỨNG']),
('Two stick figures argue across the same dinner table while transparent memory reconstructions float behind them: one version emphasizes an angry face and red cup, the other a sad face and blue chair; midground shared objects remain while extra details differ; background arrows reveal different attention, later stories and repeated recall feeding each version; a central detective board asks three Vietnamese questions; title exactly “HAI KÝ ỨC ĐỀU CÓ THỂ CHÂN THÀNH”', ['HAI KÝ ỨC ĐỀU CÓ THỂ CHÂN THÀNH']),
('A near-future media storm surrounds the protagonist with an artificial face image, fake audio waveform, endless news cards and a rapidly forming crowd memory mural; midground ancient brain tools appear as four gears for familiarity, coherence, guessed source and gist; background algorithm screens manufacture increasingly convincing versions while an evidence lighthouse remains visible; title exactly “VẬT LIỆU GIẢ, CẢM GIÁC THẬT”', ['VẬT LIỆU GIẢ, CẢM GIÁC THẬT']),
('Inside a theater shaped like a brain, the protagonist watches memory actors rebuild the same scene on stage each time it is recalled; foreground script pages are revised, props move and one new character enters; midground storyteller brain connects emotion, image, speech and belief with colored threads; background shows three successive versions becoming smoother but less faithful; title exactly “MỖI LẦN NHỚ LÀ MỘT LẦN DỰNG LẠI”', ['MỖI LẦN NHỚ LÀ MỘT LẦN DỰNG LẠI']),
('Closing mirror of scene one: foreground protagonist calmly holds the same vivid family-dinner memory frame beside an evidence folder showing it never occurred; midground sensory icons and strong heartbeat prove vividness while a separate historical timeline remains blank; background brain workshop is visible, now understood as a reconstruction system rather than a camera; a balanced caption separates certainty from occurrence; final text exactly “SỐNG ĐỘNG KHÔNG CÓ NGHĨA ĐÃ XẢY RA”', ['SỐNG ĐỘNG KHÔNG CÓ NGHĨA ĐÃ XẢY RA'])
]
assert len(scenes) == len(timeline) == 23
items=[]
for row,(desc,vt) in zip(timeline,scenes):
    prompt=f'{prefix} {required}, {desc}, use the channel palette orange #F5820D, cobalt blue #2D5FBF, grass green #3A9E3A, golden yellow #F5C518, red #D94040, brown #8B5E3C, sky blue #6EB5E8, tan #C4965A and white, maintain the recurring protagonist design and visual continuity, all visible words must be exactly the listed Vietnamese text and no English words, {suffix}'
    items.append({'id':row['id'],'text':row['text'],'start':row['start'],'end':row['end'],'duration':row['duration'],'prompt':prompt,'visible_text':vt,'output_path':str(p/f'images/scenes/scene_{row["id"]:03d}.png')})
out=p/'prompts/image_prompts.json'; tmp=out.with_suffix('.json.tmp')
tmp.write_text(json.dumps({'version':1,'language':'vi','items':items},ensure_ascii=False,indent=2)+'\n'); os.replace(tmp,out)
print(out)
