
    LBj4"                     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)PathzE/data/video-pipeline/Youtube-Video-Maker/Project/29062026-001-Nha-MaczD/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.a1  Avoid modern objects, wrong culture, Qing dynasty queue, Chinese opera costume, European armor, fantasy armor, samurai, guns as dominant modern look, 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     c/data/video-pipeline/Youtube-Video-Maker/Project/29062026-001-Nha-Mac/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 }dv r|                    d           dv r|                    d           dv r|                    d           dv sdv r|                    d	           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 r|                    d           dv sdv sdv r|                    d           t          fddD                       r|                    d           dv sdv sdv r|                    d           d v sd!v sd"v r|                    d#           g }|D ]F}|                    |          }|r-|                                r||vr|                    |           G|S )$Nu   mạc đăng dungmac-dang-dungu   mạc đăng doanhzmac-dang-doanhu   mạc mậu hợpzmac-mau-hopu   nguyễn bỉnh khiêmu   bạch vânz nguyen-binh-khiem-bach-van-cu-siu   lê trang tôngu   lê trung hưngu   nam triềuzle-trung-hung-le-trang-tongu   nguyễn kimu   trịnh kiểmznguyen-kim-va-trinh-kiemu   trịnh tùngu   lê – trịnhu   lê-trịnhztrinh-tung-va-quan-le-trinhu   sĩ phuu
   quan lạiu	   khoa cửzsi-phu-va-quan-lai-dai-vietc              3       K   | ]}|v V  	d S )N )r   xts     r   r   zscene_refs.<locals>.<genexpr>!   s'      
e
ea16
e
e
e
e
e
er   )u   dân chúngu   dân phuu   làngu   ruộngu   bắt línhu   đói nghèozdan-chung-nam-bac-trieuu   quân mạcu   bắc triềuu   thăng longzquan-mac-bac-trieuu	   nhà minhu   triều minhu   biên giớiznha-minh-su-than-va-bien-gioi)r   appendanyr*   r&   )textr+   keysoutkprF   s         @r   
scene_refsrN      sK   
jjllADa_!=!=!=q  $++.>"?"?"?a]!;!;!;1$$(:(:DKKHj<k<k<kA!2a!7!7=A;M;Mt{{[xOyOyOy.!33T[[A[5\5\5\!0A55!9K9KT[[YvMwMwMwA~~**kQ.>.>Li@j@j@j

e
e
e
ed
e
e
eee  Ngkgrgr  tM  hN  hN  hN_11]a5G5GUiIjIjIja>Q...A2E2Et{{SrGsGsGs
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: 	narrationzf
Subtle 16th-century Mac dynasty / Nam Bac Trieu motifs, court seals, divided banners, 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: 16th-century Dai Viet, Mac dynasty in Thang Long, late Le legitimacy crisis, Nam-Bac Trieu civil war, Thanh Hoa-Nghe An bases, Ming border pressure, Confucian court and village society.
Narration beat: z
Visual direction: visual_beatvisual_promptr4   zOne cinematic narrative scene, historically grounded Vietnamese 16th-century clothing, armor, banners, palaces, villages, temples, exam halls, war camps, and atmosphere.
Negative exclusions: )r*   STYLE_HEADINGNEGrN   STYLE_SCENE)scener+   srref_notes       r   
prompt_forr]   )   sp   yy)##  a  a`efq`r  a  a  \_  a  a  	a%))K++C/		)B0G0GGNNB rt  |  n  n  z|H  n  n  }B  CN  }O  n  n  ej  en  en  o|  e}  e}  e[  AF  AJ  AJ  KZ  A[  A[  n  n  _g  n  n  il  n  n  n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)r_   statusoutputbytes--prompt--output--sizeauto	--quality--background--image-detailhigh--output-formatpng--n1rR   r   rS   rT      --input-refT  rI   capture_outputtimeoutr   failed0)r_   rb   rc   errorok)
OUT_SCENESr&   statst_sizestrsys
executable
GEN_SCRIPTr]   rN   r*   
subprocessrun
returncodestderrstdout)rZ   r+   rK   cmdrefrM   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 compositionuM  . Cinematic Vietnamese historical dynasty poster for 'NHÀ MẠC - DANH NGHĨA VÀ BÃO TỐ NAM BẮC TRIỀU'. Large dramatic portrait of Mạc Đăng Dung in 16th-century Đại Việt court-military robe, split background: Thăng Long palace and burning civil-war battlefield, Lê-Trịnh banners in distance, Ming border pressure hinted by envoy silhouettes, manuscript parchment texture, dark sepia bronze black palette, large readable metallic-gold Vietnamese brush lettering over irregular black ink-splash title panel. Historically grounded, not modern, not fantasy, no watermark.rD   )kindaspects     r   thumb_promptr   7   s5    26,,..  EMF  d	  d	  d	  d	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          }|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 )Nr`   ra   )r   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rB   rr   Trs   rt   r   rw   rx   )r   rb   rc   ry   rz   )r&   r|   r}   r~   r   r   r   r   r*   r   r   r   r   r   )r   rK   r+   r   rM   r,   s         r   	gen_thumbr   :   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                      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 rD   )submitr   )r   r   exr+   s     r   
<dictcomp>zmain.<locals>.<dictcomp>F   s+    :::abii$'':::r   r_   rb   rS   z bytes=rd   c              3   .   K   | ]}|d          dk    V  dS )rb   rw   NrD   r   r,   s     r   r   zmain.<locals>.<genexpr>J   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 rb   rz   ra   NrD   r   s     r   r   zmain.<locals>.<genexpr>N   s,      VVak-DDVVVVVVr   rq   c              3   *   K   | ]}|d          dv V  dS r   rD   r   s     r   r   zmain.<locals>.<genexpr>N   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steprb   workerstotal_scenesscene_resultsthumbnail_resultsF)ensure_asciiindentzDONE c              3   .   K   | ]}|d          dv dV  dS )rb   r      NrD   r   s     r   r   zmain.<locals>.<genexpr>P   s4      ={={ATUV^T_czTzTzaTzTzTzTz={={r   )rb   scenes_donescenes_totalthumbs)r   )r{   r:   
OUT_THUMBSr8   r9   
write_textr-   r'   r(   SCENESr)   r@   lenWORKERS
concurrentfuturesThreadPoolExecutoras_completedresultrG   r*   r~   rH   r   allMANIFESTdumpsPROJECTnamesum
SystemExit)r   resultsfutsfutr,   thumb_resultsr   r   trrb   r   r+   s             @@r   mainr   B   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   rY   rW   rX   r   r-   r@   rN   r]   r   r   r   r   __name__rD   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      TUU4VWW
##'2X*XT?"
w7J/JJPWXtPtC  @G  Hj  @jv~BJNN+C0011 C l x= = =  
A A A  $n n n| | |d	 d	 d	k k k< < <  Zr   