
    )j                      8   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i Ze                                rU ej        e                    d                                        dg           D ]Z e
ed                   eed         <   d Z d Z!d Z"d Z#d Z$d Z%d Z&e'dk    r e&             dS dS )    N)PathzG/data/video-pipeline/Youtube-Video-Maker/Project/11062026-001-Trieu-NgozD/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7a  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.a  Avoid modern objects, wrong culture, Chinese opera costume, European armor, fantasy armor, samurai, guns, 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     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   utf-8encoding
referencesoutput_pathcharacter_idc                 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   logr6      s    	+	,	,S	0D%42H2H2H2H#*JZJZcgquJZJvJvJv	#w	'	'@1aggd4i.@.@.@@@@@@@@@@@@@@@@@@@s   &BBBc                    |                                  }g }d|v sd|v sd|v sd|v r|                    d           d|v r|                    d           d|v r|                    d	           d
|v sd|v r|                    d           d|v sd|v r|                    d           d|v sd|v r|                    d           d|v sd|v r|                    d           d|v sd|v sd|v sd|v r|                    d           d|v sd|v sd|v sd|v r|                    d           g }|D ]K}t                              |          }|r-|                                r||vr|                    |           L|S ) Nu   ngô quyềnu   bạch đằngu   cổ loau   xưng vương	ngo-quyenu   dương đình nghệzduong-dinh-ngheu   kiều công tiễnzkieu-cong-tienu   nam hánu   hoằng tháozhoang-thao-va-quan-nam-hanu   dương tam khau   bình vươngzduong-tam-khau   ngô xương vănu   nam tấn vươngzngo-xuong-van-nam-tan-vuongu   ngô xương ngậpu   thiên sách vươngzngo-xuong-ngap-thien-sach-vuongu
   sứ quânu   hào trưởngu	   cát cứu   bình kiềuzhao-truong-va-muoi-hai-su-quanu   dânu   người việtu   bắc thuộcu   làngzdan-viet-thoi-dau-doc-lap)r   appendREFSgetexists)texttkeysoutkps         r   
scene_refsrC      s   
jjllAD.!33zQ/]^J^J^`d`k`klw`x`x`x!##T[[1B%C%C%C!!4;;/?#@#@#@Q/Q..<X0Y0Y0YAA!5!5t{{?7S7S7Sa#6!#;#;T[[If=g=g=g!!%;q%@%@$++NoBpBpBpq,11[A5E5E[\I\I\^b^i^i  kK  _L  _L  _L{{'1,,10D0DSTVZVaVab}V~V~V~
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: 	narrationu@   
Subtle Trần dynasty motifs, spear silhouette, 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. u   
Historical context: 10th-century Tĩnh Hải quân and early independent Việt polity after Bắc thuộc, Bạch Đằng river ambush, Cổ Loa capital, rough early court, local warlords and villages.
Narration beat: z
Visual direction: visual_beatvisual_promptr*   u   One cinematic narrative scene, historically grounded 10th-century Việt clothing, simple armor, river boats, wooden stakes, Cổ Loa earthworks, villages and local warlord atmosphere.
Negative exclusions: )r;   STYLE_HEADINGNEGrC   STYLE_SCENE)scenerefsref_notes      r   
prompt_forrR   %   sn   yy)##  {  {`efq`r  {  {  vy  {  {  	{	EIIk"--c1%))Ib2I2II	J	JD rv  ~  n  n  |~H  z  z  z  @K  zL  z  z  bg  bk  bk  ly  bz  bz  bX  ~C  ~G  ~G  HW  ~X  ~X  z  z  \d  z  z  ux  z  z  zr   c                 h   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)rT   statusoutputbytes--prompt--output--sizeauto	--quality--background--image-detailhigh--output-formatpng--n1rG   r   rH   rI      --input-refT  r=   capture_outputtimeoutr   failed0)rT   rW   rX   errorok)
OUT_SCENESr<   statst_sizestrsys
executable
GEN_SCRIPTrR   rC   r;   
subprocessrun
returncodestderrstdout)rO   r@   cmdrefrB   s        r   run_oner~   +   s.   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
:e3D3DZPSTWPXPXYabhitu{  }K  LR  Sc  dj  k|  }B  CH  IL  	MC%))K33C7		)B8O8OOPPQSRSQSTuuVY^klopsltlt]uVuVYVY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 compositionui  . Cinematic Vietnamese historical dynasty poster for 'TRIỀU NGÔ - ÁNH BÌNH MINH SAU BẮC THUỘC'. Large dramatic portrait of Ngô Quyền as a 10th-century Việt commander-king, Bạch Đằng river stakes and broken Nam Hán warships, Cổ Loa earth citadel silhouette, misty dawn after a long dark occupation, local warlords in the distance, manuscript parchment texture, dark sepia bronze black palette, large readable metallic-gold Vietnamese brush lettering over irregular black ink-splash title panel. Historically grounded 10th-century Việt / Tĩnh Hải quân, not modern, not fantasy, no watermark. )kindaspects     r   thumb_promptr   3   s5    26,,..  EMF  @
  @
  @
  @
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}t          	                    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 )NrU   rV   )r   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   r8   rg   Trh   ri   r   rl   rm   )r   rW   rX   rn   ro   )r<   rq   rr   rs   rt   ru   rv   r   r:   r;   rw   rx   ry   rz   r{   )r   r@   r|   rB   rs        r   	gen_thumbr   6   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
hh{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          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                       s`t          d           dD ]N\  }}t-          |t          |z            }|                    |           t          t)          |                     Ot/          d |D                       r.t          |          dk    rt/          d |D                       rdnd}	t0                              t          j        t4          j        d|	t          t          |           ||ddd          d           t          dt          j        |	t9          d |D                       t          |           t          |          dd          z              |	dk    rt;          d          d S ) NTr&   r   r   r   sceneszSTART step6 scenes=z	 workers=)max_workersc                 H    i | ]}                     t          |          |S r   )submitr~   )r   r   exs     r   
<dictcomp>zmain.<locals>.<dictcomp>B   s)    555bii""1555r   rT   rW   rH   z bytes=rY   c              3   .   K   | ]}|d          dk    V  dS )rW   rl   Nr   r   r   s     r   r   zmain.<locals>.<genexpr>F   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 rW   ro   rV   Nr   r   s     r   r   zmain.<locals>.<genexpr>J   s,      VVak-DDVVVVVVr   rf   c              3   *   K   | ]}|d          dv V  dS r   r   r   s     r   r   zmain.<locals>.<genexpr>J   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steprW   workerstotal_scenesscene_resultsthumbnail_resultsF)ensure_asciiindentzDONE c              3   .   K   | ]}|d          dv dV  dS )rW   r      Nr   r   s     r   r   zmain.<locals>.<genexpr>L   s4      ={={ATUV^T_czTzTzaTzTzTzTz={={r   )rW   scenes_donescenes_totalthumbs)r   )rp   r0   
OUT_THUMBSr.   r/   
write_textjsonloadsSCENES	read_textr6   lenWORKERS
concurrentfuturesThreadPoolExecutoras_completedresultr9   r;   rs   anyr   allMANIFESTdumpsPROJECTnamesum
SystemExit)r   resultsfutsfutr   thumb_resultsr   r   trrW   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:f&&&8899(CFRWQT  VKknoukvkv  VK  VK  BI  VK  VK  RL  RL  RL			.	.7	.	C	C Qr5555f555%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 WZ 	W 	WIDjo..B0D0DR0H0H0H#cRTgg,,,,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   8B0F55F9<F9__main__)(concurrent.futuresr   r   osrw   rt   r+   r   r   pathlibr   r   rv   r   PLANrp   r   r.   r   intenvironr;   r   rN   rL   rM   r   r:   r<   r   r   r   r6   rC   rR   r~   r   r   r   __name__r   r   r   <module>r      s7   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      VWW4VWW
##'2X*XT?"
w7J/JJPWXtPtC  @G  Hj  @jv~BJNN+C0011 C l L= = = ;;== TZ8899==l2NN~~hlhlmno|m}h~h~PTUVWeUfPgPgA A A   z z z| | |@
 @
 @
k k k< < <  Zr   