#!/usr/bin/env python3
from pathlib import Path
import subprocess,sys,hashlib,json,datetime
R=Path('/data/video-pipeline/HaTramAudio/project/027-Nguoi-Thua-Ke-Khong-Nhan-Chiec-Ghe-Danh-San');G=Path.home()/'.hermes/skills/content-creation/tao-anh/scripts/generate_image.py';W=R/'work/artwork';out=R/'image/provider/intro_poster-provider.png'
p='''Create an exact 16:9 landscape cinematic Vietnamese audiobook title poster, master 1920x1080, full bleed edge to edge. Keep every text glyph and all Vietnamese diacritics within a 15 percent safe margin from every edge. Rainy traditional canal street beside a restored wood workshop. Foreground adult Vietnamese woman with shoulder-length black hair in a cream coat holding one antique brass key and one plain brown document folder. Behind her, a second adult Vietnamese woman clearly wearing a dark navy work jacket. One empty wooden chair. Restrained teal-gray and warm amber palette, minimal composition, no villain and no final governance reveal. All buildings, signs, documents, walls and props must contain no letters, numbers, symbols, pseudo-text or logos. Provider must render exactly these three text blocks and no other text: "Hạ Trâm Audio"; "Người Thừa Kế Không Nhận Chiếc Ghế Dành Sẵ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". Render the complete title and branding at comfortable size, fully visible, uncropped. No final period, no extra text, no watermark, no collage, no slide.'''
rec={'schema_version':1,'project_id':'027','run_id':'run-20260722T063859Z-aa8eca81','asset':'intro_poster','status':'creating','reason':'intro_text_crop_gate','prompt_sha256':hashlib.sha256(p.encode()).hexdigest(),'created_at':datetime.datetime.now(datetime.timezone.utc).isoformat()};(W/'intro_poster-regenerate.intent.json').write_text(json.dumps(rec,ensure_ascii=False,indent=2)+'\n');x=subprocess.run([sys.executable,str(G),'--prompt',p,'--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,'sha256':hashlib.sha256(b).hexdigest(),'bytes':len(b),'completed_at':datetime.datetime.now(datetime.timezone.utc).isoformat()});(W/'intro_poster-regenerate.receipt.json').write_text(json.dumps(rec,ensure_ascii=False,indent=2)+'\n');print(json.dumps({'status':'regenerated','sha256':rec['sha256']}))
