import os, sys, json, hashlib
from pathlib import Path

def load_env(path):
    for line in Path(path).read_text(errors='ignore').splitlines():
        line=line.strip()
        if not line or line.startswith('#') or '=' not in line:
            continue
        key, value = line.split('=', 1)
        os.environ.setdefault(key.strip(), value.strip().strip('"\\\''))

load_env('/opt/OpenMontage/.env')
sys.path.insert(0, '/opt/OpenMontage')
from tools.graphics.cx_image import CXImage
P='gacmai_20260718_075153'; R=Path('/data/video-pipeline/GacMaiAudio/project')/P; out=R/'assets/images'; out.mkdir(parents=True, exist_ok=True)
base='Premium cinematic semi-realistic illustrated Vietnamese audio-drama campaign, cohesive painterly technique, warm amber and teal floodplain atmosphere, serious editorial composition, no photography, no plastic 3D, no flat clip-art, no watermark, no pseudo-text, no seals, no extra writing. '
prompts={
'intro_campaign_rev1.png':base+'Native 16:9 opening poster. Exactly six Vietnamese adults, exactly three women and three men, full faces, protagonist Võ Thanh Hà dominant at center holding a rolled floodplain map; broad river floodplain after receding water, communal boat path, survey stakes, distant embankment plan. Include exactly these readable strings and no other text: ĐƯỜNG NƯỚC TRỞ VỀ; Gác Mái Audio; Truyện độc quyền, nghiêm cấm sao chép dưới mọi hình thức.',
'left_campaign_rev1.png':base+'Native 16:9 left rail campaign panel, no people. River-floodplain textures, survey lines, reeds and communal path, typography only with exactly: Gác Mái Audio; Like; Share; Subscribe. No other text.',
'right_campaign_rev1.png':base+'Native 16:9 right rail campaign panel. Exactly six Vietnamese adults, exactly three women and three men, all full faces, Võ Thanh Hà dominant, same cast and lighting as campaign. Include only the title text ĐƯỜNG NƯỚC TRỞ VỀ. No names or other text.'}
provider=CXImage(); results=[]
for name,prompt in prompts.items():
 path=out/name
 r=provider.execute({'prompt':prompt,'model':'cx/gpt-5.5-image','size':'1920x1080','quality':'high','background':'auto','image_detail':'high','output_format':'png','n':1,'output_path':str(path)})
 if not r.success: raise SystemExit(f'{name}: {r.error}')
 results.append({'file':str(path),'sha256':hashlib.sha256(path.read_bytes()).hexdigest(),'provider':r.data.get('provider'),'model':r.model})
print(json.dumps({'status':'passed','results':results},ensure_ascii=False))
