
    +j              	       
   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JrJrJrJrJrJrJrJrJrJrJr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#J$r$J%r%  Sr&Sr' " S S	\RP                  5      r) " S
 S\RP                  5      r* " S S\RP                  5      r+ " S S\RP                  5      r, " S S\RP                  5      r- " S S\RP                  5      r.\R^                  " \R`                  " / SQS9SS9r1S\2S\34S jr4S\5\RP                     S\6S-  S\2S\3\
   S-  4S jr7S\5\RP                     S\	S\Rp                  4S  jr9 " S! S"\RP                  5      r: " S# S$\RP                  5      r; " S% S&\5      r<S\<4S' jr=g)(    N)override)IOComfyExtensionInput)Luma2GenerationLuma2GenerationRequestLuma2ImageRefLumaAspectRatioLumaCharacterRefLumaConceptChainLumaGenerationLumaGenerationRequestLumaImageGenerationRequestLumaImageIdentityLumaImageModelLumaImageReferenceLumaIOLumaKeyframesLumaModifyImageRefLumaReferenceLumaReferenceChainLumaVideoModelLumaVideoModelOutputDurationLumaVideoOutputResolutionget_luma_concepts)ApiEndpointdownload_url_to_image_tensordownload_url_to_video_outputpoll_opsync_opupload_image_to_comfyapiupload_images_to_comfyapivalidate_stringi   d   c            
           \ rS rSr\S\R                  4S j5       r\S
S\R                  S\
S\S\R                  4S jj5       rS	rg)LumaReferenceNode+   returnc                 r   [         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9/[         R
                  " [        R                  5      R                  SS9/S9$ )Nr'   zLuma Referencepartner/image/Lumaz@Holds an image and weight for use with Luma Generate Image node.imagezImage to use as reference.tooltipweight      ?        {Gz?zWeight of image reference.defaultminmaxstepr.   luma_refT)optionaldisplay_namenode_idr;   categorydescriptioninputsoutputs)	r   SchemaImager   FloatCustomr   LUMA_REFOutputclss    :/home/wildlama/comfy/ComfyUI/comfy_api_nodes/nodes_luma.pydefine_schemaLumaReferenceNode.define_schema,   s    yy'))Z8   8   		&//*00! 1 $ YYv/66J6OP/
 	
    Nr,   r/   r8   c           	          Ub  UR                  5       nO
[        5       nUR                  [        U[	        US5      S95        [
        R                  " U5      $ )N   r,   r/   )cloner   addr   roundr   
NodeOutput)rI   r,   r/   r8   s       rJ   executeLumaReferenceNode.executeH   sE    ~~'H)+H]uVQ7GHI}}X&&rM    N)__name__
__module____qualname____firstlineno__classmethodr   rB   rK   torchTensorfloatr   rT   rU   __static_attributes__rW   rM   rJ   r'   r'   +   s[    
bii 
 
6 'ELL '% 'CU 'acanan ' 'rM   r'   c                       \ rS rSr\S\R                  4S j5       r\ SS\S\S\S\S	\	S\R                  4S
 jj5       rSrg)LumaConceptsNodeR   r)   c                    [         R                  " SSSS[         R                  R                  S[	        SS9S9[         R                  R                  S	[	        SS9S9[         R                  R                  S
[	        SS9S9[         R                  R                  S[	        SS9S9[         R
                  " [        R                  5      R                  SSSS9/[         R
                  " [        R                  5      R                  SS9/S9$ )Nrc   zLuma Conceptspartner/video/LumazNCamera Concepts for use with Luma Text to Video and Luma Image to Video nodes.concept1T)include_noneoptionsconcept2concept3concept4luma_conceptsz8Optional Camera Concepts to add to the ones chosen here.r.   r9   r:   r<   )	r   rB   Combor   r   rE   r   LUMA_CONCEPTSrG   rH   s    rJ   rK   LumaConceptsNode.define_schemaS   s    yy&()h-4@   -4@   -4@   -4@   		&../55#V! 6 #. YYv334;;;YZ9
 	
rM   Nrg   rk   rl   rm   rn   c                 l    [        XX4/S9nUb  UR                  U5      n[        R                  " U5      $ )N)str_list)r   clone_and_merger   rT   )rI   rg   rk   rl   rm   rn   chains          rJ   rU   LumaConceptsNode.executet   s8     !8x*RS$!11%8E}}U##rM   rW   rX   )rY   rZ   r[   r\   r]   r   rB   rK   strr   rT   rU   ra   rW   rM   rJ   rc   rc   R   sw    
bii 
 
@  +/$$ $ 	$
 $ ($ 
$ $rM   rc   c                      \ rS rSr\S\R                  4S j5       r\   SS\S\S\S\	S	\
S-  S
\R                  S-  S\R                  S-  S\R                  4S jj5       r\S\
S\4S j5       r\S
\R                  S\	4S j5       rSrg)LumaImageGenerationNode   r)   c                    [         R                  " SSSS[         R                  R                  SSSSS	9[         R                  R                  S
[
        S9[         R                  R                  S[        [        R                  S9[         R                  R                  SSSS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                  SSSS9[         R                  R                  SSSS9/[         R                  R                  5       /[         R                  R                   [         R                  R"                  [         R                  R$                  /S[         R&                  " [         R(                  " S
/S 9S!S"9S#9	$ )$NLumaImageNodezLuma Text to Imager+   z@Generates images synchronously based on prompt and aspect ratio.promptT Prompt for the image generation	multiliner4   r.   modelri   aspect_ratiorj   r4   seedr       `Seed to determine if node should re-run; actual results are nondeterministic regardless of seed.r4   r5   r6   control_after_generater.   style_image_weightr0   r1   r2   z:Weight of style image. Ignored if no style_image provided.r3   image_luma_refzkLuma Reference node connection to influence generation with input images; up to 4 images can be considered.ro   style_imagez1Style reference image; only 1 image will be used.character_imagezYCharacter reference images; can be a batch of multiple, up to 4 images can be considered.widgetsV  
                (
                  $m := widgets.model;
                  $contains($m,"photon-flash-1")
                    ? {"type":"usd","usd":0.0027}
                    : $contains($m,"photon-1")
                      ? {"type":"usd","usd":0.0104}
                      : {"type":"usd","usd":0.0246}
                )
                
depends_onexpr	r=   r;   r>   r?   r@   rA   hiddenis_api_nodeprice_badge)r   rB   Stringr   rp   r   r
   
ratio_16_9IntrD   rE   r   rF   rC   rG   Hiddenauth_token_comfy_orgapi_key_comfy_org	unique_id
PriceBadgePriceBadgeDependsrH   s    rJ   rK   %LumaImageGenerationNode.define_schema   s   yy#-)Z		"=	    *   "++66  
 *+/~   (X   		&//*00$ J! 1 
 !O!  
 %w!  U/` XX__&'		..		++		##
 //	B	yI
 I	
rM   Nr~   r   r   r   r   r   r   c	                    #    [        USSS9  S n	Ub  U R                  USS9I S h  vN n	S n
Ub  U R                  XuS9I S h  vN n
S nUb"  [        XSS9I S h  vN n[	        [        US9S	9n[        U [        S
SS9[        [        UUUU	U
US9S9I S h  vN n[        U [        SUR                   3S9[        S S9I S h  vN n[        R                  " [        UR                  R                   5      I S h  vN 5      $  N N N Nr NG N7f)NT   strip_whitespace
min_length   max_refs)r/   
max_images)images)	identity0/proxy/luma/generations/imagePOSTpathmethod)r~   r   r   	image_ref	style_refcharacter_refresponse_modeldata/proxy/luma/generations/r   c                     U R                   $ rX   statexs    rJ   <lambda>1LumaImageGenerationNode.execute.<locals>.<lambda>       qwwrM   r   status_extractor)r#   _convert_luma_refs_convert_style_imager"   r   r   r    r   r   r   r   idr   rT   r   assetsr,   )rI   r~   r   r   r   r   r   r   r   api_image_refapi_style_refr   download_urlsresponse_apiresponse_polls                  rJ   rU   LumaImageGenerationNode.execute   s5     	!D%"%"8"8RS"8"TTM""%":":;":"bbM&";C]^"__M,7HP]7^_M$<VL)+)''+	
 
 &77HIJ).	
 
 }}#?@T@T@Z@Z#[[\\= U c `

 \si   $DDDDDD;DD,DD
6D9D:	DDDD
DDr8   r   c                    #    / nSnUR                    H?  n[        XR                  SS9I S h  vN nUR                  US   5        US-  nXB:  d  M?    O   UR	                  X2S9$  N77f)Nr      r   )r   r   )refsr"   r,   appendcreate_api_model)rI   r8   r   	luma_urls	ref_countrefr   s          rJ   r   *LumaImageGenerationNode._convert_luma_refs  sr     		==C";CWX"YYM]1-.NI$ ! ((y(TT Zs   +A'A% A'A'r/   c                 ^   #    [        [        XS9S9nU R                  USS9I S h  vN $  N7f)NrP   )	first_refr   r   )r   r   r   )rI   r   r/   rv   s       rJ   r   ,LumaImageGenerationNode._convert_style_image  s0     "]-\]++EA+>>>>s   $-+-rW   NNN)rY   rZ   r[   r\   r]   r   rB   rK   rx   r`   r   r^   r_   rT   rU   intr   r   ra   rW   rM   rJ   rz   rz      s   J
bii J
 J
X  59+//3-]-] -] 	-] "-] +T1-] \\D(-] ,-] 
-] -]^ 	U0B 	Uc 	U 	U ?U\\ ?5 ? ?rM   rz   c                       \ rS rSr\S\R                  4S j5       r\S\S\S\	R                  S\S\R                  4
S j5       rS	rg
)LumaImageModifyNodei  r)   c                    [         R                  " SSSS[         R                  R                  S5      [         R                  R                  SSSS	S
9[         R
                  R                  SSSSSSS9[         R                  R                  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9SS9S9	$ )Nr   zLuma Image to Imager+   z?Modifies images synchronously based on prompt and aspect ratio.r,   r~   Tr   r   r   image_weightg?r1   \(\?r2   zLWeight of the image; the closer to 1.0, the less the image will be modified.r3   r   ri   r   r   r   r   r   r   r   r   r   )r   rB   rC   r   r   rD   rp   r   r   rG   r   r   r   r   r   r   rH   s    rJ   rK   !LumaImageModifyNode.define_schema  s/   yy).)Y 		"=	    "j   *   *+/~  -> XX__&'		..		++		##
 //	B	W8
 8	
rM   r~   r   r,   r   c                   #    [        XSS9I S h  vN nUS   n[        U [        SSS9[        [	        UU[        U[        [        [        SU-
  S5      S	5      S
5      S9S9S9I S h  vN n[        U [        SUR                   3S9[        S S9I S h  vN n	[        R                  " [        U	R                  R                  5      I S h  vN 5      $  N Nn NC N7f)Nr   r   r   r   r   r   r0   r   r1   rO   )urlr/   )r~   r   modify_image_refr   r   r   c                     U R                   $ rX   r   r   s    rJ   r   -LumaImageModifyNode.execute.<locals>.<lambda>k  r   rM   r   )r"   r    r   r   r   r   rS   r6   r5   r   r   r   rT   r   r   r,   )
rI   r~   r   r,   r   r   r   	image_urlr   r   s
             rJ   rU   LumaImageModifyNode.executeP  s      8qQQ!!$	$<VL)+!3!%Cl8JD4QSV0WYZ*["	
 
 &77HIJ).	
 
 }}#?@T@T@Z@Z#[[\\) R

 \sF   CCAC'C(,CC6CC	CCCCrW   N)rY   rZ   r[   r\   r]   r   rB   rK   rx   r^   r_   r`   rT   rU   ra   rW   rM   rJ   r   r     ss    9
bii 9
 9
v ]] ] ||	]
 ] 
] ]rM   r   c                       \ rS rSr\S\R                  4S j5       r\ SS\S\S\S\S	\S
\	S\
S-  S\R                  4S jj5       rSrg)LumaTextToVideoGenerationNodeip  r)   c                 t   [         R                  " SSSS[         R                  R                  SSSSS	9[         R                  R                  S
[
        S9[         R                  R                  S[        [        R                  S9[         R                  R                  S[        [        R                  S9[         R                  R                  S[        S9[         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$                  R&                  [         R$                  R(                  [         R$                  R*                  /S[,        S9	$ )NLumaVideoNodezLuma Text to Videorf   z?Generates videos synchronously based on prompt and output_size.r~   Tr   Prompt for the video generationr   r   ri   r   r   
resolutiondurationloopFr4   r   r   r   r   r   rn   MOptional Camera Concepts to dictate camera motion via the Luma Concepts node.ro   r   )r   rB   r   r   rp   r   r
   r   r   res_540pr   Booleanr   rE   r   rq   VideorG   r   r   r   r   PRICE_BADGE_VIDEOrH   s    rJ   rK   +LumaTextToVideoGenerationNode.define_schemaq  s   yy#-)Y		"=	    *   "++66  
  55>>  
 8   

  ! !  *+/~   		&../55#k! 6 K*V XX__&'		..		++		##
 )o8
 8	
rM   Nr~   r   r   r   r   r   rn   c	                   #    [        USSS9  U[        R                  :w  a  UOS nU[        R                  :w  a  UOS n[        U [	        SSS9[
        [        UUUUUUU(       a  UR                  5       OS S9S9I S h  vN n	[        U [	        S	U	R                   3S
9[
        S [        S9I S h  vN n
[        R                  " [        U
R                  R                  5      I S h  vN 5      $  Nq NA N7f)NFr   r   /proxy/luma/generationsr   r   )r~   r   r   r   r   r   conceptsr   r   r   c                     U R                   $ rX   r   r   s    rJ   r   7LumaTextToVideoGenerationNode.execute.<locals>.<lambda>  r   rM   )r   r   estimated_duration)r#   r   ray_1_6r    r   r   r   r   r   r   LUMA_T2V_AVERAGE_DURATIONr   rT   r   r   video)rI   r~   r   r   r   r   r   r   rn   r   r   s              rJ   rU   %LumaTextToVideoGenerationNode.execute  s      	1E$(>(>>8D#(N,B,B#BZ
$6vF)&%)!=J779PT	
 
 &77HIJ).8
 
 }}#?@T@T@Z@Z#[[\\+

 \s6   A;C5=C/>1C5/C106C5&C3'	C51C53C5rW   rX   )rY   rZ   r[   r\   r]   r   rB   rK   rx   boolr   rT   rU   ra   rW   rM   rJ   r   r   p  s    9
bii 9
 9
v  26$]$] $] 	$]
 $] $] $] ($.$] 
$] $]rM   r   c                   
   \ rS rSr\S\R                  4S j5       r\   SS\S\S\S\S	\	S
\
R                  S\
R                  S\S\R                  4S jj5       r\  SS
\
R                  S\
R                  4S jj5       rSrg)LumaImageToVideoGenerationNodei  r)   c                    [         R                  " SSSS[         R                  R                  SSSSS	9[         R                  R                  S
[
        S9[         R                  R                  S[        [        R                  S9[         R                  R                  S[         Vs/ s H  oR                  PM     snS9[         R                  R                  SSS9[         R                  R                  SSSSSSS9[         R                  R                  SSSS9[         R                  R                  SSSS9[         R                  " [        R                  5      R                  SSSS9/	[         R                   R#                  5       /[         R$                  R&                  [         R$                  R(                  [         R$                  R*                  /S[,        S9	$ s  snf )NLumaImageToVideoNodezLuma Image to Videorf   zNGenerates videos synchronously based on prompt, input images, and output_size.r~   Tr   r   r   r   ri   r   r   r   r   Fr   r   r   r   r   r   first_imagezFirst frame of generated video.ro   
last_imagezLast frame of generated video.rn   r   r   )r   rB   r   r   rp   r   r   r   r   valuer   r   rC   rE   r   rq   r   rG   r   r   r   r   r   )rI   durs     rJ   rK   ,LumaImageToVideoGenerationNode.define_schema  s   yy*.)h		"=	    *    55>>  
 2NO2N3YY2NO   

  ! !  *+/~   !=!  
  <!  
 		&../55#k! 6 _4j XX__&'		..		++		##
 )CB
 B	
8 Ps   'G Nr~   r   r   r   r   r	  r
  rn   c
                 N  #    Uc  Uc  [        S5      eU R                  Xx5      I S h  vN n
U[        R                  :w  a  UOS nU[        R                  :w  a  UOS n[	        U [        SSS9[        [        UU[        R                  UUUU
U	(       a  U	R                  5       OS S9S9I S h  vN n[        U [        SUR                   3S9[        S	 [        S
9I S h  vN n[        R                  " [!        UR"                  R$                  5      I S h  vN 5      $  N Ns NC N7f)Nz=At least one of first_image and last_image requires an input.r   r   r   )r~   r   r   r   r   r   	keyframesr   r   r   r   c                     U R                   $ rX   r   r   s    rJ   r   8LumaImageToVideoGenerationNode.execute.<locals>.<lambda>A  r   rM   )poll_endpointr   r   r   )	Exception_convert_to_keyframesr   r   r    r   r   r   r
   r   r   r   r   LUMA_I2V_AVERAGE_DURATIONr   rT   r   r   r  )rI   r~   r   r   r   r   r   r	  r
  rn   r  r   r   s                rJ   rU   &LumaImageToVideoGenerationNode.execute  s     :#5[\\33KLL	$(>(>>8D#(N,B,B#BZ
$6vF)&,77%!#=J779PT		
 
 &%-ElooEV+WX).8
 
 }}#?@T@T@Z@Z#[[\\3 M

 \sF   &D%DBD%+D,1D%D!6D%D#	D%D%!D%#D%c                    #    Uc  Uc  g S nS nUb  [        XSS9I S h  vN n[        SUS   S9nUb  [        XSS9I S h  vN n[        SUS   S9n[        X4S9$  N< N7f)Nr   r   r,   r   )typer   )frame0frame1)r"   r   r   )rI   r	  r
  r  r  r   s         rJ   r  4LumaImageToVideoGenerationNode._convert_to_keyframesF  s      :#5"";CYZ"[[M'W-:JKF!";CXY"ZZM'W-:JKFF:: \ [s!   AA!A AAArW   r   )NN)rY   rZ   r[   r\   r]   r   rB   rK   rx   r  r^   r_   r   rT   rU   r  ra   rW   rM   rJ   r  r    s    C
bii C
 C
J  %)#'*.']'] '] 	']
 '] '] \\'] LL'] ('] 
'] ']R  %)#';\\; LL; ;rM   r  )r   r   r   r   a  
    (
      $p := {
        "ray-flash-2": {
          "5s": {"4k":3.13,"1080p":0.79,"720p":0.34,"540p":0.2},
          "9s": {"4k":5.65,"1080p":1.42,"720p":0.61,"540p":0.36}
        },
        "ray-2": {
          "5s": {"4k":9.11,"1080p":2.27,"720p":1.02,"540p":0.57},
          "9s": {"4k":16.4,"1080p":4.1,"720p":1.83,"540p":1.03}
        }
      };

      $m := widgets.model;
      $d := widgets.duration;
      $r := widgets.resolution;

      $modelKey :=
        $contains($m,"ray-flash-2") ? "ray-flash-2" :
        $contains($m,"ray-2") ? "ray-2" :
        $contains($m,"ray-1-6") ? "ray-1-6" :
        "other";

      $durKey := $contains($d,"5s") ? "5s" : $contains($d,"9s") ? "9s" : "";
      $resKey :=
        $contains($r,"4k") ? "4k" :
        $contains($r,"1080p") ? "1080p" :
        $contains($r,"720p") ? "720p" :
        $contains($r,"540p") ? "540p" : "";

      $modelPrices := $lookup($p, $modelKey);
      $durPrices := $lookup($modelPrices, $durKey);
      $v := $lookup($durPrices, $resKey);

      $price :=
        ($modelKey = "ray-1-6") ? 0.5 :
        ($modelKey = "other") ? 0.79 :
        ($exists($v) ? $v : 0.79);

      {"type":"usd","usd": $price}
    )
    r   max_image_refsr)   c                    [         R                  R                  SSS/SSS9[         R                  R                  SSSS	9[         R                  R                  S
[         R                  R                  [         R                  R                  S5      [        SU S-   5       Vs/ s H  nSU 3PM
     snSS9SSU  S3S9/$ s  snf )NstyleautomangazStyle preset. 'auto' picks based on the prompt; 'manga' applies a manga/anime aesthetic and requires a portrait aspect ratio (2:3, 9:16, 1:2, 1:3).rj   r4   r.   
web_searchFz7Search the web for visual references before generating.)r4   r.   r   r,   r   image_r   )namesr5   TzUp to z- reference images for style/content guidance.)templater9   r.   )r   rp   r   r   AutogrowTemplateNamesrC   range)r  is     rJ   _luma2_uni1_common_inputsr*    s    
W%2	 	 	
 	

M 	 	

 	[[..w'-21nq6H-IJ-Is|-IJ / 
 ^,,YZ 	 		
 $ Ks   "C rI   r   	max_countc                    #    U(       d  g / nU H1  n[        XU   5      I S h  vN nUR                  [        US95        M3     [        U5      U:  a  [	        SU S35      eU=(       d    S $  NI7f)Nr   zMaximum z reference images are allowed.)r!   r   r	   len
ValueError)rI   r   r+  outkeyr   s         rJ   _luma2_upload_image_refsr2    sp     
 !C,Ss)<<

=S)*  3x)8I;.LMNN;$	 =s   !A/A-A
A/requestc                   #    [        U [        SSS9[        US9I S h  vN nUR                  (       d  [	        S5      e[        U [        SUR                   3SS9[        S S	 S
9I S h  vN nUR                  (       d#  UR                  =(       d    Sn[	        SU 35      eUR                  S   R                  nU(       d  [	        S5      e[        U5      I S h  vN $  N Nx N7f)Nz/proxy/luma_2/generationsr   r   r   z*Luma 2 API did not return a generation id.z/proxy/luma_2/generations/GETc                     U R                   $ rX   r   rs    rJ   r   (_luma2_submit_and_poll.<locals>.<lambda>  s    177rM   c                     g rX   rW   r7  s    rJ   r   r9    s    TrM   )r   r   progress_extractorzno output returnedzLuma 2 generation failed: r   z2Luma 2 generation completed without an output URL.)
r    r   r   r   RuntimeErrorr   outputfailure_reasonr   r   )rI   r3  initialfinalmsgr   s         rJ   _luma2_submit_and_pollrB    s      4VD&	 G ::GHH5gjj\B5Q&*) E <<"":&:7u=>>
,,q/

COPP-c222+ 3s5   C'C!AC'*C#+A1C'C%C'#C'%C'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	)
r}   i  r)   c                 :   [         R                  " SSSS[         R                  R                  SSSSS	9[         R                  R                  S
[         R                  R                  S[         R                  R                  S/ SQSSS9/[        SS9Q5      [         R                  R                  S[         R                  R                  S/ SQSSS9/[        SS9Q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9SS9S9	$ ) NLumaImageNode2zLuma UNI-1 Imager+   z5Generate images from text using the Luma UNI-1 model.r~   Tr   u;   Text description of the desired image. 1–6000 characters.r   r   uni-1r   )
r  z3:1z2:1z16:9z3:2z1:12:39:161:21:3r  zJOutput image aspect ratio. 'auto' lets the model pick based on the prompt.r!  	   r  	uni-1-maxzModel to use for generation.rj   r.   r   r   _Seed controls whether the node should re-run; results are non-deterministic regardless of seed.r   model.image_refr   input_groupsa%  
                (
                  $m := widgets.model;
                  $refs := $lookup(inputGroups, "model.image_ref");
                  $base := $m = "uni-1-max" ? 0.1 : 0.0404;
                  {"type":"usd","usd": $round($base + 0.003 * $refs, 4)}
                )
                r   r   )r   rB   r   r   DynamicComboOptionrp   r*  r   rC   rG   r   r   r   r   r   r   rH   s    rJ   rK   LumaImageNode.define_schema  s   yy$+)O		"Y	    %%..# "$2-& -3-J !/ !"& ";!!L'0 ..' "$2-& -3-J !/ !"& ";!!L'31d ;i & 5l "+/H  {FN XX__&'		..		++		##
 //	QbPcd
g^
 ^	
rM   r~   r   r   c                   #    [        USSS9  US   nUS   n1 SknUS:X  a5  US:w  a/  XF;  a*  [        S	S
R                  [        U5      5       SU S35      e[	        UUS   SUS:w  a  UOS US:w  a  UOS SUS   [        XR                  S5      SS9I S h  vN S9n[        R                  " [        X5      I S h  vN 5      $  N- N
7f)Nr   p  r   
max_lengthr   r  >   rI  rJ  rG  rH  r   r  z0'manga' style requires a portrait aspect ratio (z, z) or 'auto'; got 'z'.r   r,   pngr"  r   rK  r+  )r~   r   r  r   r  output_formatr"  r   )
r#   r/  joinsortedr   r2  getr   rT   rB  )rI   r~   r   r   r   r  allowed_manga_ratiosr3  s           rJ   rU   LumaImageNode.execute4  s      	1>^,g<G 6<;cIIf%9:;<<N|n\^`  ).)5)?T F?%\*4S))K:P\]^^	
 }}#9##GGHH _Gs$   BCC$C:C;	CCrW   N)rY   rZ   r[   r\   r]   r   rB   rK   rx   dictr   rT   rU   ra   rW   rM   rJ   r}   r}     sg    _
bii _
 _
B II I 	I
 
I IrM   r}   c                       \ rS rSr\S\R                  4S j5       r\S\R                  S\
S\S\S\R                  4
S j5       rS	rg
)LumaImageEditNodeiQ  r)   c                    [         R                  " SSSS[         R                  R                  SSS9[         R                  R                  SS	S
SS9[         R
                  R                  S[         R
                  R                  S[        SS95      [         R
                  R                  S[        SS9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9SS9S9	$ )NLumaImageEditNode2zLuma UNI-1 Image Editr+   zEEdit an existing image with a text prompt using the Luma UNI-1 model.sourcezSource image to edit.r-   r~   Tr   u5   Description of the desired edit. 1–6000 characters.r   r   rF     rL  rM  zModel to use for editing.rN  r   r   rO  rP  r   rQ  rR  a'  
                (
                  $m := widgets.model;
                  $refs := $lookup(inputGroups, "model.image_ref");
                  $base := $m = "uni-1-max" ? 0.103 : 0.0434;
                  {"type":"usd","usd": $round($base + 0.003 * $refs, 4)}
                )
                r   r   )r   rB   rC   r   r   rT  rU  r*  r   rG   r   r   r   r   r   r   rH   s    rJ   rK   LumaImageEditNode.define_schemaS  s]   yy(0)_3   		"S	    %%..#5QG ..'5QG	 8 &  "+/H  3"F XX__&'		..		++		##
 //	QbPcd
_:
 :	
rM   rh  r~   r   r   c                 0  #    [        USSS9  [        UUS   S[        [        X5      I S h  vN S9US   S:w  a  US   OS S	US
   [	        XR                  S5      SS9I S h  vN S9n[        R                  " [        X5      I S h  vN 5      $  Nc N/ N7f)Nr   rX  rY  r   
image_editr-  r  r  r[  r"  r   ri  r\  )r~   r   r  rh  r  r]  r"  r   )	r#   r   r	   r!   r2  r`  r   rT   rB  )rI   rh  r~   r   r   r3  s         rJ   rU   LumaImageEditNode.execute  s      	1>(. +CC+P%PQ$)'Nf$<%.$\*4S))K:P\]^^	
 }}#9##GGHH &Q _Gs3   *BB5B"B#$BB	BBBrW   N)rY   rZ   r[   r\   r]   r   rB   rK   r   rC   rx   rc  r   rT   rU   ra   rW   rM   rJ   re  re  Q  ss    ;
bii ;
 ;
z II I 	I
 I 
I IrM   re  c                   L    \ rS rSr\S\\\R                        4S j5       r	Sr
g)LumaExtensioni  r)   c                 ^   #    [         [        [        [        [        [
        [        [        /$ 7frX   )rz   r   r   r  r'   rc   r}   re  )selfs    rJ   get_node_listLumaExtension.get_node_list  s)      $)*	
 		
s   +-rW   N)rY   rZ   r[   r\   r   listr  r   	ComfyNoderr  ra   rW   rM   rJ   ro  ro    s)    

T$r||*<%= 

 

rM   ro  c                     #    [        5       $ 7frX   )ro  rW   rM   rJ   comfy_entrypointrw    s     ?s   )>r^   typing_extensionsr   comfy_api.latestr   r   r   comfy_api_nodes.apis.lumar   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   comfy_api_nodes.utilr   r   r   r   r    r!   r"   r#   r  r  ru  r'   rc   rz   r   r   r  r   r   r   r   rt  r*  r  rc  r2  rC   rB  r}   re  ro  rw  rW   rM   rJ   <module>r|     s    & 6 6     .	 	 	    $' $'N.$r|| .$bM?bll M?`Z]",, Z]zb]BLL b]JA;R\\ A;H MM##,OP)
, ^c d 8	bll	
+  
-4	 3	bll	3#3 [[38~IBLL ~IBSI SIl
N 
 rM   