
    +j*                        % S r SSKrSSKJr  SSKJrJrJr  SSKJ	r	J
r
JrJrJr  SSKJrJrJrJrJrJr   " S S5      rS	\\R.                     S
\R0                  S\4S jrSrSrSr\S\S\S0r\\\4   \ S'   / SQr!S/r"/ SQr#/ SQr$\RJ                  " S5      r&S\'4S jr( " S S\R.                  5      r) " S S\R.                  5      r* " S S\5      r+S\+4S  jr,g)!zKrea image-generation nodes.    N)override)IOComfyExtensionInput)KreaAssetResponseKreaGenerateImageRequestKreaImageStyleReferenceKreaJobKreaMoodboard)ApiEndpointdownload_url_to_image_tensorpoll_opsync_optensor_to_bytesiovalidate_stringc                       \ rS rSrSrSrg)KreaIO   KREA_STYLE_REF N)__name__
__module____qualname____firstlineno__	STYLE_REF__static_attributes__r       :/home/wildlama/comfy/ComfyUI/comfy_api_nodes/nodes_krea.pyr   r      s     Ir   r   clsimagereturnc           
         #    [        USSS9n[        U [        SSS9[        SUR                  US44/SS	S
S9I Sh  vN nUR
                  $  N7f)zPUpload an image to Krea's /assets endpoint and return the Krea-hosted image URL.i  @ z	image/png)total_pixels	mime_typez/proxy/krea/assetsPOSTpathmethodfilezmultipart/form-data   zUploading reference)endpointresponse_modelfilescontent_typemax_retries
wait_labelN)r   r   r   r   name	image_url)r   r    img_ioresponses       r   _upload_image_to_krea_assetsr5      se     u;+VF"6vF(fk:;<*( H s   :AAAzKrea 2 MediumzKrea 2 Medium TurbozKrea 2 Largez-/proxy/krea/generate/image/krea/krea-2/mediumz3/proxy/krea/generate/image/krea/krea-2/medium-turboz,/proxy/krea/generate/image/krea/krea-2/large_MODEL_ENDPOINTS)z1:1z4:3z3:2z16:9z2.35:1z4:5z2:3z9:161K)rawlowmediumhigh)
backloggedqueued	scheduledzM^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$c                     [         R                  R                  S[        SS9[         R                  R                  S[        SS9[         R                  R                  S[
        SSS	9[         R                  R                  S
SSSS9[         R                  R                  SSSSSSSS9[         R                  " [        R                  5      R                  SSSS9/$ )zUNested inputs shared by Krea 2 Medium, Medium Turbo and Large under the DynamicCombo.aspect_ratiozOutput aspect ratio.optionstooltip
resolutionzResolution scale.
creativityr:   zWPrompt interpretation strength: raw stays closest to the prompt; high is most creative.)rB   defaultrC   moodboard_id zOptional Krea moodboard UUID (e.g. from the Krea website). Leave empty to disable. Only one moodboard is supported per request.T)rF   rC   optionalmoodboard_strengthffffff?g      g      ?皙?z8Moodboard influence; ignored when moodboard_id is empty.)rF   minmaxsteprC   rI   style_referencezNOptional chain of style references (max 10) from Krea 2 Style Reference nodes.rI   rC   )r   Combor   _ASPECT_RATIOS_RESOLUTIONS_CREATIVITY_LEVELSStringFloatCustomr   r   r   r   r   _krea_model_inputsrY   =   s     	"* 	 	

 	 ' 	 	

 	&m	 	 	
 			S 	 	
 	 N 	 	
 			&""#))d 	* 	
C& &r   c            	       x    \ rS rSr\S\R                  4S j5       r\S\S\	S\
S\R                  4S j5       rSrg	)
Krea2ImageNodeh   r!   c                    [         R                  " SSSS[         R                  R                  SSSSS	9[         R                  R                  S
[         R                  R                  [        [        5       5      [         R                  R                  [        [        5       5      [         R                  R                  [        [        5       5      /SS9[         R                  R                  SSSSSSS9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                   /S[         R"                  " [         R$                  " S
S/S/S9SS9S9	$ )Nr[   zKrea 2 Imagepartner/image/Kreau   Generate images via Krea 2 — pick Medium (expressive illustrations) or Large (expressive photorealism). Supports an optional moodboard and up to 10 chained image style references.promptTrH   zText prompt for the image.)	multilinerF   rC   modelzeKrea 2 Medium is best for expressive illustrations; Krea 2 Large is best for expressive photorealism.rA   seedr   iz Random seed for reproducibility.)rF   rM   rN   control_after_generaterC   zmodel.moodboard_idzmodel.style_reference)widgetsinputsa  
                (
                  $rates := {
                    "krea 2 medium turbo": {"text": 0.015, "style": 0.0175, "moodboard": 0.02},
                    "krea 2 medium": {"text": 0.03, "style": 0.035, "moodboard": 0.04},
                    "krea 2 large": {"text": 0.06, "style": 0.065, "moodboard": 0.07}
                  };
                  $r := $lookup($rates, widgets.model);
                  $hasMoodboard := $length($lookup(widgets, "model.moodboard_id")) > 0;
                  $hasStyle := $lookup(inputs, "model.style_reference").connected;
                  $usd := $hasMoodboard ? $r.moodboard : ($hasStyle ? $r.style : $r.text);
                  {"type":"usd","usd": $usd}
                )
                )
depends_onexpr)	node_iddisplay_namecategorydescriptionre   outputshiddenis_api_nodeprice_badge)r   SchemarV   r   DynamicComboOption_MODEL_MEDIUMrY   _MODEL_MEDIUM_TURBO_MODEL_LARGEIntImageOutputHiddenauth_token_comfy_orgapi_key_comfy_org	unique_id
PriceBadgePriceBadgeDependsr   s    r   define_schemaKrea2ImageNode.define_schemaj   sU   yy$')8
 		"8	    %%..}>P>RS../BDVDXY..|=O=QR
H & 	 "+/>  #4 XX__&'		..		++		##
 //$&:;34U>
 >	
r   r_   ra   rb   c                 F  #    [        USSS9  US   n[        R                  U5      nUc  [        SU< 35      eS nUR                  S5      =(       d    SR	                  5       nU(       aS  [
        R                  U5      (       d  [        SU< S	35      eUR                  S
5      n[        Xxc  SO
[        U5      S9/nUR                  S5      n	S n
U	(       aP  [        U	5      S:  a  [        S[        U	5       S35      eU	 Vs/ s H  n[        US   [        US   5      S9PM     n
n[        U [        USS9[        [        UUS   US   UUS   UU
S9S9I S h  vN n[        U [        SUR                    3SS9[        S ["        S9I S h  vN nUR$                  (       a  UR$                  R&                  (       d  [)        SUR                    S 35      e[+        UR$                  R&                  S!   5      I S h  vN n[,        R.                  " U5      $ s  snf  N N N#7f)"NFr*   )strip_whitespace
min_lengthra   zUnknown Krea 2 model: rG   rH   z&moodboard_id must be a UUID (received z!); copy it from the Krea website.rJ   rK   )idstrengthrP   
   z;Krea 2 accepts at most 10 image_style_references; received .urlr   r   r   r%   r&   r@   rD   rE   )r_   r@   rD   rb   rE   
moodboardsimage_style_references)r,   dataz/proxy/krea/jobs/GETc                     U R                   $ N)status)rs    r   <lambda>(Krea2ImageNode.execute.<locals>.<lambda>   s    qxxr   )r,   status_extractorqueued_statuseszKrea 2 job z" completed without any image URLs.r   )r   r6   get
ValueErrorstrip_UUID_REmatchr   floatlenr	   r   r   r
   r   r   job_id_KREA_QUEUED_STATUSESresulturlsRuntimeErrorr   r   
NodeOutput)r   r_   ra   rb   model_choiceendpoint_pathr   mb_idmb_strengthrP   r   refinitialjobr    s                  r   executeKrea2ImageNode.execute   s     	1EW~(,,\: 5l5EFGG15
>*0b779>>%(( #I%Rs!tuu))$89K'5CV4\abm\nopJ))$56GK?#b( #^_bcr_s^ttu!vwwds&ds]`'CJs:AWXds # &  ]6:")">2 . .%'=	
 
 00@A%P"/1
 
 zzSZZL8Z[\\23::??13EFF}}U##7&

 GsC   DH!#H&3H!H2H!HA.H!;H< H!H!H!r   N)r   r   r   r   classmethodr   rp   r   strdictintr   r   r   r   r   r   r[   r[   h   s^    ?
bii ?
 ?
B 5$5$ 5$ 	5$
 
5$ 5$r   r[   c            
           \ rS rSr\S\R                  4S j5       r\ S
S\R                  S\
S\\   S-  S\R                  4S jj5       rS	rg)Krea2StyleReferenceNode   r!   c                    [         R                  " SSSS[         R                  R                  SSS9[         R                  R                  SS	S
SSSS9[         R
                  " [        R                  5      R                  SSSS9/[         R
                  " [        R                  5      R                  SS9/[         R                  R                  [         R                  R                  [         R                  R                  /S9$ )Nr   zKrea 2 Style Referencer^   zAdd an image style reference to a Krea 2 generation. Chain multiple Krea 2 Style Reference nodes (max 10) and feed the final `style_reference` output into Krea 2 Image. Each image is uploaded to ComfyAPI storage and passed as URL.r    z6Reference image whose style influences the generation.)rC   r   g      ?g       g       @rL   z?Reference strength; negative values invert the style influence.)rF   rM   rN   rO   rC   rP   TzHOptional incoming chain of style references; this node appends one more.rQ   )ri   )rh   ri   rj   rk   re   rl   rm   )r   rp   rw   r   rW   rX   r   r   rx   ry   rz   r{   r|   r   s    r   r   %Krea2StyleReferenceNode.define_schema   s    yy-1)c
 T   ]   		&**+11%!f 2 & YYv//077EV7WX		..		++		##;"
 "	
r   Nr    r   rP   c                    #    U(       a  [        U5      O/ n[        U5      S:  a  [        S5      e[        X5      I S h  vN nUR	                  U[        U5      S.5        [        R                  " U5      $  N77f)Nr   zCKrea 2 accepts at most 10 image_style_references in one generation.r   )listr   r   r5   appendr   r   r   )r   r    r   rP   chainr   s         r   r   Krea2StyleReferenceNode.execute  sd      6ED1"u:bcc0<<SeHo>?}}U## =s   =A9A7 8A9r   r   )r   r   r   r   r   r   rp   r   r   rw   r   r   r   r   r   r   r   r   r   r   r      sp    #
bii #
 #
J 
 .2	${{$ $ dd*	$
 
$ $r   r   c                   L    \ rS rSr\S\\\R                        4S j5       r	Sr
g)KreaExtensioni  r!   c                 "   #    [         [        /$ 7fr   )r[   r   )selfs    r   get_node_listKreaExtension.get_node_list  s      #
 	
s   r   N)r   r   r   r   r   r   typer   	ComfyNoder   r   r   r   r   r   r     s)    
T$r||*<%= 
 
r   r   c                     #    [        5       $ 7fr   )r   r   r   r   comfy_entrypointr   %  s     ?s   )-__doc__retyping_extensionsr   comfy_api.latestr   r   r   comfy_api_nodes.apis.krear   r   r	   r
   r   comfy_api_nodes.utilr   r   r   r   r   r   r   r   r   rw   r   r5   rs   rt   ru   r6   r   __annotations__rS   rT   rU   r   compiler   r   rY   r[   r   r   r   r   r   r   <module>r      s   " 	 & 6 6  ! !D,> u{{ WZ   + BN@$ $sCx.  Ov5 = ::fg(D (Vz$R\\ z$z4$bll 4$n
N 
 r   