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/right_panel-provider.png'
p='''Create an exact 656:1080 aspect-ratio portrait panel, master 1312x2160, full bleed edge to edge with no padding or borders. Keep every required text block within a 12 percent safe margin from all edges. Cinematic minimal upright portrait, exactly the same Vietnamese woman as the approved poster: shoulder-length black hair, cream coat, holding one antique brass key and a brown document folder. Behind her, clearly visible at medium distance, is a SECOND adult Vietnamese woman with shoulder-length dark hair wearing a DISTINCT DARK NAVY-BLUE WORK JACKET, no umbrella, standing beside a restored wood workshop. A single empty wooden chair is visible. Rainy traditional canal street, teal gray and warm amber, no physical contact, no villain, no final governance reveal. ALL storefront signs, plaques, tools, documents, walls, windows, props and background objects must be completely blank with no letters, words, numbers, symbols, pseudo-text, logos or watermarks. Do not render a workshop sign. Provider must render exactly these 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". No final period, no extra text, no watermark, no collage, no slide.'''
intent={'project_id':'027','run_id':'run-20260722T063859Z-aa8eca81','asset':'right_panel','status':'creating','reason':'identity_gate_regenerate','prompt_sha256':hashlib.sha256(p.encode()).hexdigest(),'created_at':datetime.datetime.now(datetime.timezone.utc).isoformat()};(W/'right_panel-regenerate.intent.json').write_text(json.dumps(intent,ensure_ascii=False,indent=2)+'\n');r=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 r.returncode==0 and out.exists();b=out.read_bytes();intent.update({'status':'completed','verified':True,'sha256':hashlib.sha256(b).hexdigest(),'bytes':len(b),'completed_at':datetime.datetime.now(datetime.timezone.utc).isoformat()});(W/'right_panel-regenerate.receipt.json').write_text(json.dumps(intent,ensure_ascii=False,indent=2)+'\n');print(json.dumps({'status':'regenerated','sha256':intent['sha256']}))

