
    '<i                         d 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Z ed      ZdZ	dZ
dZdZd	Zd
 Zd Zd Zedk(  r e        yy)u^   Step 1: Gemini Pro로 3인 프로필 배경 이미지 생성 (concept #19 페르소나 카드)    N)PathzJ/home/jay/workspace/output/meta-ads/concept-catalog/19-persona-card/bg.pngad  Three professional Korean business people portrait headshots arranged side by side against a clean light gray background (hex #F4F6FA). Left person: a confident Korean woman in her late 20s, warm genuine smile, wearing a light blue professional blouse, shoulder-length hair. Center person: a composed Korean man in his early 40s, slight reassuring smile, wearing a dark navy suit with white shirt, short hair, professional demeanor. Right person: an energetic Korean woman in her early 30s, bright enthusiastic smile, wearing a smart casual charcoal blazer, modern hairstyle. All three are portrait headshots from shoulders up. Professional studio lighting, soft shadows, photorealistic quality. Three equal-width panels side by side, each panel 360x400px roughly. Clean minimal background #F4F6FA throughout. No text, no watermarks, no logos. 1080x1080 square format.zgemini-3-pro-image-previewzgemini-3.1-flash-image-previewz0https://generativelanguage.googleapis.com/v1betaz3https://www.googleapis.com/auth/generative-languagec                  t    t         j                  j                  dd       dd l} | j	                  t
              S )Nr   z&/home/jay/workspace/tools/ai-image-gen)syspathinsertgcloud_authget_service_account_tokenGEMINI_SCOPE)r   s    g/home/jay/workspace/.worktrees/task-2057-dev2/output/meta-ads/concept-catalog/19-persona-card/gen_bg.py	get_tokenr   $   s)    HHOOA?@00>>    c                 |    t          d| d}d|  dd}dd|igigdd	gd
dd}t        j                  |||d      S )Nz/models/z:generateContentzBearer zapplication/json)AuthorizationzContent-TypepartstextIMAGETEXTg      ?)responseModalitiestemperature)contentsgenerationConfig   )headersjsontimeout)GEMINI_API_BASErequestspost)tokenmodel_idprompturlr   payloads         r   call_geminir$   *   sm    XhZ/?
@C"5'**G
  0123#*F"3
G ==gGSIIr   c            	         t         j                  j                  dd       t        d       t	               } t        dt        |        d       t        dt         d       t        j                         }t        | t        t              }|j                  dv r4t        d|j                   d	t                t        | t        t              }|j                          t        j                         |z
  }t        d
|dd       |j                         }|j                  dg       }|s/t        dt        |      d d         t!        j"                  d       |d   j                  di       j                  dg       }d }|D ]
  }d|v s|} n |J|D 	cg c]  }	d|	v s|	j                  dd       }
}	t        d|
d d         t!        j"                  d       |d   j                  dd      }t%        j&                  |d   d         }t         j)                  |       t         j+                         j,                  dz  }t        dt          d|dd | d       y c c}	w )!NT)parentsexist_oku   [1] SA 토큰 획득 중...u"   [1] 토큰 획득 완료 (길이: )u3   [2] Gemini 이미지 생성 요청 중... (모델: )i  i  u   [2] Pro 모델 실패 (HTTP z), fallback: u   [2] 응답 수신 (z.1fu   초)
candidatesu%   [ERROR] 응답에 candidates 없음: i,     r   contentr   
inlineDatar    u/   [ERROR] 이미지 데이터 없음. 텍스트:    mimeTypez
image/jpegdatai   u   [3] 저장 완료: z (z.0fz
 KB, mime=)OUTPUT_PATHparentmkdirprintr   lenMODEL_IDtimer$   PROMPTstatus_codeFALLBACK_MODEL_IDraise_for_statusr   getstrr   exitbase64	b64decodewrite_bytesstatst_size)r   startrespelapsedr0   r)   r   
image_partpartp
text_parts	mime_typeimage_bytessize_kbs                 r   mainrN   :   s0   TD9	
'(KE	.s5zl!
<=	?z
KLIIKEuh/D:%,T-=-=,>mL]K^_`5"3V<iikE!G	}D
1299;D,+J5c$io5FGHqMi,00"=EJ 4J
 16FA&A+aeeFB'F
F?
2A?OPQ<(,,ZFI"":l#;F#CDKK( ((4/G	}Bwsm:i[PQ
RS Gs   	II__main__)__doc__r?   
subprocessr   r7   pathlibr   r   r1   r8   r6   r:   r   r
   r   r$   rN   __name__ r   r   <module>rU      sm    d   
   _`A   (4 DD?J )TX zF r   