
    J4j#                     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)PathzD/data/video-pipeline/Youtube-Video-Maker/Project/18062026-001-Nha-HozD/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 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 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 r|                    d           g }|D ]K}t                              |          }|r-|                                r||vr|                    |           L|S )Nu   hồ quý lyu   quý ly	ho-quy-lyu   hồ hán thươngu   hán thươngzho-han-thuongu   trần thiếu đếu   tôn thất nhà trầnu   nhà trầnz"tran-thieu-de-va-ton-that-nha-tranu   chu văn anu   thất trảm sớz
chu-van-anu
   đại nguu   dân chúngu
   lòng dânu   thành tây đôzquan-dan-dai-nguu
   quân minhu	   nhà minhu   phù trần diệt hồz	quan-minhu   chế bồng ngau   chiêm thànhz che-bong-nga-va-quan-chiem-thanhu	   lê lợiu   lam sơnzle-loi-va-nghia-quan-lam-son)r   appendREFSgetexists)texttkeysoutkps         r   
scene_refsrC      s   
jjllADi1nndkk+.F.F.Fq  Oq$8$8$++o:V:V:V""&?1&D&DYZHZHZ\`\g\g  iM  ]N  ]N  ]N1Q66L8Q8Q8QqMQ..,!2C2CGY]^G^G^`d`k`kl~```qK1,,0IQ0N0NPTP[P[\gPhPhPhQ/Q"6"6Df8g8g8ga:??DKK8V,W,W,W
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: 	narrationuv   
Subtle Nhà Hồ / Thành Tây Đô motifs, stone citadel silhouette, reform edicts and storm clouds, 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: late 14th to early 15th-century Đại Việt / Đại Ngu under Nhà Hồ, Tây Đô stone citadel, late Trần decline, Hồ Quý Ly reforms, Ming invasion threat, court crisis and loss of country.
Narration beat: z
Visual direction: visual_beatvisual_promptr*   u   One cinematic narrative scene, historically grounded early 15th-century Việt clothing, simple armor, stone citadel, Thanh Hóa landscape, royal court, village atmosphere, reform turmoil and war clouds.
Negative exclusions: )r;   STYLE_HEADINGNEGrC   STYLE_SCENE)scenerefsref_notes      r   
prompt_forrR   $   sn   yy)##  q  q`efq`r  q  q  lo  q  q  	q	EIIk"--c1%))Ib2I2II	J	JD rv  ~  n  n  |~H  ^	  ^	  KP  Q\  K]  ^	  ^	  sx  s|  s|  }J  sK  sK  si  OT  OX  OX  Yh  Oi  Oi  ^	  ^	  mu  ^	  ^	  Y	\	  ^	  ^	  ^	r   c                 \   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  }d}t          dt          t          j        
                    dd                    dz             D ]6}t          j        |ddd          }|j        dk    re|                                rQ|                                j        dk    r4| d         dt	          |          |                                j        |d c S |j        p|j        d!d          }d"|v s0d#|v s,d$|                                v sd%|                                v rbt          t          j        
                    d&d'                    }t+          d(| d          d)| d*| d+           t-          j        |           7 | d         d,t	          |          |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-ref   STEP06_MAX_ATTEMPTS6T  r=   capture_outputtimeoutr   ok)rT   rW   rX   rY   attempt0401429zusage limitzinvalidated oauth tokenSTEP06_RATE_WAIT150z
rate_wait z	 attempt=z wait=r   failed)rT   rW   rX   error)
OUT_SCENESr<   statst_sizestrsys
executable
GEN_SCRIPTrR   rC   r;   rangeintosenviron
subprocessrun
returncodestderrstdoutr   r6   r+   sleep)rO   r@   cmdreflast_errrp   rB   waits           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HC
/DS I IJJQNOO  
.$d4
H
H
H<??szz||?

0B40G0G$Z0$CY\YaYaYcYcYkv}~~~~~(&ah/H 1 1]hnnFVFV5V5VZsw  xF  xF  xH  xH  [H  [HRZ^^$6u==>>DOU:.OOOOOOOPPPJtZ((CHHU]^^^r   c                      | dk    rdnd}| dS )N16x9z!16:9 YouTube thumbnail, 1920x1080zFTikTok-safe vertical thumbnail/poster, 1080x1280 preferred compositionuP  . Cinematic Vietnamese historical dynasty poster for 'NHÀ HỒ - BẢY NĂM CẢI CÁCH GIỮA CƠN BÃO MẤT NƯỚC'. Large dramatic portrait of Hồ Quý Ly as an early 15th-century Việt reformer-ruler, Thành Tây Đô stone citadel, reform edicts, paper money, Ming invasion banners in storm clouds, manuscript parchment texture, dark sepia bronze black palette, large readable metallic-gold Vietnamese brush lettering over irregular black ink-splash title panel. Historically grounded early 15th-century Đại Việt / Đại Ngu / Nhà Hồ, not modern, not fantasy, no watermark. )kindaspects     r   thumb_promptr   =   s5    26,,..  EMF  g	  g	  g	  g	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   Trk   rl   r   rv   rq   )r   rW   rX   rw   ro   )r<   ry   rz   r{   r|   r}   r~   r   r:   r;   r   r   r   r   r   )r   r@   r   rB   rs        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          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>L   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   rv   Nr   r   r   s     r   r   zmain.<locals>.<genexpr>P   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>T   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>T   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   rh   Nr   r   s     r   r   zmain.<locals>.<genexpr>V   s4      ={={ATUV^T_czTzTzaTzTzTzTz={={r   )rW   scenes_donescenes_totalthumbs)r   )rx   r0   
OUT_THUMBSr.   r/   
write_textjsonloadsSCENES	read_textr6   lenWORKERS
concurrentfuturesThreadPoolExecutoras_completedresultr9   r;   r{   anyr   allMANIFESTdumpsPROJECTnamesum
SystemExit)r   resultsfutsfutr   thumb_resultsr   r   trrW   r   s             @r   mainr   H   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   r   r   r|   r+   r   r   pathlibr   r   r~   r   PLANrx   r   r.   r   r   r   r;   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      STT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  ^	 ^	 ^	_ _ _&g	 g	 g	k k k< < <  Zr   