
    c)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)PathzL/data/video-pipeline/Youtube-Video-Maker/Project/10062026-001-Tran-Quoc-TuanzD/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 r|                    d           d|v sd|v r|                    d           d|v sd|v sd|v sd|v sd	|v sd
|v r|                    d           d|v sd|v sd|v s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 r|                    d           d|v sd|v r|                    d            d!|v sd"|v sd#|v r|                    d$           g }|D ]K}t                              |          }|r-|                                r||vr|                    |           L|S )%Nu   trần quốc tuấnu   hưng đạou   đức thánh trầntran-quoc-tuan-hung-dao-vuongu	   tam quânu   quân trầnu   đông au   đại việtu   dânu   làngztran-soldiers-dai-viet-quan-danu   nguyênu   môngu   thoát hoanu
   ô mã nhiu   toa đôzquan-nguyen-mongu   trần khánh dưu   vân đồnztran-khanh-duu   trần quang khảiu   chương dươngztran-quang-khaiu   trần nhật duậtu	   hàm tửztran-nhat-duatu   yết kiêuu   dã tượngzyet-kieu-va-da-tuongu   trần liễuzan sinhz	tran-lieuu
   vua trầnu   triều đìnhu   diên hồngzvua-tran-trieu-dinh-nha-tran)r   appendREFSgetexists)texttkeysoutkps         r   
scene_refsrC      s   
jjllAD""n&9&9=SWX=X=XZ^ZeZe  gF  [G  [G  [G""n&9&94;;Gf;g;g;ga>Q..*//_XYEYEY]cgh]h]hlswxlxlxz~  {F  {F  Gh  {i  {i  {iA~~A!););|q?P?PT^bcTcTceiepep  rD  fE  fE  fEa=A#5#5t{{?7S7S7S!!%71%<%<dkkJ[>\>\>\""kQ&6&6DT8U8U8U^q00$++>T2U2U2U!yA~~t{{;/G/G/Gq,11^q5H5H$++VtJuJuJu
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: 13th-century Đại Việt under the Trần dynasty, Bắc Bộ villages, Thăng Long court, Trần army camps, rivers Hàm Tử/Chương Dương/Bạch Đằng, anti-Mongol resistance atmosphere.
Narration beat: z
Visual direction: visual_beatvisual_promptr*   u   One cinematic narrative scene, historically grounded Vietnamese Trần dynasty clothing, armor, spears, boats, architecture, terrain, and 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  e  e  HM  NY  HZ  e  e  pu  py  py  zG  pH  pH  pf  LQ  LU  LU  Ve  Lf  Lf  e  e  jr  e  e  `c  e  e  e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 compositionua  . Cinematic Vietnamese historical biography poster for 'HƯNG ĐẠO VƯƠNG TRẦN QUỐC TUẤN - ĐỨC THÁNH TRẦN'. Large dramatic portrait of Trần Quốc Tuấn / Hưng Đạo Vương as a dignified Đại Việt commander, Bạch Đằng river stakes, Trần war banners, Mongol-Yuan invasion smoke and warships in the background, manuscript parchment texture, dark sepia bronze black palette, large readable metallic-gold Vietnamese brush lettering over irregular black ink-splash title panel. Historically grounded 13th-century Đại Việt Trần dynasty, not modern, not fantasy, no watermark. )kindaspects     r   thumb_promptr   4   s5    26,,..  EMF  x	  x	  x	  x	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   7   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>C   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>G   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>K   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>K   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>M   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      [\\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  "e e e| | |x	 x	 x	k k k< < <  Zr   