#!/usr/bin/env python3
from pathlib import Path
import sys,json,hashlib,datetime
sys.path.insert(0,'/opt/OpenMontage')
from tools.graphics.cx_image import CXImage
P='gacmai_20260717_104203';R=Path('/data/video-pipeline/GacMaiAudio/project')/P;A=R/'artifacts';O=R/'assets/images/candidates';O.mkdir(parents=True,exist_ok=True)
status=json.loads((R/'status.json').read_text());release=json.loads((A/'story_release_manifest.json').read_text())
if status.get('cx_authorized') is not True or status.get('story_sha256')!=release.get('story_sha256'):raise SystemExit('CX authorization mismatch')
style='premium cinematic illustrated Vietnamese audio drama, semi-realistic polished illustration, dark teal near-black icy blue palette, cream and pale-gold typography, controlled red accents, dramatic key light, layered atmospheric depth, no medical imagery, no waveform, no ECG, no watermark, no interface, all props completely blank and unlabeled, no letters, numbers, notation or pseudo-text except exact requested typography'
prompt=f'''{style}. 16:9 opening title card. Archival reel-to-reel tape in a dim preservation room, one tiny missing interval in the tape loop casting a shadow shaped like a Vietnamese communal-house roof, dust in a narrow beam, zero people. Stylized reel machine has blank surfaces, no meter lettering or control markings; papers and boxes blank. Exact readable Vietnamese typography only: "GÁC MÁI AUDIO" and "NỬA NHỊP KHÔNG THUỘC VỀ AI". High-contrast distressed serif, centered cinematic composition. ABSOLUTELY NO divider, horizontal line, zigzag, pulse mark, ornament or symbol between or around the two text lines.'''
out=O/'intro_v3.png'
if out.exists():raise SystemExit(f'refuse overwrite {out}')
res=CXImage().execute({'prompt':prompt,'model':'cx/gpt-5.5-image','size':'1536x864','quality':'high','output_format':'png','n':1,'output_path':str(out)})
if not res.success or not out.exists():raise RuntimeError(f'intro_v3.png: {res.error} {res.data}')
receipt={'status':'passed','provider':'CXImage','story_sha256':status['story_sha256'],'items':[{'name':'intro_v3.png','path':str(out),'sha256':hashlib.sha256(out.read_bytes()).hexdigest(),'bytes':out.stat().st_size}],'completed_at':datetime.datetime.now(datetime.timezone.utc).isoformat()};(A/'cx_visual_generation_intro_v3_receipt.json').write_text(json.dumps(receipt,indent=2)+'\n');print(json.dumps(receipt))
