#!/usr/bin/env python3
from pathlib import Path
import json,hashlib,datetime,subprocess,sys
R=Path('/data/video-pipeline/HaTramAudio/project/030-Nguoi-Khong-Co-Ten-Trong-Danh-Sach-So-Tan');W=R/'work/artwork';OUT=R/'image/provider';G=Path.home()/'.hermes/skills/content-creation/tao-anh/scripts/generate_image.py';RUN='run-20260722T163045Z-9f2c6fbf';CANON='380204871f7899308c1a322d1e531e6a625c1de9394ee177fe0bbd46d57a1484'
prompts=[
('intro_poster','''Create an exact 16:9 landscape cinematic Vietnamese audiobook title poster, full bleed, all text inside 15 percent safe margins. Rainy reservoir town at dusk, spillway and rescue lights, foreground adult Vietnamese woman water engineer with shoulder-length black hair in a pale yellow raincoat holding a folded evacuation map and flashlight, behind her an adult Vietnamese male rescue captain in orange rescue jacket beside two rescue boats, distant homes with signal lights. Restrained storm blue, slate gray and warm amber palette, serious but hopeful, no disaster spectacle, no injured people, no romance embrace, no final governance reveal. All signs, maps, buildings and props must be blank with no pseudo-text. Provider must render exactly these three text blocks and no other text: "Hạ Trâm Audio"; "Người Không Có Tên Trong Danh Sách Sơ Tán"; "Truyện được phát độc quyền tại Hạ Trâm Audio, nghiêm cấm sao chép dưới mọi hình thức". Complete Vietnamese diacritics, no final period, no watermark, no collage, no slide.'''),
('left_panel','''Create an exact 656:1080 portrait audio branding panel, full bleed, text within safe margins. Rainy control-room window overlooking reservoir lights, studio microphone, headphones, warm emergency lamp, folded map with completely blank surface, no people. Storm blue and amber cinematic minimal composition. Provider must render exactly two text blocks and no other text: "Hạ Trâm Audio"; "Like • Chia sẻ • Đăng ký". No title, no plot text, no pseudo-text, no watermark, no collage, no slide.'''),
('right_panel','''Create an exact 656:1080 portrait Vietnamese audiobook story panel, full bleed, all text inside 12 percent safe margins. Same adult Vietnamese woman as poster, shoulder-length black hair, pale yellow raincoat, holding folded evacuation map and flashlight; adult Vietnamese male rescue captain behind her wearing a clear orange rescue jacket beside two rescue boats; rainy reservoir town and distant signal lights. No physical contact, no injured people, no disaster spectacle, no final governance reveal. All signs, maps and props blank with no pseudo-text. Provider must render exactly these three text blocks and no other text: "Hạ Trâm Audio"; "Người Không Có Tên Trong Danh Sách Sơ Tán"; "Truyện được phát độc quyền tại Hạ Trâm Audio, nghiêm cấm sao chép dưới mọi hình thức". Complete Vietnamese diacritics, no final period, no watermark, no collage, no slide.''')]
for name,prompt in prompts:
 out=OUT/f'{name}-provider.png';rec={'schema_version':1,'project_id':'030','run_id':RUN,'asset':name,'source_canon_sha256':CANON,'prompt_sha256':hashlib.sha256(prompt.encode()).hexdigest(),'status':'creating','provider_skill':'tao-anh','created_at':datetime.datetime.now(datetime.timezone.utc).isoformat()};(W/f'{name}.intent.json').write_text(json.dumps(rec,ensure_ascii=False,indent=2)+'\n');x=subprocess.run([sys.executable,str(G),'--prompt',prompt,'--output',str(out),'--n','1','--size','auto','--quality','auto','--background','auto','--detail','high','--format','png','--timeout','600'],capture_output=True,text=True,timeout=720);assert x.returncode==0 and out.exists(),(x.stderr or x.stdout)[-1000:];b=out.read_bytes();rec.update({'status':'completed','verified':True,'path':str(out.relative_to(R)),'sha256':hashlib.sha256(b).hexdigest(),'bytes':len(b),'completed_at':datetime.datetime.now(datetime.timezone.utc).isoformat()});(W/f'{name}.receipt.json').write_text(json.dumps(rec,ensure_ascii=False,indent=2)+'\n')
print(json.dumps({'status':'provider_artwork_completed','assets':3},ensure_ascii=False))
