#!/usr/bin/env python3
from pathlib import Path
import json,hashlib,datetime,subprocess,sys
R=Path('/data/video-pipeline/HaTramAudio/project/031-Buoi-Dien-Cuoi-Truoc-Ngay-Tot-Nghiep');W=R/'work/artwork';OUT=R/'image/provider';G=Path.home()/'.hermes/skills/content-creation/tao-anh/scripts/generate_image.py';RUN='run-20260723T010035Z-09393c41';CANON='8316d0fc4fc1f28785ce23216e9254e5eb561e4e56847ff464f71fdba8bac4f7'
prompts=[
('intro_poster','''Create an exact 16:9 landscape cinematic Vietnamese university youth-romance audiobook poster, full bleed, all text inside 15 percent safe margins. Night inside a university experimental theatre in Hangzhou, red velvet curtain, empty audience seats, warm work light and small green stage signal. Foreground: adult 22-year-old Chinese female stage manager with shoulder-length black hair, simple cream cardigan over dark student clothes, holding a cue clipboard and headset. Background: adult 23-year-old Chinese male sound-design student in dark blue overshirt at a sound console, holding one side of a two-channel black headset. They are separate, focused, no embrace. Graduation-project atmosphere, hopeful and restrained, no luxury, no wedding, no disaster, no spoiler of scholarship result. All consoles, papers and signs blank with no pseudo-text. Provider must render exactly these three text blocks and no other text: "Hạ Trâm Audio"; "Buổi Diễn Cuối Trước Ngày Tốt Nghiệp"; "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". Exact 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 inside safe margins. Dark university theatre sound booth overlooking red curtain and warm stage work light, vintage studio microphone, headphones, compact sound console, no people. Deep navy, burgundy and warm amber cinematic palette. Consoles and papers blank with no pseudo-text. Provider must render exactly two text blocks and no other text: "Hạ Trâm Audio"; "Like • Chia sẻ • Đăng ký". No story title, no plot text, no watermark, no collage, no slide.'''),
('right_panel','''Create an exact 656:1080 portrait Vietnamese university youth-romance audiobook story panel, full bleed, all text inside 12 percent safe margins. Same adult Chinese female stage manager as poster, shoulder-length black hair, cream cardigan, holding cue clipboard and headset near a red theatre curtain; same adult Chinese male sound-design student behind her at sound console holding one side of a black two-channel headset. Warm work light and small green stage signal, graduation project mood. No embrace, no wedding, no luxury, no scholarship-result spoiler. All consoles, papers and signs blank with no pseudo-text. Provider must render exactly these three text blocks and no other text: "Hạ Trâm Audio"; "Buổi Diễn Cuối Trước Ngày Tốt Nghiệp"; "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". Exact 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':'031','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))
