
    j              	       N   d dl Z d dlZd dlZd dlZd dlZd dlmZmZ d dlmZ d dl	m
Z
  e
d          Zedz  Zedz  Z e
d          Zed	z  Zed
z  ZdZdZdZdZdg dfddgfddgfddgfdddgfdg dfdg dfgZd Zd Zd  Zd! Zd" Zed#k    r e e                      dS )$    N)ThreadPoolExecutoras_completed)datetime)PathzT/data/video-pipeline/Youtube-Video-Maker/Project/31052026-001-Nguyen-Hue-Quang-Trungzscript/scenes.jsonz$script/character_reference_plan.jsonzD/home/hermes/.hermes/skills/media/gen-img-gpt/scripts/gen_img_gpt.pyz(logs/step06_first50_images_manifest.jsonz"logs/step06_first50_images_run.log2      a  [VISUAL STYLE]
Vietnamese historical ink-wash storytelling illustration, 16:9 horizontal composition/canvas, centered irregular ink-wash window on warm antique cream paper. The painted image should occupy only about 65-70% of the page, leaving 30-35% negative space of antique paper. Do not fill the whole frame. Balanced breathing room, light page composition, handcrafted historical mood, soft brown-black ink, transparent watercolor wash, muted earthy palette.

[HISTORICAL GROUNDING]
Late 18th-century Dai Viet during the Tay Son uprising and the Quang Trung era; Binh Dinh highlands, Phu Xuan, Gia Dinh river country, Bac Ha and Thang Long; Vietnamese villages, royal courts, river fleets, war elephants, muskets, spears, drums, banners, bamboo, wood, earthworks, winter campaign atmosphere. Keep Vietnamese Tay Son/Le/Nguyen clothing distinct from Qing and Siamese troops. Avoid fantasy drift, European drift, and wrong cultural costumes.
a  [NEGATIVE EXCLUSIONS]
Not a character sheet, not a turnaround sheet, not a concept art board, not multiple views, not a lineup, not floating costume parts, not isolated armor pieces, not a design sheet, not a model sheet, not a reference layout, not modern objects, not watermark, not logo, not text labels, not poster typography, not edge-to-edge full-frame illustration, not glossy 3D, not game key art.
znguyen-hue_ref.png)u   Nguyễn HuệzQuang Trungu   ông zvua Quang Trungznguyen-anh_ref.pngu   Nguyễn Ánhzle-chieu-thong_ref.pngu   Lê Chiêu Thốngzton-si-nghi_ref.pngu   Tôn Sĩ Nghịzle-ngoc-han_ref.pngu   Lê Ngọc Hânu   công chúaz*tay-son-soldiers-and-common-people_ref.png)u	   Tây Sơnu   nghĩa quânu	   quân sĩu   dân chúngu   người línhzxiem-and-qing-armies_ref.png)u   quân Xiêmu   Xiêmu   quân ThanhThanhu   Sầm Nghi Đốngc                 ^   t           j                            dd           dt          j                                        d           d|  }t          |d           t                               dd	
          5 }|                    |dz              d d d            d S # 1 swxY w Y   d S )NT)parentsexist_ok[secondstimespecz] )flushautf-8encoding
)	RUN_LOGparentmkdirr   now	isoformatprintopenwrite)msglinefhs      r/data/video-pipeline/Youtube-Video-Maker/Project/31052026-001-Nguyen-Hue-Quang-Trung/scripts_run_step06_first50.pylogr#   )   s    N555Dx|~~''';;DDsDDD	$d	cG	,	, 
                 s   <B""B&)B&c                    g }|                                  t          D ]c\  }}t          fd|D                       rCt          dz  |z  }|                                r"|                    t          |                     d|d d         S )Nc              3   D   K   | ]}|                                 v V  d S Nlower).0wr(   s     r"   	<genexpr>z!refs_for_scene.<locals>.<genexpr>5   s0      11aqwwyyE!111111    zimages/refs   )r(   KEYWORDSanyPROJECTexistsappendstr)textrefsfilewordspr(   s        @r"   refs_for_scener9   1   s    	D
**,,E $ $e1111511111 	$m#D(Axxzz $CFF###8Or,   c                 @   |                      d          p|                      dd          |                      d          dk    rd dt           S g d}t          fd	|D                       rd
nd}d|d
k    rdnd d d}d}t           d| d| dt           S )N	narrationr4    typeheadinga  [VISUAL STYLE]
Light Vietnamese old-calligraphy title-card on warm antique paper, subtle ink wash and small seal/stamp accent, airy text with breathing room, not heavy black title slam, not clean modern typography. 16:9 horizontal canvas.

[HISTORICAL GROUNDING]
Late 18th-century Dai Viet / Tay Son historical memory, antique manuscript paper, Vietnamese calligraphy mood.

[SCENE ACTION / FRAMING]
Create a chapter heading image for this exact Vietnamese title: z. Keep the card elegant, readable, spacious, and handcrafted.

[CHARACTER IDENTITY]
No character portrait needed unless a very subtle historical silhouette supports the title.

)	u   trậnu   quânu   đánhu   chiếnu   pháou   đồnu   thủy quânu   xâm lượcu   tháo chạyc              3   D   K   | ]}|                                 v V  d S r&   r'   )r)   r*   r;   s     r"   r+   zbuild_prompt.<locals>.<genexpr>M   s2      HHa1	 1 11HHHHHHr,   battlegenericzOne cinematic narrative zbattle z)scene showing this exact narration beat: z. Clear environment, clear focal action, readable emotional staging, historically grounded props and setting, suitable for a story video frame.zUse attached character references only for identity consistency when applicable: face, age, hair, expression tendency, costume details, and armor language. Do not reproduce the reference sheets themselves.z
[SCENE ACTION / FRAMING]
z

[CHARACTER IDENTITY]
z

)getNEGr/   STYLE)scenebattle_wordskindactioncharr;   s        @r"   build_promptrJ   <   s   		+&&>%))F2*>*>IyyI%%	 BK	 	 	 	 		 wvvLHHHH<HHHHHW88iD QT8^^		  Q  Qv  Q  Q  QF [D 	 		 	
 	 	 	 	 	r,   c                    | d         }t           dz  | dz  }|                                r0|                                j        dk    r|dt	          |          dS t
          j        t	          t                    dt          |           dt	          |          d	d
dd
dd
ddddddg}t          | 
                    d          p| 
                    dd                    D ]	}|d|gz  }
t          j        |ddd          }|j        dk    r|d|j        p|j        dd          dS |                                r|                                j        dk     r|ddS |d t	          |          |                                j        d!S )"Nscene_idzimages/scenesz.pngi  skipped_existing)rL   statusoutput_pathz--promptz--outputz--sizeautoz	--qualityz--backgroundz--image-detailhighz--output-formatpngz--n1r;   r4   r<   z--input-refTi  )r4   capture_outputtimeoutr   failedi0)rL   rN   errorfailed_empty_output)rL   rN   	generated)rL   rN   rO   bytes)r0   r1   statst_sizer3   sys
executable
GEN_SCRIPTrJ   r9   rB   
subprocessrun
returncodestderrstdout)rE   sidoutcmdrefprocs         r"   generaterj   Z   s   jC3,C
zz|| S

*4//(:SRRR	J
<3F3FzRUVYRZRZ[cdjkvw}  M  NT  Ue  fl  m~  D  EJ  KN  	OCeii44L		&8L8LMM $ $s##	T#	F	F	FD$+:TV[V\V\9]^^^::<< ?388::-d22(=>>>Kc#hhsxxzzOabbbr,   c            	      f   t           j                            d          st          d          t	          j        t                              d                    } |                     d          st          d          t	          j        t                              d                    d         d t                   }dd	t          t          t          j                                        d
          dg d}t                              t	          j        |dd          d           t#          dt           dt           d           t%          t                    5 fd|D             }t'          |          D ]}|                                }|d                             |           t#          |d          d|d                     t                              t	          j        |dd          d           |d                             d          rDd|d<   t                              t	          j        |dd          d            d d d            dS 	 d d d            n# 1 swxY w Y   t/          d |d         D                       }t          j                                        d
          |d<   |t          k    rdnd|d<   ||d <   t                              t	          j        |dd          d           t#          d!| d"t           d#           |t          k    rd$ndS )%NGEN_IMG_API_KEYzGEN_IMG_API_KEY missingr   r   approved_for_scene_imagesz*Step 05 refs not approved for scene imagesscenesz#31052026-001-Nguyen-Hue-Quang-Trung6_limited_first50r   r   running)
project_idsteplimitworkers
started_atrN   resultsF   )ensure_asciiindentzStart Step 06 limited first z scenes with z workers)max_workersc                 H    i | ]}                     t          |          |S  )submitrj   )r)   sexs     r"   
<dictcomp>zmain.<locals>.<dictcomp>u   s)    666!bii##A666r,   rv   rL    rN   rV      c              3   .   K   | ]}|d          dv dV  dS )rN   )rY   rM   r   Nr|   )r)   rs     r"   r+   zmain.<locals>.<genexpr>   s1      
]
]Qx[<\-\-\1-\-\-\-\
]
]r,   completed_at#completed_limited_50_pending_review
incompletegenerated_or_existing_countzStep 06 limited complete: /z*; stopping before scene_051 and thumbnailsr   )osenvironrB   
SystemExitjsonloadsREF_PLAN_PATH	read_textSCENES_PATHLIMITWORKERSr   r   r   MANIFEST_PATH
write_textdumpsr#   r   r   resultr2   
startswithsum)ref_planrn   manifestfutsfutresokr   s          @r"   mainr   j   s   :>>+,, 42333Z///AABBH<<344 GEFFF:k++W+==>>xH%PF@H[dit{  JR  JV  JX  JX  Jb  Jb  lu  Jb  Jv  Jv  @I  TV  W  WHTZe1MMMW^___LuLL7LLLMMM		0	0	0 
B6666v666%% 	 	C

CY&&s+++3z?44S]44555$$TZeST%U%U%U_f$ggg8}''11 #+"((H%WX)Y)Y)Ycj(kkk
 
 
 
 
 
 
 
	
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
]
]hy)
]
]
]]]B%\^^55y5IIH^@BE		<<|HX,.H*+TZe1MMMW^___[R[[%[[[\\\E		11q s    C2I-I--I14I1__main__)r   r   rer`   r]   concurrent.futuresr   r   r   pathlibr   r0   r   r   r_   r   r   r   r   rD   rC   r.   r#   r9   rJ   rj   r   __name__r   r|   r,   r"   <module>r      s    				 				     



 ? ? ? ? ? ? ? ?            
$e
f
f,,@@TXYY
DD
8
8

	
 UUUVO,- 456./0.}=>13z3z3z{#%g%g%gh    	 	 	<c c c ! ! !: Z
*TTVV

 r,   