
    i~W                    V   d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlZddlmZ  ee      j                  Z ed      Z ed      Zed	z  d
ddedz  dddedz  ddddZdZdZdZd#dZd$dZd%dZd%dZd%dZd&dZd'dZd#dZd#dZd#d Z d! Z!e"d"k(  r e!        yy)(uu   
컨셉 #24, #25, #26 하이브리드 이미지 생성 스크립트
Gemini Pro 배경 + Playwright HTML 오버레이
    )annotationsN)Path)Any)sync_playwrightz&/home/jay/workspace/tools/ai-image-genz3/home/jay/workspace/output/meta-ads/concept-catalogz24-apple-stylezPure clean off-white background #F5F5F7, extremely minimal, no objects, no texture, vast empty space, ultra clean studio lighting, Apple-inspired minimalism, 1080x1080, square formatapple)
output_dir	bg_promptstylez25-mcdonalds-stylezBold energetic background, top half bright vivid red #DA291C, bottom half golden yellow #FFC72C, diagonal split line between colors, cheerful and optimistic mood, high saturation, no text, no people, 1080x1080, square format	mcdonaldsz26-hyundai-stylea  Dark cinematic studio background, deep charcoal black #0D0F12, subtle metallic silver light streak coming from upper left corner, soft blue-tinted ambient glow on the edges, ultra-premium automotive aesthetic, no text, no objects, high contrast, 1080x1080, square formathyundai242526z0https://generativelanguage.googleapis.com/v1betazgemini-3-pro-image-previewzgemini-3.1-flash-image-previewc                    t         j                  j                  dt        t                     ddl} 	 | j                  d      }t        dt        |       d       |S # t        $ r}t        d| d       Y d}~nd}~ww xY w	 | j                  d      }|rd	| S n# t        $ r Y nw xY wddl}|j                  g d
ddd      }|j                  j                         }t        dt        |       d       |S )u5   인증 토큰 획득 (SA 우선, gcloud CLI fallback)r   Nz3https://www.googleapis.com/auth/generative-languageu$     [인증] SA 토큰 획득 성공 (z chars)u     [인증] SA 토큰 실패: u   , API 키 시도...GEMINI_API_KEYAPI_KEY:)gcloudauthzprint-access-tokenT)capture_outputtextchecku,     [인증] gcloud CLI 토큰 획득 성공 ()syspathinsertstrWORK_DIRgcloud_authget_service_account_tokenprintlen	Exceptionget_api_key
subprocessrunstdoutstrip)r   tokeneapi_keyr$   results         ^/home/jay/workspace/.worktrees/task-2116-dev1/tools/ai-image-gen/_backup/gen_concepts_24_26.pyget_auth_tokenr-   E   s   HHOOAs8}%F55A
 	4SZLHI F-aS0CDEEF))*:;gY''   ^^0$d  F MM!E	8UG
LMLs)   *A 	B 'A;;B B 	B)(B)c                   t        d|dd  d       | j                  d      r| dd }t         dt         d| }d	d
i}nt         dt         d}d|  d
d}dd|igigdddgid}	 t	        j
                  |||d      }|j                  dv rft        d|j                   d       | j                  d      rt         dt         d }nt         dt         d}t	        j
                  |||d      }|j                          |j                         }|j                  dg       }	|	st        d       y|	d   j                  di       j                  dg       }
t        d |
D        d      }|t        d       yt        j                  |d    d!         }|j                  |       t        |      d"z  }t        d#|j                    d$|d%d&       y'# t"        $ r}t        d(|        Y d}~yd}~ww xY w))u%   Gemini API로 배경 이미지 생성u     [배경생성] 프롬프트: NP   z...r      z/models/z:generateContent?key=Content-Typezapplication/jsonz:generateContentzBearer )Authorizationr1   partsr   responseModalitiesIMAGETEXT)contentsgenerationConfigx   )headersjsontimeout)i  i  u'     [배경생성] 모델 접근 실패 (u   ), fallback 시도...
candidatesu*     [배경생성] 오류: candidates 없음Fr   contentc              3  *   K   | ]  }d |v s|  yw)
inlineDataN ).0ps     r,   	<genexpr>z&generate_background.<locals>.<genexpr>   s     A|q/@1As   	u3     [배경생성] 오류: 이미지 데이터 없음r@   data   u     [배경생성] 완료:  (.0f KB)Tu     [배경생성] 오류: )r    
startswithGEMINI_API_BASEMODEL_IDrequestspoststatus_codeFALLBACK_MODELraise_for_statusr;   getnextbase64	b64decodewrite_bytesr!   namer"   )r(   promptoutput_pathr*   urlr:   payloadresprE   r=   r3   
image_partimage_bytessize_kbr)   s                  r,   generate_backgroundr`   c   s7   	+F3BK=
<= 
#) !(3H	R!#56 !(3CD&ug..
  01231GV3DEG
!}}S'Mz);D<L<L;MMbcd
+().1AAVW^V_`().1AAQR==gGSQDyy{XXlB/
>@1!!)R044WbAAeA4H
GI&&z,'?'GH,k"T))+*:*:);2gc]$OP )!-.s'   (CG 5AG ;AG 	G4G//G4c                    d|  dS )z#24 Apple Style HTMLa  <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
  @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;600;700&display=swap');
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body {
    width: 1080px;
    height: 1080px;
    overflow: hidden;
    background: #F5F5F7;
    font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  }
  .container {
    width: 1080px;
    height: 1080px;
    position: relative;
    background-image: url('file://u\  ');
    background-size: cover;
    background-position: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  .content {
    text-align: center;
    padding: 0 120px;
  }
  .headline {
    font-size: 84px;
    font-weight: 600;
    color: #1D1D1F;
    line-height: 1.15;
    letter-spacing: -2px;
    white-space: pre-line;
    margin-bottom: 36px;
  }
  .sub {
    font-size: 64px;
    font-weight: 400;
    color: #86868B;
    line-height: 1.3;
    letter-spacing: -1px;
    margin-bottom: 0;
  }
  .cta {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 40px;
    font-weight: 400;
    color: #0066CC;
    letter-spacing: -0.5px;
    white-space: nowrap;
    text-decoration: none;
  }
</style>
</head>
<body>
<div class="container">
  <div class="content">
    <div class="headline">열심히는 하는데,<br>월급은 제자리걸음?</div>
    <div class="sub">이제 다른 방법을 찾아볼 때입니다</div>
  </div>
  <div class="cta">더 알아보기 →</div>
</div>
</body>
</html>rA   bg_paths    r,   build_apple_htmlrd      s    #$ $+) 4,%F F    c                    d|  dS )z#25 McDonald's Style HTMLa  <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
  @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;700;900&display=swap');
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body {
    width: 1080px;
    height: 1080px;
    overflow: hidden;
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
  }
  .container {
    width: 1080px;
    height: 1080px;
    position: relative;
    background-image: url('file://u  ');
    background-size: cover;
    background-position: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  .top-block {
    width: 100%;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 80px 30px;
  }
  .headline {
    font-size: 96px;
    font-weight: 900;
    color: #FFFFFF;
    line-height: 1.1;
    letter-spacing: -2px;
    text-align: center;
    white-space: pre-line;
    text-shadow: 2px 4px 12px rgba(0,0,0,0.3);
  }
  .bottom-block {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 80px 60px;
    gap: 40px;
  }
  .sub {
    font-size: 64px;
    font-weight: 700;
    color: #292929;
    line-height: 1.2;
    text-align: center;
    letter-spacing: -1px;
  }
  .cta-btn {
    background: #FFC72C;
    color: #292929;
    font-size: 48px;
    font-weight: 700;
    padding: 24px 80px;
    border-radius: 60px;
    letter-spacing: -0.5px;
    white-space: nowrap;
  }
</style>
</head>
<body>
<div class="container">
  <div class="top-block">
    <div class="headline">월급 제자리걸음?<br>이제 바꾸면 되잖아!</div>
  </div>
  <div class="bottom-block">
    <div class="sub">T.O.P 사업단과 함께 시작하세요</div>
    <div class="cta-btn">지금 시작하기</div>
  </div>
</div>
</body>
</html>rA   rb   s    r,   build_mcdonalds_htmlrg      s     #" $+) C,#T Tre   c                    d|  dS )z#26 Hyundai Style HTMLa  <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
  @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;700;900&display=swap');
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body {
    width: 1080px;
    height: 1080px;
    overflow: hidden;
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
  }
  .container {
    width: 1080px;
    height: 1080px;
    position: relative;
    background-image: url('file://u  ');
    background-size: cover;
    background-position: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
  }
  .content {
    text-align: center;
    padding: 0 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 48px;
  }
  .eyebrow {
    font-size: 28px;
    font-weight: 300;
    color: #00D4FF;
    letter-spacing: 6px;
    text-transform: uppercase;
  }
  .headline {
    font-size: 96px;
    font-weight: 900;
    color: #F5F7FA;
    line-height: 1.1;
    letter-spacing: -2px;
    white-space: pre-line;
    text-align: center;
  }
  .divider {
    width: 80px;
    height: 2px;
    background: #00D4FF;
  }
  .sub {
    font-size: 64px;
    font-weight: 300;
    color: #C0C8D0;
    line-height: 1.3;
    letter-spacing: -0.5px;
    text-align: center;
  }
  .cta {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    border: 2px solid #00D4FF;
    color: #00D4FF;
    font-size: 40px;
    font-weight: 400;
    padding: 20px 72px;
    letter-spacing: 3px;
    text-transform: uppercase;
    white-space: nowrap;
  }
</style>
</head>
<body>
<div class="container">
  <div class="content">
    <div class="eyebrow">T.O.P 사업단</div>
    <div class="headline">열심히는 하는데,<br>월급은 제자리걸음?</div>
    <div class="divider"></div>
    <div class="sub">이제 변속할 시간입니다</div>
  </div>
  <div class="cta">T.O.P 확인하기</div>
</div>
</body>
</html>rA   rb   s    r,   build_hyundai_htmlri   D  s     #" $+) I,#Z Zre   c                   |j                   dz  }|j                  | d       	 t               5 }|j                  j	                         }	 |j                  ddd      }|j                  d|j                          d	       |j                  d
       |j                   j                  dd       |j                  t        |      d       |j                         j                  dz  }t        d|j                   d|dd       	 |j!                          ddd       |j#                         r|j%                          yy# |j!                          w xY w# 1 sw Y   nxY wnE# t&        $ r9}t        d|        Y d}~|j#                         r|j%                          yyd}~ww xY w	 |j#                         r|j%                          yy# |j#                         r|j%                          w w xY w)u-   Playwright로 HTML을 1080x1080 PNG로 캡처z_overlay_temp.htmlzutf-8)encodingi8  )widthheight)viewportzfile://networkidle)
wait_untili  Tparentsexist_okpng)r   typerF   u     [캡처] 완료: rG   rH   rI   Nu     [캡처] 오류: F)parent
write_textr   chromiumlaunchnew_pagegotoresolvewait_for_timeoutmkdir
screenshotr   statst_sizer    rW   closeexistsunlinkr"   )html_contentrY   	html_pathrC   browserpager_   r)   s           r,   capture_html_to_pngr     s   ""%99I8 	 !jj'')G ''441P'Q		GI$5$5$7#89m	T %%d+""(((ES%5EB%**,44t;+K,<,<+=R}DQR	 (   	  	  	    #A3'( 	!	 (  9 s_   
E$ E
B=EEE$ EEE E$ #G $	F&-F!;G !F&&G #G/c           	        t         |    }|d   }|j                  dd       |dz  }|dz  }|d   }t        dd        t        d	|  d
       t        d        t        j                         }t	        ||d   |      }|r|}	nt        d       d}	|dk(  r|	rt        |	      }
nVt               }
nK|dk(  r|	rt        |	      }
n8t               }
n-|dk(  r|	rt        |	      }
nt               }
nt        d|        yt        |
|      }|j                         r|j                          t        j                         |z
  }|rt        d	|  d| d|dd       |S t        d	|  d|dd       |S )u   단일 컨셉 이미지 생성r   Trq   zbg_temp.jpg
sample.pngr
   
<============================================================u	   [컨셉 #u   ] 생성 시작r	   u7     [배경] 배경 생성 실패, 단색 fallback 사용Nr   r   r   u%     [오류] 알 수 없는 스타일: Fu
   ] 완료: rG   z.1fu   초)u
   ] 실패 ()CONCEPTSr~   r    timer`   rd   build_apple_html_solidrg   build_mcdonalds_html_solidri   build_hyundai_html_solidr   r   r   )
concept_idr(   cfgr   rc   sample_pathr
   startbg_okbg_for_htmlhtmlokelapseds                r,   generate_conceptr     s   
:
C<(JTD1=(G|+KLE	Bvh-	Ij\
12	VHIIKE  s;'7AE 	GI #K0D)+D	+	'4D-/D	)	%k2D+-D5eW=> 
T;	/B ~~iikE!G		*Z}Bwsm4PQ I 		*Z}DABIre   c                      y)u*   Apple Style - 순수 CSS 배경 (fallback)ud  <!DOCTYPE html>
<html><head><meta charset="UTF-8">
<style>
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body { width: 1080px; height: 1080px; overflow: hidden;
    font-family: 'Pretendard', 'Noto Sans KR', -apple-system, sans-serif; }
  .container { width: 1080px; height: 1080px; position: relative;
    background: #F5F5F7; display: flex; flex-direction: column;
    align-items: center; justify-content: center; }
  .headline { font-size: 84px; font-weight: 600; color: #1D1D1F;
    line-height: 1.15; letter-spacing: -2px; text-align: center;
    margin-bottom: 36px; }
  .sub { font-size: 64px; font-weight: 400; color: #86868B;
    line-height: 1.3; letter-spacing: -1px; text-align: center; }
  .cta { position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%);
    font-size: 40px; color: #0066CC; white-space: nowrap; }
</style></head><body>
<div class="container">
  <div class="headline">열심히는 하는데,<br>월급은 제자리걸음?</div>
  <div class="sub">이제 다른 방법을 찾아볼 때입니다</div>
  <div class="cta">더 알아보기 →</div>
</div></body></html>rA   rA   re   r,   r   r     s    re   c                      y)u/   McDonald's Style - 순수 CSS 배경 (fallback)u  <!DOCTYPE html>
<html><head><meta charset="UTF-8">
<style>
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body { width: 1080px; height: 1080px; overflow: hidden;
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif; }
  .container { width: 1080px; height: 1080px; position: relative;
    display: flex; flex-direction: column; }
  .top-block { flex: 1; background: #DA291C; display: flex;
    align-items: center; justify-content: center; padding: 60px 80px 30px; }
  .headline { font-size: 96px; font-weight: 900; color: #FFFFFF;
    line-height: 1.1; letter-spacing: -2px; text-align: center; }
  .bottom-block { flex: 1; background: #FFC72C; display: flex;
    flex-direction: column; align-items: center; justify-content: center;
    padding: 20px 80px 60px; gap: 40px; }
  .sub { font-size: 64px; font-weight: 700; color: #292929;
    text-align: center; letter-spacing: -1px; }
  .cta-btn { background: #FFC72C; border: 4px solid #292929; color: #292929;
    font-size: 48px; font-weight: 700; padding: 24px 80px;
    border-radius: 60px; }
</style></head><body>
<div class="container">
  <div class="top-block">
    <div class="headline">월급 제자리걸음?<br>이제 바꾸면 되잖아!</div>
  </div>
  <div class="bottom-block">
    <div class="sub">T.O.P 사업단과 함께 시작하세요</div>
    <div class="cta-btn">지금 시작하기</div>
  </div>
</div></body></html>rA   rA   re   r,   r   r      s    re   c                      y)u,   Hyundai Style - 순수 CSS 배경 (fallback)uB  <!DOCTYPE html>
<html><head><meta charset="UTF-8">
<style>
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body { width: 1080px; height: 1080px; overflow: hidden;
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif; }
  .container { width: 1080px; height: 1080px; position: relative;
    background: #0D0F12; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 0; }
  .content { text-align: center; padding: 0 100px; display: flex;
    flex-direction: column; align-items: center; gap: 48px; }
  .eyebrow { font-size: 28px; font-weight: 300; color: #00D4FF;
    letter-spacing: 6px; text-transform: uppercase; }
  .headline { font-size: 96px; font-weight: 900; color: #F5F7FA;
    line-height: 1.1; letter-spacing: -2px; text-align: center; }
  .divider { width: 80px; height: 2px; background: #00D4FF; }
  .sub { font-size: 64px; font-weight: 300; color: #C0C8D0;
    line-height: 1.3; text-align: center; }
  .cta { position: absolute; bottom: 80px; left: 50%;
    transform: translateX(-50%); border: 2px solid #00D4FF;
    color: #00D4FF; font-size: 40px; font-weight: 400;
    padding: 20px 72px; letter-spacing: 3px; text-transform: uppercase;
    white-space: nowrap; }
</style></head><body>
<div class="container">
  <div class="content">
    <div class="eyebrow">T.O.P 사업단</div>
    <div class="headline">열심히는 하는데,<br>월급은 제자리걸음?</div>
    <div class="divider"></div>
    <div class="sub">이제 변속할 시간입니다</div>
  </div>
  <div class="cta">T.O.P 확인하기</div>
</div></body></html>rA   rA   re   r,   r   r   B  s     re   c            	     n   dd l } | j                  d      }|j                  dg dd       |j                         }t	        d       t	        d	       t	        d       	 t               }|j                  dk(  rg dn|j                  g}i }|D ]  }t        ||      }|||<    t	        d       t	        d       t	        d       |j                         D ].  \  }}|rdnd}	t        |   d   dz  }
t	        d| d|	 d|
        0 y # t        $ r%}t	        d
|        t	        d       d }Y d }~d }~ww xY w)Nr   u/   컨셉 #24~#26 하이브리드 이미지 생성)descriptionz	--concept)r   r   r   allr   )choicesdefaultr   uB   컨셉 이미지 생성 시작 (Gemini 배경 + HTML 오버레이)u   [오류] 인증 실패: u5   [fallback] CSS 단색 배경으로 진행합니다...r   z=
============================================================u   생성 결과u   성공u   실패r   r   z  #z: u    → )argparseArgumentParseradd_argument
parse_argsr    r-   r"   conceptr   itemsr   )r   parserargsr(   r)   conceptsresultscidr   statusr   s              r,   mainr   k  s?   $$1b$cF
-FPUVD	(O	
NO	(O  &*\\U%:!HG c5) 
/	/	(O==? 0RX}\*\9C56(%v./0  (,-EFs   
D 	D4D//D4__main__)returnr   )r(   r   rX   r   rY   r   r   bool)rc   r   r   r   )r   r   rY   r   r   r   )r   r   r(   r   r   r   )#__doc__
__future__r   rT   r;   r   r   pathlibr   typingr   rM   playwright.sync_apir   __file__rv   BASE_DIRr   OUTPUT_BASEr   rK   rL   rP   r-   r`   rd   rg   ri   r   r   r   r   r   r   __name__rA   re   r,   <module>r      s  
 #   
     / >  89HI "$44B  "$88'
 	 "$666 
)J E'1<6zHVVr\FD:z4D"R0D zF re   