
    +j                     L   S SK r S SKJ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  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   " S S\R@                  5      r! " S	 S
\R@                  5      r" " S S\"5      r# " S S\R@                  5      r$ " S S\R@                  5      r% " S S\R@                  5      r& " S S\R@                  5      r' " S S\R@                  5      r( " S S\(5      r)SSS.r*S r+ " S S\R@                  5      r, " S S \5      r-S!\-4S" jr.g)#    N)	BaseModel)override)IOComfyExtensionInput)
BFLFluxEraseRequestBFLFluxExpandImageRequestBFLFluxFillImageRequest BFLFluxKontextProGenerateRequestBFLFluxProGenerateResponseBFLFluxProUltraGenerateRequestBFLFluxStatusResponseBFLFluxVTORequest	BFLStatusFlux2ProGenerateRequest)ApiEndpointconvert_mask_to_imagedownload_url_to_image_tensorget_number_of_imagespoll_opresize_mask_to_imagesync_optensor_to_base64_stringvalidate_aspect_ratio_stringvalidate_image_dimensionsvalidate_stringc                       \ rS rSr\S\R                  4S j5       r\S\4S j5       r	\     SS\S\S\
S	\
S
\S\R                  S-  S\S\R                  4S jj5       rSrg)FluxProUltraImageNode!   returnc                    [         R                  " SSSS[         R                  R                  SSSSS	9[         R                  R                  S
S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                  SSS9[         R                  R                  SSSSSS SS!9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                  " S"S#9S$9	$ )%Nr   zFlux 1.1 [pro] Ultra Imagepartner/image/BFLzQGenerates images using Flux Pro 1.1 Ultra via api based on prompt and resolution.promptT Prompt for the image generation	multilinedefaulttooltipprompt_upsamplingFWhether to perform upsampling on the prompt. If active, automatically modifies the prompt for more creative generation, but results are nondeterministic (same seed will not produce exactly the same result).r(   r)   advancedseedr       ,The random seed used for creating the noise.r(   minmaxcontrol_after_generater)   aspect_ratio16:93Aspect ratio of image; must be between 1:4 and 4:1.r(   r)   rawz@When True, generate less processed, more natural-looking images.image_promptoptionalimage_prompt_strength皙?g        g      ?g{Gz?z.Blend between the prompt and the image prompt.)r(   r2   r3   stepr)   r<   z{"type":"usd","usd":0.06}expr	node_iddisplay_namecategorydescriptioninputsoutputshiddenis_api_nodeprice_badge)r   SchemaStringr   BooleanIntImageFloatOutputHiddenauth_token_comfy_orgapi_key_comfy_org	unique_id
PriceBadgeclss    9/home/wildlama/comfy/ComfyUI/comfy_api_nodes/nodes_bfl.pydefine_schema#FluxProUltraImageNode.define_schema#   sy   yy+5(k		"=	    

  '!m " !  *+/J   		""Q   
 

  !^ ! 
 "!   +L!  K.^ XX__&'		..		++		##
 4w>
 >	
    r5   c                     [        USS5        g)N      ra   r`   T)r   )rY   r5   s     rZ   validate_inputs%FluxProUltraImageNode.validate_inputse   s    $\66Br]   Nr#   r*   r9   r.   r:   r=   c                 $  #    Uc
  [        USS9  [        U [        SSS9[        [	        UUUUUUc  UO
[        U5      Uc  S O[        US5      S9S9I S h  vN n[        U [        UR                  5      [        S	 S
 [        R                  /[        R                  [        R                  [        R                  [        R                  // S9I S h  vN n	[         R"                  " [%        U	R&                  S   5      I S h  vN 5      $  N N: N7f)NFstrip_whitespacez&/proxy/bfl/flux-pro-1.1-ultra/generatePOSTpathmethod   )r#   r*   r.   r5   r9   r:   r=   response_modeldatac                     U R                   $ Nstatusrs    rZ   <lambda>/FluxProUltraImageNode.execute.<locals>.<lambda>       qxxr]   c                     U R                   $ rq   progressrt   s    rZ   rv   rw          r]   rn   status_extractorprogress_extractorcompleted_statusesfailed_statusesqueued_statusessample)r   r   r   r   r   r   roundr   polling_urlr   r   readyrequest_moderatedcontent_moderatederrortask_not_foundr   
NodeOutputr   result)
rY   r#   r5   r*   r9   r.   r:   r=   initial_responseresponses
             rZ   executeFluxProUltraImageNode.executej   s	     FU;!(EfU5/"3).:.BlH_`lHm/;/CtOdfgIh	"
 
 !(4450/3 )0++++((	 
 
 }}#?PX@Y#ZZ[[;

 [s7   ADD
A;DD/DD	DDD )FFr   Nr>   )__name__
__module____qualname____firstlineno__classmethodr   rL   r[   strrc   boolintr   rP   floatr   r   __static_attributes__r   r]   rZ   r   r   !   s    ?
bii ?
 ?
B 3   
 #(+/'*)\)\ )\  	)\
 )\ )\ kkD()\  %)\ 
)\ )\r]   r   c                       \ rS rSr\S\R                  4S j5       rSrS r	Sr
\   SS\S\S	\S
\S\R                  S-  S\R                   4S jj5       rSrg)FluxKontextProImageNode   r    c                    [         R                  " U R                  U R                  SS[         R                  R                  SSSSS9[         R                  R                  SS	S
S9[         R                  R                  SSSSSSS9[         R                  R                  SSSSSS9[         R                  R                  SSSSSSS9[         R                  R                  SSS SS!9[         R                  R                  S"SS#9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /SS$9$ )%Nr"   zQEdits images using Flux.1 Kontext [pro] via api based on prompt and aspect ratio.r#   Tr$   z?Prompt for the image generation - specify what and how to edit.r&   r5   r6   r7   r8   guidanceg      @r>   g     X@2Guidance strength for the image generation process)r(   r2   r3   r?   r)   steps2   r`      0Number of steps for the image generation processr(   r2   r3   r)   r.   i  r   r/   r0   r1   r*   Fr+   r,   input_imager;   )rC   rD   rE   rF   rG   rH   rI   rJ   )r   rL   NODE_IDDISPLAY_NAMErM   r   rQ   rO   rN   rP   rR   rS   rT   rU   rV   rX   s    rZ   r[   %FluxKontextProImageNode.define_schema   ss   yyKK))(k		"]	    		""Q   
 P   N    *+/J   

  '! m!	 !  !!  S-\ XX__&'		..		++		##
 s:
 :	
r]   z$/proxy/bfl/flux-kontext-pro/generatezFlux.1 Kontext [pro] ImageNr#   r5   r   r   r   c                 H  #    [        USS5        Uc
  [        USS9  [        U [        U R                  SS9[
        [        UU[        US5      UUUUc  UO
[        U5      S9S	9I S h  vN n[        U [        UR                  5      [        S
 S [        R                  /[        R                  [        R                  [        R                   [        R"                  // S9I S h  vN n	[$        R&                  " [)        U	R*                  S   5      I S h  vN 5      $  N N: N7f)Nr_   rb   Frf   rh   ri   r`   )r#   r*   r   r   r.   r5   r   rm   c                     U R                   $ rq   rr   rt   s    rZ   rv   1FluxKontextProImageNode.execute.<locals>.<lambda>   rx   r]   c                     U R                   $ rq   rz   rt   s    rZ   rv   r      r|   r]   r}   r   )r   r   r   r   BFL_PATHr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )
rY   r#   r5   r   r   r   r.   r*   r   r   s
             rZ   r   FluxKontextProImageNode.execute   s     	%\66BFU;!(S\\&951"3x+),7,?[E\]hEi	"
 
 !(4450/3 )0++++((	 
 
 }}#?PX@Y#ZZ[[;

 [s7   A%D"'D(A;D"#D$/D"D 	D"D" D"r   )Nr   F)r   r   r   r   r   r   rL   r[   r   r   r   r   r   r   r   rP   r   r   r   r   r]   rZ   r   r      s    ;
bii ;
 ;
z 6H'G/L +/*\*\ *\ 	*\
 *\ [[4'*\ 
*\ *\r]   r   c                   $    \ rS rSrSrSrS rSrSrg)FluxKontextMaxImageNodei	  zQEdits images using Flux.1 Kontext [max] via api based on prompt and aspect ratio.z$/proxy/bfl/flux-kontext-max/generatezFlux.1 Kontext [max] Imager   N)	r   r   r   r   DESCRIPTIONr   r   r   r   r   r]   rZ   r   r   	  s    eK5H'G/Lr]   r   c                       \ rS rSr\S\R                  4S j5       r\ SS\R                  S\
S\S\S\S	\S
\S\S\S\R                  4S jj5       rSrg)FluxProExpandNodei  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9[         R                  R                  SSSSSS9[         R                  R                  SSSSSS9[         R                  R                  SSSSSS9[         R                  R                  SSSSSS9[         R                  R                  SSSSSS9[         R                  R                  SS S!S S"S9[         R                  R                  S#SSS$SS%S&9/
[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                  " S'S(9S)9	$ )*Nr   zFlux.1 Expand Imager"   z Outpaints image based on prompt.imager#   Tr$   r%   r&   r*   Fr+   r,   topr      z2Number of pixels to expand at the top of the imager   bottomz5Number of pixels to expand at the bottom of the imageleftz3Number of pixels to expand at the left of the imagerightz4Number of pixels to expand at the right of the imager   <         ?d   r   r   r      r   r.   r/   r0   r1   {"type":"usd","usd":0.05}r@   rB   )r   rL   rP   r   rM   rN   rO   rQ   rR   rS   rT   rU   rV   rW   rX   s    rZ   r[   FluxProExpandNode.define_schema  s   yy'.(:w'		"=	    

  '!m " !  P   S   Q   R   P   N   *+/J  uBF XX__&'		..		++		##
 4_R
 R	
r]   r   r#   r*   r   r   r   r   r   r   c                   #    [        U [        SSS9[        [        UUUUUUUU	U
[	        U5      S9
S9I S h  vN n[        U [        UR                  5      [        S S [        R                  /[        R                  [        R                  [        R                  [        R                  // S9I S h  vN n[        R                  " [!        UR"                  S	   5      I S h  vN 5      $  N N: N7f)
Nz'/proxy/bfl/flux-pro-1.0-expand/generaterh   ri   )
r#   r*   r   r   r   r   r   r   r.   r   rm   c                     U R                   $ rq   rr   rt   s    rZ   rv   +FluxProExpandNode.execute.<locals>.<lambda>  rx   r]   c                     U R                   $ rq   rz   rt   s    rZ   rv   r     r|   r]   r}   r   )r   r   r   r	   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rY   r   r#   r*   r   r   r   r   r   r   r.   r   r   s                rZ   r   FluxProExpandNode.executei  s      ")FvV5*"3!-e4	"
 
" !(4450/3 )0++++((	 
 
 }}#?PX@Y#ZZ[[A
"
 [s4   5C2C,A;C23C.4/C2#C0$	C2.C20C2r   Nr   r   r   r   r   r   r   rL   r[   r   rP   r   r   r   r   r   r   r   r   r]   rZ   r   r     s    S
bii S
 S
j  -\{{-\ -\  	-\
 -\ -\ -\ -\ -\ -\ 
-\ -\r]   r   c                       \ rS rSr\S\R                  4S j5       r\ SS\R                  S\R                  S\
S\S\S	\S\R                  4S
 jj5       rSrg)FluxProFillNodei  r    c                    [         R                  " SSSS[         R                  R                  S5      [         R                  R                  S5      [         R
                  R                  SSS	S
S9[         R                  R                  SSSSS9[         R                  R                  SSSSSS9[         R                  R                  SSSSSS9[         R                  R                  SSSSSSS9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                  " SS 9S!9	$ )"Nr   zFlux.1 Fill Imager"   z(Inpaints image based on mask and prompt.r   maskr#   Tr$   r%   r&   r*   Fr+   r,   r   r   r   r   r   r   r   r   r   r   r.   r   r/   r0   r1   r   r@   rB   )r   rL   rP   r   MaskrM   rN   rQ   rO   rR   rS   rT   rU   rV   rW   rX   s    rZ   r[   FluxProFillNode.define_schema  sY   yy%,(Bw'f%		"=	    

  '!m " !  P   N   *+/J  ?'P XX__&'		..		++		##
 4i7
 7	
r]   r   r   r#   r*   r   r   c                 >  #    [        X!5      n[        [        U5      5      n[        U [	        SSS9[
        [        UUUUU[        US S 2S S 2S S 2S S24   5      US9S9I S h  vN n[        U [	        UR                  5      [        S S [        R                  /[        R                  [        R                  [        R                  [        R                  // S	9I S h  vN n	[         R"                  " [%        U	R&                  S
   5      I S h  vN 5      $  N N: N7f)Nz%/proxy/bfl/flux-pro-1.0-fill/generaterh   ri      )r#   r*   r   r   r.   r   r   rm   c                     U R                   $ rq   rr   rt   s    rZ   rv   )FluxProFillNode.execute.<locals>.<lambda>  rx   r]   c                     U R                   $ rq   rz   rt   s    rZ   rv   r     r|   r]   r}   r   )r   r   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   )
rY   r   r   r#   r*   r   r   r.   r   r   s
             rZ   r   FluxProFillNode.execute  s     $D0&'<T'BC!(DVT5("3!-eAq!RaRK.@A	"
 
 !(4450/3 )0++++((	 
 
 }}#?PX@Y#ZZ[[;

 [s7   A D"D#A;DD/DD	DDDr   Nr   r   r   r]   rZ   r   r     s    8
bii 8
 8
t  *\{{*\ kk*\ 	*\
  *\ *\ *\ 
*\ *\r]   r   c                       \ rS rSr\S\R                  4S j5       r\  SS\R                  S\R                  S\
S\
S\R                  4
S jj5       rS	rg
)FluxEraseNodei  r    c                 (   [         R                  " SSSS[         R                  R                  S5      [         R                  R                  SSS9[         R
                  R                  S	S
SSSS9[         R
                  R                  SSSSSSSS9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                  " SS9S9	$ )Nr   zFlux Erase Imager"   ztRemoves the masked object from an image and reconstructs the background. Paint the mask over what you want to erase.r   r   z3White areas are removed; black areas are preserved.r)   dilate_pixels
   r      zKExpands the mask boundaries to ensure clean coverage of the object's edges.r   r.   iTr0   )r(   r2   r3   r4   r)   r<   zP{"type":"range_usd","min_usd":0.03,"max_usd":0.06,"format":{"approximate":true}}r@   rB   )r   rL   rP   r   r   rO   rR   rS   rT   rU   rV   rW   rX   s    rZ   r[   FluxEraseNode.define_schema  s    yy#+(: w'f.cd#i   "+/J!  ( XX__&'		..		++		##
 kC$
 $	
r]   r   r   r   r.   c                   ^#    [        USSS9  [        X!5      n[        [        U5      5      n[	        U [        SSS9[        [        [        US S 2S S 2S S 2S S24   5      UUUS9S9I S h  vN mS	[        S
[        S -  4U4S jjn[        U [        TR                  5      [        S S U[        R                  /[        R                  [        R                   [        R"                  [        R$                  // S9	I S h  vN n[&        R(                  " [+        UR,                  S   5      I S h  vN 5      $  N N: N7f)N   )	min_width
min_heightz!/proxy/bfl/v1/flux-tools/erase-v1rh   ri   r   )r   r   r   r.   rm   _rr    c                 @   > TR                   c  S $ TR                   S-  $ Nr   costr   r   s    rZ   price_extractor.FluxEraseNode.execute.<locals>.price_extractorF  &    +0084Y>N>S>SVY>YYr]   c                     U R                   $ rq   rr   rt   s    rZ   rv   'FluxEraseNode.execute.<locals>.<lambda>M  rx   r]   c                     U R                   $ rq   rz   rt   s    rZ   rv   r   N  r|   r]   rn   r~   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rY   r   r   r   r.   r   r   r   s          @rZ   r   FluxEraseNode.execute/  s,     	"%33G#D0&'<T'BC!(@P5$-eAq!RaRK.@A+		
"
 

	Z	 	Zedl 	Z !(4450/3+ )0++++((	 
 
  }}#?PX@Y#ZZ[[?


  [s7   A(D>+D8,BD>?D: /D>/D<0	D>:D><D>r   N)r   r   )r   r   r   r   r   r   rL   r[   r   rP   r   r   r   r   r   r]   rZ   r   r     s    %
bii %
 %
N 
  )\{{)\ kk)\ 	)\
 )\ 
)\ )\r]   r   c                       \ rS rSr\S\R                  4S j5       r\  SS\R                  S\R                  S\
S\S\R                  4
S jj5       rS	rg
)FluxVTONodei\  r    c                 "   [         R                  " SSSS[         R                  R                  SSS9[         R                  R                  SS	S9[         R                  R                  S
SSSS9[         R
                  R                  SSSSSSS9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                  " SS9S9	$ )Nr   zFlux Virtual Try-Onr"   z;Virtual try-on: dresses the person in the provided garment.personzImage of the person to dress.r   garmentzImage of the garment to apply.r#   Tr$   zPOptional natural-language styling instruction (e.g. how the garment should fit).r&   r.   r   r/   r0   r1   zS{"type":"range_usd","min_usd":0.0375,"max_usd":0.075,"format":{"approximate":true}}r@   rB   )r   rL   rP   r   rM   rO   rR   rS   rT   rU   rV   rW   rX   s    rZ   r[   FluxVTONode.define_schema^  s    yy!.(Ux1PQy2RS		"n	    *+/J  $ XX__&'		..		++		##
 n=!
 !	
r]   r   r   r#   r.   c                 \  ^#    [        U [        SSS9[        [        U[	        US S 2S S 2S S 2S S24   5      [	        US S 2S S 2S S 2S S24   5      US9S9I S h  vN mS[
        S[        S -  4U4S	 jjn[        U [        TR                  5      [        S
 S U[        R                  /[        R                  [        R                  [        R                  [        R                  // S9	I S h  vN n[         R"                  " [%        UR&                  S   5      I S h  vN 5      $  N N: N7f)Nz/proxy/bfl/v1/flux-tools/vto-v1rh   ri   r   )r#   r   r   r.   rm   r   r    c                 @   > TR                   c  S $ TR                   S-  $ r   r   r   s    rZ   r   ,FluxVTONode.execute.<locals>.price_extractor  r   r]   c                     U R                   $ rq   rr   rt   s    rZ   rv   %FluxVTONode.execute.<locals>.<lambda>  rx   r]   c                     U R                   $ rq   rz   rt   s    rZ   rv   r     r|   r]   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rY   r   r   r#   r.   r   r   r   s          @rZ   r   FluxVTONode.execute  s     ")>vN5".vaArrk/BC/1a!0DE		
"
 

	Z	 	Zedl 	Z !(4450/3+ )0++++((	 
 
  }}#?PX@Y#ZZ[[?


  [s7   AD,D&BD,-D(./D,D*	D,(D,*D,r   N)r$   r   )r   r   r   r   r   r   rL   r[   r   rP   r   r   r   r   r   r   r]   rZ   r   r   \  s    "
bii "
 "
H 
 &\&\ &\ 	&\
 &\ 
&\ &\r]   r   c                       \ rS rSrS rSrSrSr\S\	R                  4S j5       r\ SS\S	\S
\S\S\S\R                   S-  S\	R"                  4S jj5       rSrg)Flux2ProImageNodei  zFlux.2 [pro] Image/proxy/bfl/flux-2-pro/generatea  
    (
      $MP := 1024 * 1024;
      $outMP := $max([1, $floor(((widgets.width * widgets.height) + $MP - 1) / $MP)]);
      $outputCost := 0.03 + 0.015 * ($outMP - 1);
      inputs.images.connected
        ? {
            "type":"range_usd",
            "min_usd": $outputCost + 0.015,
            "max_usd": $outputCost + 0.12,
            "format": { "approximate": true }
          }
        : {"type":"usd","usd": $outputCost}
    )
    r    c                    [         R                  " U R                  U R                  SS[         R                  R                  SSSSS9[         R                  R                  SS	S
SSS9[         R                  R                  SSS
SSS9[         R                  R                  SSSSSSS9[         R                  R                  S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/S/S9U R                   S9SS9
$ )Nr"   z>Generates images synchronously based on prompt and resolution.r#   Tr$   'Prompt for the image generation or editr&   width   r   r       r(   r2   r3   r?   height   r.   r   r/   r0   r1   r*   zwWhether to perform upsampling on the prompt. If active, automatically modifies the prompt for more creative generation.r,   imagesz(Up to 9 images to be used as references.)r<   r)   )widgetsrG   
depends_onrA   )
rC   rD   rE   rF   rG   rH   rI   rJ   rK   is_deprecated)r   rL   r   r   rM   r   rO   rN   rP   rR   rS   rT   rU   rV   rW   PriceBadgeDependsPRICE_BADGE_EXPRrX   s    rZ   r[   Flux2ProImageNode.define_schema  s   yyKK))(X		"E	           *+/J   

  ' a! !  x$@jkI%L XX__&'		..		++		##
 //(8KU]T^_)) m7
 7	
r]   Nr#   r  r  r.   r*   r  c                   ^#    0 nUbX  [        U5      S:  a  [        S5      e[        UR                  S   5       H"  nU(       a  SUS-    3OSn	[	        Xh   SS9Xy'   M$     [        U [        U R                  S	S
9[        [        SUUUUUS.UD6S9I S h  vN mS[        S[        S -  4U4S jjn
[        U [        TR                  5      [        S S U
[        R                   /[        R"                  [        R$                  [        R&                  [        R(                  // S9	I S h  vN n[*        R,                  " [/        UR0                  S   5      I S h  vN 5      $  N N: N7f)N	   z4The current maximum number of supported images is 9.r   input_image_r`   r     @ total_pixelsrh   ri   )r#   r  r  r.   r*   rm   r   r    c                 @   > TR                   c  S $ TR                   S-  $ r   r   r   s    rZ   r   2Flux2ProImageNode.execute.<locals>.price_extractor  r   r]   c                     U R                   $ rq   rr   rt   s    rZ   rv   +Flux2ProImageNode.execute.<locals>.<lambda>#  rx   r]   c                     U R                   $ rq   rz   rt   s    rZ   rv   r  $  r|   r]   r   r   r   )r   
ValueErrorrangeshaper   r   r   API_ENDPOINTr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rY   r#   r  r  r.   r*   r  reference_imagesimage_indexkey_namer   r   r   s               @rZ   r   Flux2ProImageNode.execute  sp     #F+a/ !WXX$V\\!_5?J\+/):;P]-DVEXgr-s *  6 ")S--f=5( "3 #	"
 
	Z	 	Zedl 	Z !(4450/3+ )0++++((	 
 
  }}#?PX@Y#ZZ[[C
"
  [s7   BE(E"BE()E$*/E(E&	E($E(&E(r   rq   )r   r   r   r   r   r   r  r  r   r   rL   r[   r   r   r   r   rP   r   r   r   r   r]   rZ   r   r     s    !G'L3L  8
bii 8
 8
t  &*1\1\ 1\ 	1\
 1\  1\ d"1\ 
1\ 1\r]   r   c                   $    \ rS rSrS rSrSrSrSrg)Flux2MaxImageNodei2  zFlux.2 [max] Image/proxy/bfl/flux-2-max/generatea  
    (
      $MP := 1024 * 1024;
      $outMP := $max([1, $floor(((widgets.width * widgets.height) + $MP - 1) / $MP)]);
      $outputCost := 0.07 + 0.03 * ($outMP - 1);

      inputs.images.connected
        ? {
            "type":"range_usd",
            "min_usd": $outputCost + 0.03,
            "max_usd": $outputCost + 0.24,
            "format": { "approximate": true }
          }
        : {"type":"usd","usd": $outputCost}
    )
    r   N)	r   r   r   r   r   r   r  r  r   r   r]   rZ   r$  r$  2  s    !G'L3Lr]   r$  r   r%  )Flux.2 [pro]Flux.2 [max]c                  |   [         R                  R                  SSSSSS9[         R                  R                  SSSSSS9[         R                  R                  S	[         R                  R	                  [         R
                  R                  S
5      [        SS5       V s/ s H  n SU  3PM
     sn SS9SS9/$ s  sn f )Nr  r  r   r   r  r  r  r  r  r   r`   r  image_r   )namesr2   zJOptional reference image(s) for image-to-image generation. Up to 8 images.)templater)   )r   rO   r   AutogrowTemplateNamesrP   r  )is    rZ   _flux2_model_inputsr/  O  s    
 	 	
 	 	 	
 	[[..w'-21a[9[s|[9 / 
 a 	 	
 & :s    B9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	)
Flux2ImageNodeik  r    c                    [         R                  " SSSS[         R                  R                  SSSSS	9[         R                  R                  S
[         R                  R                  S[        5       5      [         R                  R                  S[        5       5      /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QS/S9SS9S9	$ )Nr1  zFlux.2 Imager"   z]Generate images via Flux.2 [pro] or Flux.2 [max] from a prompt and optional reference images.r#   Tr$   r  r&   modelr&  r'  )optionsr.   r   r/   r0   r1   )r3  zmodel.widthzmodel.heightzmodel.images)r	  input_groupsa  
                (
                  $isMax := widgets.model = "flux.2 [max]";
                  $MP := 1024 * 1024;
                  $w := $lookup(widgets, "model.width");
                  $h := $lookup(widgets, "model.height");
                  $outMP := $max([1, $floor((($w * $h) + $MP - 1) / $MP)]);
                  $outputCost := $isMax
                    ? (0.07 + 0.03 * ($outMP - 1))
                    : (0.03 + 0.015 * ($outMP - 1));
                  $refMin := $isMax ? 0.03 : 0.015;
                  $refMax := $isMax ? 0.24 : 0.12;
                  $hasRefs := $lookup(inputGroups, "model.images") > 0;
                  $hasRefs
                    ? {
                        "type": "range_usd",
                        "min_usd": $outputCost + $refMin,
                        "max_usd": $outputCost + $refMax,
                        "format": { "approximate": true }
                      }
                    : {"type": "usd", "usd": $outputCost}
                )
                r
  rB   )r   rL   rM   r   DynamicComboOptionr/  rO   rP   rR   rS   rT   rU   rV   rW   r  rX   s    rZ   r[   Flux2ImageNode.define_schemam  s.   yy$'(w		"E	    %%..~?R?TU..~?R?TU &  *+/J  . XX__&'		..		++		##
 //D"0!1G@
 @	
r]   r#   r3  r.   c                 :  ^^#    US   n[         U   nUS   nUS   nUR                  S5      =(       d    0 nUR                  5        V	s/ s H	  oc  M  U	PM     n
n	[        S U
 5       5      nUS:  a  [	        S5      e/ nU
 H`  m[        TR                  5      S:X  a3  UR                  U4S	 j[        TR                  S
   5       5       5        MO  UR                  T5        Mb     0 n[        U5       H#  u  nmU(       a  SUS-    3OSn[        TSS9X'   M%     [        U [        USS9[        [        SUUUUS.UD6S9I S h  vN mS[         S["        S -  4U4S jjn[%        U [        TR&                  5      [(        S S U[*        R,                  /[*        R.                  [*        R0                  [*        R2                  [*        R4                  // S9	I S h  vN n[6        R8                  " [;        UR<                  S   5      I S h  vN 5      $ s  sn	f  N N? N7f)Nr3  r  r  r  c              3   8   #    U  H  n[        U5      v   M     g 7frq   )r   ).0ts     rZ   	<genexpr>)Flux2ImageNode.execute.<locals>.<genexpr>  s     F1+A..s      z4The current maximum number of supported images is 8.ra   c              3   .   >#    U  H
  nTU   v   M     g 7frq   r   )r;  r.  tensors     rZ   r=  r>    s     #N7M!F1I7Ms   r   r  r`   r   r  r  rh   ri   )r#   r  r  r.   rm   r   r    c                 @   > TR                   c  S $ TR                   S-  $ r   r   r   s    rZ   r   /Flux2ImageNode.execute.<locals>.price_extractor  r   r]   c                     U R                   $ rq   rr   rt   s    rZ   rv   (Flux2ImageNode.execute.<locals>.<lambda>  rx   r]   c                     U R                   $ rq   rz   rt   s    rZ   rv   rE    r|   r]   r   r   r   )_FLUX2_MODEL_ENDPOINTSgetvaluessumr  lenr  extendr  append	enumerater   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rY   r#   r3  r.   model_choiceendpointr  r  images_dictr<  image_tensorsn_imagesflat_tensorsr  idxr!  r   r   r   rA  s                     @@rZ   r   Flux2ImageNode.execute  s     W~),7gxii)/R7B7I7I7K+]7K!A7K+]FFFa<STT+-#F6<< A%###NuV\\!_7M#NN##F+	 $ ,.$\2KC36cAgY/MH)@Va)b& 3 ")Xf55( 	
 #	"
 
	Z	 	Zedl 	Z !(4450/3+ )0++++((	 
 
  }}#?PX@Y#ZZ[[c ,^"
 
  [sJ   AH	HHC*HHBHH/HHHHHr   N)r   r   r   r   r   r   rL   r[   r   dictr   r   r   r   r   r]   rZ   r1  r1  k  sg    A
bii A
 A
F =\=\ =\ 	=\
 
=\ =\r]   r1  c                   L    \ rS rSr\S\\\R                        4S j5       r	Sr
g)BFLExtensioni  r    c           
      r   #    [         [        [        [        [        [
        [        [        [        [        /
$ 7frq   )
r   r   r   r   r   r   r   r   r$  r1  )selfs    rZ   get_node_listBFLExtension.get_node_list  s/      "##
 	
s   57r   N)r   r   r   r   r   listtyper   	ComfyNoder\  r   r   r]   rZ   rY  rY    s)    
T$r||*<%= 
 
r]   rY  r    c                     #    [        5       $ 7frq   )rY  r   r]   rZ   comfy_entrypointrb    s     >s   )/torchpydanticr   typing_extensionsr   comfy_api.latestr   r   r   comfy_api_nodes.apis.bflr   r	   r
   r   r   r   r   r   r   r   comfy_api_nodes.utilr   r   r   r   r   r   r   r   r   r   r   r`  r   r   r   r   r   r   r   r   r$  rG  r/  r1  rY  rb  r   r]   rZ   <module>ri     s&     & 6 6     s\BLL s\lo\bll o\d05 0F\ F\Rh\bll h\VT\BLL T\nN\",, N\bB\ B\J) 0 54 8D\R\\ D\N
> 
" r]   