
    *FjF!                     h   d dl Zd dlZd dlZ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
  e
d          Z e
d          Zedz  Zedz  Zedz  Zedz  Zed	z  Zed
z  Z eej                            dd                    ZdZdZdZd Zd Zd Zd Zd Zd Zd Z d Z!d Z"e#dk    r e"             dS dS )    N)PathzH/data/video-pipeline/Youtube-Video-Maker/Project/02072026-001-Nha-NguyenzD/home/hermes/.hermes/skills/media/gen-img-gpt/scripts/gen_img_gpt.pyzscript/scenes.jsonz$script/character_reference_plan.jsonzimages/sceneszoutput/thumbnailszlogs/step06_images_run.logz logs/step06_images_manifest.jsonSTEP06_WORKERS5a  16:9 horizontal historical storytelling image, centered irregular ink-wash narrative window on warm antique cream paper, painted content occupies only about 65-70 percent of page with 30-35 percent clean antique paper negative space, handcrafted Vietnamese co phong feeling, muted brown black charcoal watercolor wash, not modern, not full-frame glossy digital poster, not fantasy splash art, not 3D game key art, no text, no watermark.z16:9 horizontal light Vietnamese old-calligraphy title-card on warm antique paper, subtle ink wash and small red seal stamp accent, airy text with breathing room, not heavy black title slam, not clean modern typography.zAvoid modern objects, wrong culture, fantasy armor, samurai, character sheet layout, model sheet, multiple views, floating costume parts, text labels, watermark, logo, glossy poster, edge-to-edge full-frame painting.c                 4   t          j        d|           } d                    d | D                       } |                     dd                              dd          } t	          j        dd	|                               d	                                          S )
NNFD c              3   J   K   | ]}t          j        |          d k    |V  dS )MnN)unicodedatacategory).0cs     f/data/video-pipeline/Youtube-Video-Maker/Project/02072026-001-Nha-Nguyen/scripts_run_step_06_images.py	<genexpr>zslug.<locals>.<genexpr>   s9      /^/^a@TUV@W@WY]@]@]@]@]@]@]/^/^    u   đdu   ĐDz[^a-zA-Z0-9]+-)r   	normalizejoinreplaceresubstriplower)ss    r   slugr      s    E!$$A/^/^1/^/^/^(^(^abcbkbklpqtbubub}b}  C  DG  cH  cH`a6"3q))//44::<<<r   c                      i } t                                           rbt          j        t                               d                                        dg           D ] }t          |d                   | |d         <   !| S )Nutf-8encoding
referencesoutput_pathcharacter_id)PLANexistsjsonloads	read_textgetr   )refsrs     r   	load_refsr-      s    	D{{}} CDNNGN<<==AA,rRR  	C  	CAlpqr  tA  rB  mC  mCTXYZ[iYjTkTkKr   c                 2   t          j        d          | z   }t          |d           t          j                            dd           t                              dd          5 }|                    |dz              d d d            d S # 1 swxY w Y   d S )	Nz%Y-%m-%d %H:%M:%S T)flushparentsexist_okar   r    
)timestrftimeprintLOGparentmkdiropenwrite)msglinefs      r   logr@      s    	+	,	,S	0D%42H2H2H2H#*JZJZcgquJZJvJvJv	#w	'	'@1aggd4i.@.@.@@@@@@@@@@@@@@@@@@@s   &BBBc                    |                                  g }g d}|D ]\  }}|v r|                    |           t          fddD                       r|                    d           t          fddD                       r|                    d           g }|D ]F}|                    |          }|r-|                                r||vr|                    |           G|S )N))u   nguyễn ánhgia-long-nguyen-anh)zgia longrB   )u   minh mạngz	minh-mang)u   tự đứcztu-duc)u   bảo đạibao-dai)u	   hàm nghizham-nghi)u   thành tháiz
thanh-thai)u   duy tânzduy-tan)u   khải địnhz	khai-dinh)u   tôn thất thuyếtzton-that-thuyet)u   nguyễn tri phươngznguyen-tri-phuong)u   phan thanh giảnzphan-thanh-gian)u   trương địnhztruong-dinh)u   nguyễn trung trựcznguyen-trung-trucc              3       K   | ]}|v V  	d S N r   xts     r   r   zscene_refs.<locals>.<genexpr>   s?        j  ja16  j  j  j  j  j  jr   )u   phápu   thực dânu   đà nẵngu   gia địnhu
   thuận anu   hòa ướcu
   bảo hộu   đại bácu   tàu chiếngarnieru   rivièrezquan-phap-xam-luocc              3       K   | ]}|v V  	d S rE   rF   rG   s     r   r   zscene_refs.<locals>.<genexpr>   s?        U  Ua16  U  U  U  U  U  Ur   )	u   dân chúngu   sĩ phuu
   nghĩa sĩu   cần vươngu   làngu   người dânu   phong tràou   kháng phápu
   nông dânzdan-chung-va-si-phu-dai-nam)r   appendanyr*   r&   )	textr+   keysmappingtokenkoutprI   s	           @r   
scene_refsrU      s   
jjllAD h  h  hG & &aA::t{{1~~~
  j  j  j  j  i  j  j  j  j  j  M  lp  lw  lw  xL  lM  lM  lM
  U  U  U  U  T  U  U  U  U  U  A  W[  Wb  Wb  c@  WA  WA  WA
C < <
((1++;;cjjmmmJr   c           	         |                      d          dk    rt           d| d          dt           S t          |                      dd          dz   |                      dd          z   |          }|rd	nd}t           d
| d          d|                      d          p|                      d           d| dt           	S )Ntypeheadingz>
Vietnamese title card text to depict accurately if possible: 	narrationz
Subtle Nguyen dynasty motifs, Hue citadel silhouettes, imperial seals, river mist, old maps and broken treaty papers, antique paper. r    summaryzUse attached character reference image(s) only to keep identity, age, face, costume language, and temperament consistent. Do not reproduce a reference sheet. z
Historical context: Vietnam under the Nguyen dynasty from 1802 to 1945, Hue imperial court, Gia Long reunification, Minh Mang centralization, Tu Duc crisis, French invasion, Can Vuong, colonial protectorate, Bao Dai abdication.
Narration beat: z
Visual direction: visual_beatvisual_promptr4   zOne cinematic narrative scene, historically grounded Vietnamese Nguyen dynasty clothing, Hue citadel architecture, villages, rivers, court halls, treaty rooms, war camps, French gunboats only when relevant.
Negative exclusions: )r*   STYLE_HEADINGNEGrU   STYLE_SCENE)scener+   srref_notes       r   
prompt_forrd   #   sp   yy)##  A  A`efq`r  A  A  |  A  A  	A%))K++C/		)B0G0GGNNB rt  |  n  n  z|H  i	  i	  SX  Yd  Se  i	  i	  {@  {D  {D  ER  {S  {S  {q  W\  W`  W`  ap  Wq  Wq  i	  i	  u}  i	  i	  d	g	  i	  i	  i	r   c                 l   t           | d          dz  }|                                rN|                                j        dk    r1| d         dt	          |          |                                j        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d          dz   | 
                    dd          z   |          d d         D ]}|dt	          |          gz  }t          j        |ddd          }|j        dk    r.| d         dt	          |          |j        p|j        dd          dS | d         dt	          |          |                                r|                                j        nddS ) Nscene_idz.png  skipped_exists)rf   statusoutputbytes--prompt--output--sizeauto	--quality--background--image-detailhigh--output-formatpng--n1rY   r   rZ   r[      --input-refT  rN   capture_outputtimeoutr   failed0)rf   ri   rj   errorok)
OUT_SCENESr&   statst_sizestrsys
executable
GEN_SCRIPTrd   rU   r*   
subprocessrun
returncodestderrstdout)ra   r+   rS   cmdrefrT   s         r   run_oner   )   s7   eJ'----C
zz||  ^

*4//E*DU_oy|  ~A  zB  zB  KN  KS  KS  KU  KU  K]  9^  9^  2^	J
:eT3J3J:VYZ]V^V^_ghnoz  |B  CQ  RX  Yi  jp  qB  CH  IN  OR  	SC%))K33C7		)B8O8OOQUVVWYXYWYZ{{\_dqruvyrzrzc{\{\_\_nSd$tDDDA|Q5+<hX[\_X`X`jkjrj~vwv~  AF  AG  AG  jH   I   I  IZ($CgjgqgqgsgsQzQTQYQYQ[Q[QcQcyz{{{r   c                      | dk    rdnd}| dS )N16x9z!16:9 YouTube thumbnail, 1920x1080zFTikTok-safe vertical thumbnail/poster, 1080x1280 preferred compositionu  . Cinematic Vietnamese historical dynasty poster for 'NHÀ NGUYỄN - TRIỀU ĐẠI CUỐI CÙNG'. Large dramatic Nguyen emperor silhouette before Hue citadel and Bao Dai abdication seal-sword motif, shadow of French gunboat and broken treaty papers, dark sepia bronze black palette, parchment texture, large readable metallic-gold Vietnamese brush lettering over irregular black ink-splash title panel. Historically grounded, not modern, not fantasy, no watermark.rF   )kindaspects     r   thumb_promptr   1   s5    26,,..  EMF  i  i  i  ir   c                    |                                 rH|                                j        dk    r+| dt          |          |                                j        dS t          j        t          t                    dt          |           dt          |          ddddd	dd
dddddg}|                    d          p|                    d          }|r(|                                 r|dt          |          gz  }t          j
        |ddd          }|j        dk    r(| dt          |          |j        p|j        dd          dS | dt          |          |                                 r|                                j        nddS )Nrg   rh   )r   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rC   rB   ry   Trz   r{   r   r~   r   )r   ri   rj   r   r   )r&   r   r   r   r   r   r   r   r*   r   r   r   r   r   )r   rS   r+   r   rT   r,   s         r   	gen_thumbr   4   s   
zz||  M

*4//N^hklohphpy|  zB  zB  zD  zD  zL  9M  9M  2M	J
<3E3EjQTUXQYQYZbcijuv|  ~L  MS  Td  ek  l}  ~C  DI  JM  	NC
hhy<TXX&;<<A6QXXZZ6s1vv 66nSd$tDDDA|QtXs3xxYZYaYmefemotououXvwwws3xxVYV`V`VbVb@i

@R@Rhijjjr   c                    
 t                               dd           t                              dd           t          j                            dd           t                              dd           t                      t          j        t          
                    d                    d         } g }t          dt          |            dt                      t          j                            t          	          5 

fd
| D             }t          j                            |          D ]}|                                }|                    |           t          d|v r6|d          d|                    d           d|                    d           nt+          |                     	 d d d            n# 1 swxY w Y   g }t-          d |D                       sat          d           dD ]O\  }}t/          |t          |z            }|                    |           t          t+          |                     Pt1          d |D                       r.t          |          dk    rt1          d |D                       rdnd}	t2                              t          j        t6          j        d|	t          t          |           ||ddd          d           t          dt          j        |	t;          d |D                       t          |           t          |          dd          z              |	dk    rt=          d          d S ) NTr0   r   r   r    sceneszSTART step6 scenes=z	 workers=)max_workersc                 J    i | ]}                     t          |          | S rF   )submitr   )r   r   exr+   s     r   
<dictcomp>zmain.<locals>.<dictcomp>@   s+    :::abii$'':::r   rf   ri   rZ   z bytes=rk   c              3   .   K   | ]}|d          dk    V  dS )ri   r~   NrF   r   r,   s     r   r   zmain.<locals>.<genexpr>D   s+      66q{H$666666r   zSTART thumbnails))r   zthumb_16x9_final.png)9x16zthumb_9x16_final.pngc              3   *   K   | ]}|d          dv V  dS ri   r   rh   NrF   r   s     r   r   zmain.<locals>.<genexpr>H   s,      VVak-DDVVVVVVr   rx   c              3   *   K   | ]}|d          dv V  dS r   rF   r   s     r   r   zmain.<locals>.<genexpr>H   sd        yx  yx  efyz  |D  zE  I`  z`  yx  yx  yx  yx  yx  yxr   	completedneeds_retry   )
project_idstepri   workerstotal_scenesscene_resultsthumbnail_resultsF)ensure_asciiindentzDONE c              3   .   K   | ]}|d          dv dV  dS )ri   r      NrF   r   s     r   r   zmain.<locals>.<genexpr>J   s4      ={={ATUV^T_czTzTzaTzTzTzTz={={r   )ri   scenes_donescenes_totalthumbs)r   )r   r:   
OUT_THUMBSr8   r9   
write_textr-   r'   r(   SCENESr)   r@   lenWORKERS
concurrentfuturesThreadPoolExecutoras_completedresultrL   r*   r   rM   r   allMANIFESTdumpsPROJECTnamesum
SystemExit)r   resultsfutsfutr,   thumb_resultsr   r   trri   r   r+   s             @@r   mainr   <   s   T4000*2B2B4Y]2B2^2^2^`c`j`p`py}  HL`p  aM  aM  aM  OR  O]  O]  ^`  jq  O]  Or  Or  Or	DTZ(8(8'(8(J(JKKHUf_aW^cf  h]  ~A  BH  ~I  ~I  h]  h]  T[  h]  h]  d^  d^  d^			.	.7	.	C	C Qr:::::6:::%22488 	Q 	QCjjllAGNN1---ss}  BC  tC  tCq{4o4oQUU:EVEV4o4o_`_d_del_m_m4o4o4o  IL  MN  IO  IO  0Q  0Q  0Q  0Q	QQ Q Q Q Q Q Q Q Q Q Q Q Q Q Q M66g66666 \Z 	\ 	\IDjod33B]5I5I"5M5M5MsSVWYSZSZ||||VVgVVVVV  K[^_l[m[mop[p[pux  yx  yx  jw  yx  yx  yx  vx  vx[p;;  ~KF
QPVahx{  }C  yD  yD  U\  q~  $  $  MR  Z[  \  \  \  fm  n  n  n
V#={={={={={:{:{  LO  PV  LW  LW  ad  er  as  as  t  t  BG  H  H  H  	H  I  I  I{*]";";;s   B1GG	G	__main__)$concurrent.futuresr   r'   osr   r   r5   r   r   pathlibr   r   r   r   r%   r   r   r8   r   intenvironr*   r   r`   r^   r_   r   r-   r@   rU   rd   r   r   r   r   __name__rF   r   r   <module>r      s   K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K      WXX4VWW
##'2X*XT?"
w7J/JJPWXtPtC  @G  Hj  @jv~BJNN+C0011 C l _= = =  
A A A  i	 i	 i	| | |i i ik k k< < <  Zr   