
    3j                    
   S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
r
S SKrS SKJrJrJr  S SKJr  S SKrS SKr\R,                  R/                  S \R,                  R1                  \R,                  R3                  \R,                  R5                  \5      5      S5      5        S SKrS SKrS SKrS SK rS SK!rS SK"rS SK#J$r$J%r%J&r&J'r'  S SK(J)r)J*r*  S SK+J,r,  S SK-J.r.J/r/J0r0  S SK1rS SK2rS S	K3J4r4  S SK5r5S SK6r6S SK7r7S SK8r8\4Rr                  (       a  S SK:r:S
 r;SS jr<Sr= " S S\%5      r> " S S5      r? " S S5      r@ " S S5      rA " S S5      rB " S S5      rC " S S5      rD " S S5      rE " S S5      rF " S S 5      rG " S! S"5      rH " S# S$5      rI " S% S&5      rJ " S' S(5      rK " S) S*5      rL " S+ S,5      rM " S- S.5      rN " S/ S05      rO " S1 S25      rP " S3 S45      rQ " S5 S65      rR " S7 S85      rS " S9 S:5      rT " S; S<5      rU " S= S>\U5      rV " S? S@5      rW " SA SB5      rX " SC SD5      rY " SE SF5      rZ " SG SH5      r[ " SI SJ5      r\ " SK SL5      r] " SM SN5      r^ " SO SP5      r_ " SQ SR5      r` " SS ST5      ra " SU SV5      rb " SW SX5      rc " SY SZ5      rd " S[ S\5      re " S] S^5      rf " S_ S`5      rg " Sa Sb5      rh " Sc Sd5      ri " Se Sf5      rj " Sg Sh5      rk " Si Sj5      rl " Sk Sl5      rm " Sm Sn5      rn " So Sp5      ro " Sq Sr5      rpSSs jrq " St Su5      rr " Sv Sw5      rs " Sx Sy5      rt " Sz S{\t5      ru " S| S}5      rv " S~ S\v5      rw " S S\v5      rx " S S5      ry " S S5      rz " S S5      r{ " S S5      r| " S S5      r} " S S5      r~0 Su\r_S4\Q_S\>_S:\T_S"\H_S&\J_S*\L_S@\W_S^\f_Sd\i_Sf\j_S`\g_Sb\h_Sy\t_S{\u_S}\v_S\w_0 S\x_S\y_S\z_S\{_S\|_S\~_S\}_S\@_S\?_S\A_S\B_S\C_S\D_S\E_Sw\s_Sr\p_Sl\m_E0 Sn\n_Sh\k_Sj\l_Sp\o_S<\U_SL\]_SJ\\_SN\^_SR\`_SV\b_SX\c_SF\Z_SH\[_SB\X_SD\Y_ST\a_SP\__E\I\K\S\d\e\M\P\R\O\N\F\G\VS.Er0 SuSu_SwS_S2S_S4S_S@S_S<S_S>S_SLS_SNS_SBS_SDS_STS_SPS_SJS_S8S_SZS_S6S_0 SRS_SVS_SS_S:S_SS_SS_SS_SS_SS_SS_SS_SS_SFS_SHS_S\S_SS_S*S_E0 SrS_S"S_S&S_ShS_SjS_SpS_S^S_SdS_SfS_SlS_SnS_S`S_SbS_SS_SyS_S{S_S}S_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S$S_S(S_Er0 r0 rS\S\4S jr\" 5       S4S\S\4S jjrS rS rS rS rSS jrg)    N)ImageImageOpsImageSequence)PngInfocomfy)IOComfyNodeABCInputTypeDictFileLocator)register_versionsComfyAPIWithVersion)supported_versions)ioComfyExtension	InputImpl)argsc                  @    [         R                  R                  5         g N)r   model_management)throw_exception_if_processing_interrupted     %/home/wildlama/comfy/ComfyUI/nodes.pybefore_node_executionr   2   s    	DDFr   c                 B    [         R                  R                  U 5        g r   )r   r   interrupt_current_processing)values    r   interrupt_processingr   5   s    	77>r   i @  c                   d    \ rS rSr\S\4S j5       r\R                  4r	Sr
SrSrSr/ SQrS	 rS
rg)CLIPTextEncode:   returnc                 \    S[         R                  SSSS.4[         R                  SS04S.0$ )NrequiredTzThe text to be encoded.)	multilinedynamicPromptstooltipr'   z*The CLIP model used for encoding the text.)textclip)r   STRINGCLIPss    r   INPUT_TYPESCLIPTextEncode.INPUT_TYPES;   s<     $$[t$uv9.Z"[\
 	
r   )zNA conditioning containing the embedded text used to guide the diffusion model.encodemodel/conditioningzEncodes a text prompt using a CLIP model into an embedding that can be used to guide the diffusion model towards generating specific images.)r(   promptztext promptzpositive promptznegative promptzencode textztext encoderzencode promptc                 d    Uc  [        S5      eUR                  U5      nUR                  U5      4$ )NzERROR: clip input is invalid: None

If the clip is from a checkpoint loader node your checkpoint does not contain a valid clip or text encoder model.)RuntimeErrortokenizeencode_from_tokens_scheduled)selfr)   r(   tokenss       r   r0   CLIPTextEncode.encodeK   s>    <   y  z  zt$11&9<<r   r   N)__name__
__module____qualname____firstlineno__classmethodr
   r.   r   CONDITIONINGRETURN_TYPESOUTPUT_TOOLTIPSFUNCTIONCATEGORYDESCRIPTIONSEARCH_ALIASESr0   __static_attributes__r   r   r   r    r    :   sM    
- 
 
 OO%LiOH#H aK MN=r   r    c                   B    \ rS rSrSr\S 5       rSrSrSr	/ SQr
S rS	rg
)ConditioningCombineR   Image Generationc                     SSSS.0$ )Nr$   r?   )conditioning_1conditioning_2r   r,   s    r   r.   ConditioningCombine.INPUT_TYPEST   s    /AUghiir   rL   combinemodel/conditioning/transform)rP   zmerge conditioningzcombine promptszmerge promptsmix promptsz
add promptc                     X-   4$ r   r   )r7   rM   rN   s      r   rP   ConditioningCombine.combine]   s    /22r   r   N)r:   r;   r<   r=   ESSENTIALS_CATEGORYr>   r.   r@   rB   rC   rE   rP   rF   r   r   r   rH   rH   R   s5    ,j j$LH-HwN3r   rH   c                   >    \ rS rSr/ SQr\S 5       rSrSrSr	S r
Srg	)
ConditioningAverage`   )zblend promptszinterpolate conditioningrR   zstyle fusionzweighted blendc           	           SSSSSSSSS.4S.0$ )	Nr$   rL   FLOAT      ?        {Gz?defaultminmaxstep)conditioning_toconditioning_fromconditioning_to_strengthr   r,   s    r   r.   ConditioningAverage.INPUT_TYPESc   s/    0BYk;BPS\_hkuyDz:{   	 r   rL   addWeightedrQ   c           
      j   / n[        U5      S:  a  [        R                  " S5        US   S   nUS   S   R                  SS 5      n[	        [        U5      5       GHQ  nX   S   nX   S   R                  SU5      n	US S 2S UR
                  S   24   n
U
R
                  S   UR
                  S   :  a[  [        R                  " U
/[        R                  " SUR
                  S   U
R
                  S   -
  UR
                  S   45      /-   SS9n
[        R                  " X5      [        R                  " U
SU-
  5      -   nX   S   R                  5       nUb8  U	b5  [        R                  " X5      [        R                  " USU-
  5      -   US'   OUb  XlS'   X/nUR                  U5        GMT     U4$ )N   zWarning: ConditioningAverage conditioning_from contains more than 1 cond, only the first one will actually be applied to conditioning_to.r   pooled_output   dimr[   )lenloggingwarninggetrangeshapetorchcatzerosmulcopyappend)r7   rc   rd   re   out	cond_frompooled_output_fromit1pooled_output_tot0twt_tons                 r   rg   ConditioningAverage.addWeightedm   s    !A%OO  h  i%a(+	.q1!488$Os?+,A #A&B.1!488J\]1\bhhqk\>*Bxx{RXXa[(YYtu{{Abhhqk8QTVT\T\]^T_3`'a&bbhij28599R#PhJh;jjB"%a(--/D!-2B2N(-		2B(]`e`i`ij|  @C  F^  @^  a`  )`_%#/(:_%
AJJqM -  wr   r   N)r:   r;   r<   r=   rE   r>   r.   r@   rB   rC   rg   rF   r   r   r   rW   rW   `   s/    sN    %LH-Hr   rW   c                   6    \ rS rSr\S 5       rSrSrSrS r	Sr
g)	ConditioningConcat   c                     SSSS.0$ )Nr$   rL   )rc   rd   r   r,   s    r   r.   ConditioningConcat.INPUT_TYPES   s    0!2  	r   rL   concatrQ   c                 *   / n[        U5      S:  a  [        R                  " S5        US   S   n[        [        U5      5       HJ  nX   S   n[        R
                  " Xd4S5      nXqU   S   R                  5       /nUR                  U5        ML     U4$ )Nri   zWarning: ConditioningConcat conditioning_from contains more than 1 cond, only the first one will actually be applied to conditioning_to.r   )rn   ro   rp   rr   rt   ru   rx   ry   )	r7   rc   rd   rz   r{   r}   r~   r   r   s	            r   r   ConditioningConcat.concat   s     !A%OO  g  h%a(+	s?+,A #A&BB?1-BQ'*//12AJJqM	 - wr   r   N)r:   r;   r<   r=   r>   r.   r@   rB   rC   r   rF   r   r   r   r   r      s*     
 %LH-Hr   r   c                   >    \ rS rSr/ SQr\S 5       rSrSrSr	S r
Srg	)
ConditioningSetArea   )zregional promptzarea promptzspatial conditioningzlocalized promptc                 ~    SSSSS[         SS.4SSS[         SS.4SSS[         SS.4SSS[         SS.4SS	S
SSS.4S.0$ )Nr$   rL   INT@      r^   r   rZ   r[   r\         $@r]   conditioningwidthheightxystrengthMAX_RESOLUTIONr,   s    r   r.   ConditioningSetArea.INPUT_TYPES   st    -?(-2bQ_ij/k'l).BrR`jk0l(m$)q>cd+e#f$)q>cd+e#f+2CX\fj4k*l   	 r   rL   ry   rQ   c                 \    [         R                  " XS-  US-  US-  US-  4USS.5      nU4$ )Nr   Farear   set_area_to_boundsnode_helpersconditioning_set_valuesr7   r   r   r   r   r   r   cs           r   ry   ConditioningSetArea.append   sN    00STV[_`V`bcghbhjkopjpHqLTV[@] ^ ur   r   Nr:   r;   r<   r=   rE   r>   r.   r@   rB   rC   ry   rF   r   r   r   r   r      s/    cN    %LH-Hr   r   c                   6    \ rS rSr\S 5       rSrSrSrS r	Sr
g)	ConditioningSetAreaPercentage   c                 ^    SSSSSSSS.4SSSSSS.4SSSSSS.4SSSSSS.4SSSS	SS.4S
.0$ )Nr$   rL   rZ   r[   r   r]   r^   r\   r   r   r   r,   s    r   r.   )ConditioningSetAreaPercentage.INPUT_TYPES   st    -?(/SSV`d1e'f)0c!TWae2f(g$+1SZ^-_#`$+1SZ^-_#`+2CX\fj4k*l   	 r   rL   ry   rQ   c                 D    [         R                  " USX2XT4USS.5      nU4$ )N
percentageFr   r   r   s           r   ry   $ConditioningSetAreaPercentage.append   s6    00W]fgHkLTV[@] ^ ur   r   Nr:   r;   r<   r=   r>   r.   r@   rB   rC   ry   rF   r   r   r   r   r      s*        %LH-Hr   r   c                   6    \ rS rSr\S 5       rSrSrSrS r	Sr
g)	ConditioningSetAreaStrength   c                     SSSSSSSS.4S	.0$ )
Nr$   rL   rZ   r[   r\   r   r]   r^   )r   r   r   r,   s    r   r.   'ConditioningSetAreaStrength.INPUT_TYPES   s*    -?+2CX\fj4k*l   	 r   rL   ry   rQ   c                 :    [         R                  " USU05      nU4$ )Nr   r   )r7   r   r   r   s       r   ry   "ConditioningSetAreaStrength.append   s     00
H?UVur   r   Nr   r   r   r   r   r      s*        %LH-Hr   r   c                   >    \ rS rSr/ SQr\S 5       rSrSrSr	S r
Srg	)
ConditioningSetMask   )zmasked promptzregional inpaint conditioningzmask conditioningc           	      (    SSSSSSSSS	.4S
S/4S.0$ )Nr$   rL   MASKrZ   r[   r\   r   r]   r^   r_   zmask bounds)r   maskr   set_cond_arear   r,   s    r   r.   ConditioningSetMask.INPUT_TYPES   s8    -?&0+2CX\fj4k*l1:M0J/L   	 r   rL   ry   rQ   c                     SnUS:w  a  Sn[        UR                  5      S:  a  UR                  S5      n[        R                  " XUUS.5      nU4$ )NFr_   T   r   )r   r   mask_strength)rn   rs   	unsqueezer   r   )r7   r   r   r   r   r   r   s          r   ry   ConditioningSetMask.append   s]    "I%!%tzz?Q>>!$D00VhQY@[ \ ur   r   Nr   r   r   r   r   r      s/    \N    %LH-H
r   r   c                   >    \ rS rSrSS/r\S 5       rSrSrSr	S r
S	rg
)ConditioningZeroOut   znull conditioningzclear conditioningc                     SSS00$ )Nr$   r   rL   r   r,   s    r   r.   ConditioningZeroOut.INPUT_TYPES   s    ^-?@AAr   rL   zero_outrQ   c                 T   / nU H  nUS   R                  5       nUR                  SS 5      nUb  [        R                  " U5      US'   UR                  SS 5      nUb  [        R                  " U5      US'   [        R                  " US   5      U/nUR	                  U5        M     U4$ )Nri   rj   conditioning_lyricsr   )rx   rq   rt   
zeros_likery   )r7   r   r   tdrj   r   r   s           r   r   ConditioningZeroOut.zero_out  s    A!		AEE/48M(%*%5%5m%D/""#%%(=t"D".+0+;+;<O+P'(!!!A$'+AHHQK  ur   r   N)r:   r;   r<   r=   rE   r>   r.   r@   rB   rC   r   rF   r   r   r   r   r      s5    )+?@NB B$LH-Hr   r   c                   6    \ rS rSr\S 5       rSrSrSrS r	Sr
g)	ConditioningSetTimestepRangei  c           	      .    SSSSSSSS.4SSSSSS.4S.0$ )	Nr$   rL   rZ   r\   r[   MbP?r^   )r   startendr   r,   s    r   r.   (ConditioningSetTimestepRange.INPUT_TYPES  s=    -?'.CTWaf0g&h%,#cRU_d.e$f   	 r   rL   	set_rangerQ   c                 :    [         R                  " XUS.5      nU4$ )N)start_percentend_percentr   )r7   r   r   r   r   s        r   r   &ConditioningSetTimestepRange.set_range   s    00gj?klur   r   N)r:   r;   r<   r=   r>   r.   r@   rB   rC   r   rF   r   r   r   r   r     s*       
 %LH-Hr   r   c                   F    \ rS rSr\S 5       rSrSrSrSr	Sr
/ SQrS	 rS
rg)	VAEDecodei$  c                      SSSS04SSS04S.0$ )Nr$   LATENTr'   zThe latent to be decoded.VAEz+The VAE model used for decoding the latent.)samplesvaer   r,   s    r   r.   VAEDecode.INPUT_TYPES%  s2     $y2M&NO	+XYZ
 	
r   IMAGE)zThe decoded image.decodemodel/latentz3Decodes latent images back into pixel space images.)r   zdecode latentzlatent to imagezrender latentc                 $   US   nUR                   (       a  UR                  5       S   nUR                  U5      n[        UR                  5      S:X  a;  UR                  SUR                  S   UR                  S   UR                  S   5      nU4$ )Nr   r      )	is_nestedunbindr   rn   rs   reshape)r7   r   r   latentimagess        r   r   VAEDecode.decode5  s|    #]]_Q'FF#v||!^^BR(8&,,r:JFLLY[L\]Fzr   r   N)r:   r;   r<   r=   r>   r.   r@   rA   rB   rC   rD   rE   r   rF   r   r   r   r   r   $  s9    
 
 L-OHHGKTNr   r   c                   :    \ rS rSr\S 5       rSrSrSrS	S jr	Sr
g)
VAEDecodeTiledi?  c                 \    SSSSSSSSS	S
.4SSSSSS	S
.4SSSSSSS	S.4SSSSSSS	S.4S.0$ )Nr$   r   r   r      r          Tr_   r`   ra   rb   advancedr   r      z?Only used for video VAEs: Amount of frames to decode at a time.r_   r`   ra   rb   r'   r   6Only used for video VAEs: Amount of frames to overlap.)r   r   	tile_sizeoverlaptemporal_sizetemporal_overlapr   r,   s    r   r.   VAEDecodeTiled.INPUT_TYPES@  s    Y+0c"UYcesw2x*y).BqQU_aos0t(u/4"QW[ef  tu  CG  7H  /I27QqY]gh  vn  |@  :A  2B	  	r   r   r   experimentalc           	         X4S-  :  a  US-  nXVS-  :  a  US-  nUR                  5       nUb*  [        SXW-  5      n[        S[        US-  Xg-  5      5      nOS nS nUR                  5       nUR	                  US   X8-  X8-  XH-  XVS9n	[        U	R                  5      S:X  a;  U	R                  SU	R                  S   U	R                  S	   U	R                  S   5      n	U	4$ )
Nr  rk   ri   r   tile_xtile_yr  tile_t	overlap_tr   r   r   r   )temporal_compression_decodera   r`   spacial_compression_decodedecode_tiledrn   rs   r   )
r7   r   r   r  r  r  r  temporal_compressioncompressionr   s
             r   r   VAEDecodeTiled.decodeM  s	   {"1nGa///14">>@+=#HIM"1c-1*<>N>f&gh M#446!!')"4Y=U^g^v  AH  AW  `m!  Jv||!^^BR(8&,,r:JFLLY[L\]Fzr   r   N)r   r   r   )r:   r;   r<   r=   r>   r.   r@   rB   rC   r   rF   r   r   r   r   r   ?  s*      LHHr   r   c                   >    \ rS rSr\S 5       rSrSrSr/ SQr	S r
Srg	)
	VAEEncodei`  c                     SSSS.0$ )Nr$   r   r   )pixelsr   r   r,   s    r   r.   VAEEncode.INPUT_TYPESa  s    IFGGr   r   r0   r   )r0   zencode imagezimage to latentc                 .    UR                  U5      nSU04$ )Nr   )r0   )r7   r   r  r   s       r   r0   VAEEncode.encodej  s    JJv1  r   r   N)r:   r;   r<   r=   r>   r.   r@   rB   rC   rE   r0   rF   r   r   r   r  r  `  s/    H HLHHBN!r   r  c                   :    \ rS rSr\S 5       rSrSrSrS	S jr	Sr
g)
VAEEncodeTiledin  c                 \    SSSSSSSSSS	.4SSS
SSSS	.4SSSSSSSS.4SSSSSSSS.4S.0$ )Nr$   r   r   r   r   r   r   Tr   r   r   r   r  z?Only used for video VAEs: Amount of frames to encode at a time.r  r  )r  r   r  r  r  r  r   r,   s    r   r.   VAEEncodeTiled.INPUT_TYPESo  s    {9+0c"UYcesw2x*y).BqQU_aos0t(u/4"QW[ef  tu  CG  7H  /I27QqY]gh  vn  |@  :A  2B	  	r   r   r0   r	  c           	      .    UR                  X#X4XVS9nSU04$ )Nr  r   )encode_tiled)r7   r   r  r  r  r  r  r   s           r   r0   VAEEncodeTiled.encode|  s*    Vian  LA!!r   r   N)r   r   r:   r;   r<   r=   r>   r.   r@   rB   rC   r0   rF   r   r   r   r  r  n  s*      LHH"r   r  c                   :    \ rS rSr\S 5       rSrSrSrS	S jr	Sr
g)
VAEEncodeForInpainti  c           
      "    SSSSSSSSS	S
.4S.0$ )Nr$   r   r   r   r      r   r   ri   r^   )r  r   r   grow_mask_byr   r,   s    r   r.   VAEEncodeForInpaint.INPUT_TYPES  sJ    Izlq  @A  JK  TV  `a  tb  lc  e  f  	fr   r   r0   r   c           	         UR                  5       nUR                  S   U-  U-  nUR                  S   U-  U-  n[        R                  R                  R                  UR                  SSUR                  S   UR                  S   45      UR                  S   UR                  S   4SS9nUR                  5       nUR                  S   U:w  d  UR                  S   U:w  aT  UR                  S   U-  S-  nUR                  S   U-  S-  n	US S 2XU-   2XU	-   2S S 24   nUS S 2S S 2XU-   2XU	-   24   nUS:X  a  Un
O[        R                  " SSXD45      n[        R                  " US-
  S-  5      n[        R                  " [        R                  R                  R                  UR                  5       XS9SS5      n
S	UR                  5       -
  R                  S5      n[        S
5       HH  nUS S 2S S 2S S 2U4==   S-  ss'   US S 2S S 2S S 2U4==   U-  ss'   US S 2S S 2S S 2U4==   S-  ss'   MJ     UR!                  U5      nXS S 2S S 2S U2S U24   R                  5       S.4$ )Nri   rk   r   r   bilinearsizemoder   )paddingr[   r         ?)r   
noise_mask)spacial_compression_encoders   rt   nn
functionalinterpolater   cloneonesmathceilclampconv2droundsqueezerr   r0   )r7   r   r  r   r)  downscale_ratior   r   x_offsety_offsetmask_erosionkernel_tensorr0  mr}   r   s                   r   r0   VAEEncodeForInpaint.encode  su   88:\\!_/?B\\!_/?Bxx""..t||RDJJrNTXT^T^_aTb<c/dlrlxlxyzl{  ~D  ~J  ~J  KL  ~M  lN  U_.  `<<?a6<<?a#7Q/9a?HQ/9a?HAh8|3X(l5J1LMF!H\18L3HHID 1L!JJ1l'IJMii!1Q 67G ;;uxx':':'A'A$**,P]'A'oqrtuvL4::<((+qA1Qq7Os"O1Qq7Oq O1Qq7Os"O  JJv!Abqb!)-D-J-J-LNQQr   r   N)r(  r$  r   r   r   r&  r&    s+    f fLHHRr   r&  c                   >    \ rS rSr\S 5       rSrSrSrSr	S
S jr
Srg	)InpaintModelConditioningi  c           
      "    SSSSSSSSSS	.4S
.0$ )Nr$   rL   r   r   r   BOOLEANTzAdd a noise mask to the latent so sampling will only happen within the mask. Might improve results or completely break things depending on the model.r_   r'   )positivenegativer   r  r   r2  r   r,   s    r   r.   $InpaintModelConditioning.INPUT_TYPES  s;    ););$-'2%/,54  Ul  8m  ,n   	 r   )r?   r?   r   )rK  rL  r   r0   r1   c           	      2   UR                   S   S-  S-  nUR                   S   S-  S-  n[        R                  R                  R	                  UR                  SSUR                   S   UR                   S   45      UR                   S   UR                   S   4SS9nUn	U	R                  5       nUR                   S   U:w  d  UR                   S   U:w  aT  UR                   S   S-  S-  n
UR                   S   S-  S-  nUS S 2XU
-   2XU-   2S S 24   nUS S 2S S 2XU
-   2XU-   24   nSUR                  5       -
  R                  S5      n[        S	5       HH  nUS S 2S S 2S S 2U4==   S
-  ss'   US S 2S S 2S S 2U4==   U-  ss'   US S 2S S 2S S 2U4==   S
-  ss'   MJ     UR                  U5      nUR                  U	5      n0 nUUS'   U(       a  UUS'   / nX4 H.  n[        R                  " UUUS.5      nUR                  U5        M0     US   US   U4$ )Nri   r   rk   r   r   r,  r-  r[   r   r1  r   r2  )concat_latent_imageconcat_maskr   )rs   rt   r4  r5  r6  r   r7  r=  r>  rr   r0   r   r   ry   )r7   rK  rL  r  r   r   r2  r   r   orig_pixelsr@  rA  rD  r}   concat_latentorig_latent
out_latentrz   r   r   s                       r   r0   InpaintModelConditioning.encode  sR   \\!_!Q&\\!_!Q&xx""..t||RDJJrNTXT^T^_aTb<c/dlrlxlxyzl{  ~D  ~J  ~J  KL  ~M  lN  U_.  `""$<<?a6<<?a#7Q!+1HQ!+1HAh8|3X(l5J1LMF!H\18L3HHID4::<((+qA1Qq7Os"O1Qq7Oq O1Qq7Os"O  

6*jj-
 +
9'+J|$%0L44\[hSWDY ZAJJqM 1 AA
++r   r   NT)r:   r;   r<   r=   r>   r.   r@   RETURN_NAMESrB   rC   r0   rF   r   r   r   rG  rG    s/        <L5LH#H ,r   rG  c                   J    \ rS rSrS/rS r\S 5       rSrSr	Sr
SrSS
 jrSrg	)
SaveLatenti  zexport latentc                 8    [         R                  " 5       U l        g r   )folder_pathsget_output_directory
output_dirr7   s    r   __init__SaveLatent.__init__  s    &;;=r   c                      SSSS04S.SSS.S	.$ )
Nr   r*   r_   zlatents/ComfyUI)r   filename_prefixPROMPTEXTRA_PNGINFOr2   extra_pnginfor$   hiddenr   r,   s    r   r.   SaveLatent.INPUT_TYPES  s+    )52:YHY<Z1[]%-P 	r   r   saveTr	  Nc                 *   [         R                  " X R                  5      u  pVpxnSn	Ub  [        R                  " U5      n	S n
[
        R                  (       d*  SU	0n
Ub#  U H  n[        R                  " XK   5      X'   M     U SUS S3n/ nUR                  UUSS.5        [        R                  R                  X\5      n0 nUS   R                  5       US	'   [        R                  " / 5      US
'   [        R                  R!                  XU
S9  SSU00$ )N r2   _05z_.latentoutputfilename	subfoldertyper   latent_tensorlatent_format_version_0)metadatauilatents)r[  get_save_image_pathr]  jsondumpsr   disable_metadatary   ospathjoin
contiguousrt   tensorr   utilssave_torch_file)r7   r   rb  r2   rf  full_output_folderrq  counterrr  prompt_inforv  r   fileresultsro  s                  r   rj  SaveLatent.save  s%   LXLlLlm|  N  N  MOIg/ **V,K$$ +.H(&A"&**]-=">HK ' 1WRL1%'"
 	 ww||.5"))"4"?"?"A,1LL,<()##F8#DG-//r   )r]  ComfyUINN)r:   r;   r<   r=   rE   r_  r>   r.   r@   rB   OUTPUT_NODErC   rj  rF   r   r   r   rY  rY    s>    %&N>  
 LHKH0r   rY  c                   ^    \ rS rSrSS/r\S 5       rSrSrSr	S r
\S	 5       r\S
 5       rSrg)
LoadLatenti  zimport latentzopen latentc           	      X   [         R                  " 5       n[        R                  " U5       Vs/ s H`  n[        R                  R                  [        R                  R                  X5      5      (       d  MF  UR                  S5      (       d  M^  UPMb     nnSS[        U5      /00$ s  snf )Nz.latentr$   r   )	r[  get_input_directoryr}  listdirr~  isfiler  endswithsortedr-   	input_dirffiless       r   r.   LoadLatent.INPUT_TYPES  sz     446	JJy1z1qRWW^^BGGLLQZD^5_dedndnoxdy1zXu'89<< {s   AB'7B'B'r	  r   loadc                     [         R                  " U5      n[        R                  R	                  USS9nSnSU;  a  SnSUS   R                  5       U-  0nU4$ )Ncpudevicer[   ru  g!ޅ@r   rt  )r[  get_annotated_filepathsafetensorsrt   	load_filefloat)r7   r   latent_path
multiplierr   s        r   r  LoadLatent.load   sd    "99&A"",,[,G
$F2&Jf_5;;=
JK{r   c                    [         R                  " U5      n[        R                  " 5       n[	        US5       nUR                  UR                  5       5        S S S 5        UR                  5       R                  5       $ ! , (       d  f       N,= fNrb	r[  r  hashlibsha256openupdatereaddigesthex)r-   r   
image_pathrD  r  s        r   
IS_CHANGEDLoadLatent.IS_CHANGED)  s]    !88@
NN*d#qHHQVVX $xxz~~ $#    A>>
Bc                 \    [         R                  " U5      (       d  SR                  U5      $ g)NzInvalid latent file: {}Tr[  exists_annotated_filepathformat)r-   r   s     r   VALIDATE_INPUTSLoadLatent.VALIDATE_INPUTS1  s'    55f==,33F;;r   r   N)r:   r;   r<   r=   rE   r>   r.   rC   r@   rB   r  r  r  rF   r   r   r   r  r    s\    %}5N= =
 HLH      r   r  c                   B    \ rS rSrSS/r\S 5       rSrSrSr	Sr
S	 rS
rg)CheckpointLoaderi8  
load modelmodel loaderc                 d    S[         R                  " S5      4[         R                  " S5      4S.0$ )Nr$   configscheckpoints)config_name	ckpt_namer[  get_filename_listr,   s    r   r.   CheckpointLoader.INPUT_TYPES;  s8    l.L.LY.W-Z,8,J,J=,Y+\^ _ 	_r   MODELr+   r   load_checkpointmodel/loadersTc           	          [         R                  " SU5      n[         R                  " SU5      n[        R                  R                  X4SS[         R                  " S5      S9$ )Nr  r  T
embeddings
output_vaeoutput_clipembedding_directory)r[  get_full_pathget_full_path_or_raiser   sdr  get_folder_paths)r7   r  r  config_path	ckpt_paths        r   r   CheckpointLoader.load_checkpointE  sl    "00KH 77yQ	xx''4]a  xD  xU  xU  Vb  xc'  d  	dr   r   N)r:   r;   r<   r=   rE   r>   r.   r@   rB   rC   
DEPRECATEDr  rF   r   r   r   r  r  8  s<    "N3N_ _ ,L HHJdr   r  c                   F    \ rS rSr\S 5       rSrSrSrSr	Sr
/ SQrS	 rS
rg)CheckpointLoaderSimpleiJ  c                 >    SS[         R                  " S5      SS0400$ )Nr$   r  r  r'   z+The name of the checkpoint (model) to load.r  r,   s    r   r.   "CheckpointLoaderSimple.INPUT_TYPESK  s<     l<<]Ki  ZG  NH  I
 	
r   r  )z%The model used for denoising latents.z.The CLIP model used for encoding text prompts.zMThe VAE model used for encoding and decoding images to and from latent space.r  r  zQLoads a diffusion model checkpoint, diffusion models are used to denoise latents.)r  
checkpointr  zload checkpointckptmodelc                     [         R                  " SU5      n[        R                  R	                  USS[         R
                  " S5      S9nUS S $ )Nr  Tr  r  r   r[  r  r   r  load_checkpoint_guess_configr  )r7   r  r  rz   s       r   r  &CheckpointLoaderSimple.load_checkpoint\  sa     77yQ	hh33I$\`  wC  wT  wT  Ua  wb3  c2Awr   r   N)r:   r;   r<   r=   r>   r.   r@   rA   rB   rC   rD   rE   r  rF   r   r   r   r  r  J  s>    
 
 ,LhO !HHeKeNr   r  c                   D    \ rS rSrS/r\S 5       rSrSrSr	Sr
SS jrS	rg
)DiffusersLoaderia  zload diffusers modelc           	      @   / n[         R                  " S5       H|  n[        R                  R	                  U5      (       d  M)  [        R
                  " USS9 H:  u  p4nSU;   d  M  UR                  [        R                  R                  X2S95        M<     M~     SSU400$ )N	diffusersT)followlinkszmodel_index.json)r   r$   
model_path)r[  r  r}  r~  existswalkry   relpath)clspathssearch_pathrootsubdirr  s         r   r.   DiffusersLoader.INPUT_TYPESd  s    '88EKww~~k**+-77;D+Q'D%)U2RWW__T_%MN ,R F \E8677r   r  r  Tr  c                 |   [         R                  " S5       Hp  n[        R                  R	                  U5      (       d  M)  [        R                  R                  XA5      n[        R                  R	                  U5      (       d  Mn  Un  O   [        R                  R                  XU[         R                  " S5      S9$ )Nr  r  r  )	r[  r  r}  r~  r  r  r   diffusers_loadload_diffusers)r7   r  r  r  r  r~  s         r   r  DiffusersLoader.load_checkpointt  s    '88EKww~~k**ww||K<77>>$''!%J F ##22:bm  DP  Da  Da  bn  Do2  p  	pr   r   NTT)r:   r;   r<   r=   rE   r>   r.   r@   rB   r  rC   r  rF   r   r   r   r  r  a  s8    ,-N8 8 ,L HJHpr   r  c                   :    \ rS rSr\S 5       rSrSrSrS	S jr	Sr
g)
unCLIPCheckpointLoaderi  c                 8    SS[         R                  " S5      400$ )Nr$   r  r  r  r,   s    r   r.   "unCLIPCheckpointLoader.INPUT_TYPES  &    kL,J,J=,Y+\    	 r   )r  r+   r   CLIP_VISIONr  r  c           	          [         R                  " SU5      n[        R                  R	                  USSS[         R
                  " S5      S9nU$ )Nr  Tr  )r  r  output_clipvisionr  r  )r7   r  r  r  r  rz   s         r   r  &unCLIPCheckpointLoader.load_checkpoint  s^     77yQ	hh33I$\`tx  O[  Ol  Ol  my  Oz3  {
r   r   Nr  )r:   r;   r<   r=   r>   r.   r@   rB   rC   r  rF   r   r   r   r  r    s*        ;L HHr   r  c                   6    \ rS rSr\S 5       rSrSrSrS r	Sr
g)	CLIPSetLastLayeri  c           	           SSSSSSSSS.4S	.0$ )
Nr$   r+   r   r   iri   Tr   )r)   stop_at_clip_layerr   r,   s    r   r.   CLIPSetLastLayer.INPUT_TYPES  s0    j5:SV_aklz~<  5A  ! 	!r   r  set_last_layerr1   c                 J    UR                  5       nUR                  U5        U4$ r   )r7  
clip_layer)r7   r)   r  s      r   r  CLIPSetLastLayer.set_last_layer  s!    zz|*+wr   r   N)r:   r;   r<   r=   r>   r.   r@   rB   rC   r  rF   r   r   r   r  r    s*    ! ! LH#Hr   r  c                   P    \ rS rSrSrS r\S 5       rSrSr	Sr
SrS	r/ S
QrS rSrg)
LoraLoaderi  rJ   c                     S U l         g r   loaded_lorar^  s    r   r_  LoraLoader.__init__  s
    r   c                 v    SSSS04SSS04[         R                  " S5      SS04S	S
SSSSS.4S	S
SSSSS.4S.0$ )Nr$   r  r'   z0The diffusion model the LoRA will be applied to.r+   z+The CLIP model the LoRA will be applied to.loraszThe name of the LoRA.rZ   r[         Y      Y@r]   zGHow strongly to modify the diffusion model. This value can be negative.r_   r`   ra   rb   r'   zBHow strongly to modify the CLIP model. This value can be negative.)r  r)   	lora_namestrength_modelstrength_clipr  r,   s    r   r.   LoraLoader.INPUT_TYPES  s     !I/a#bc)-Z![\*<<WE	SjGkl#*FSXbf  t}  -~  #")s6RWae  sw  ,x  "y
 	
r   )r  r+   )zThe modified diffusion model.zThe modified CLIP model.	load_lorar  zThis LoRA loader is used to modify both diffusion and CLIP models, altering the way in which latents are denoised such as applying styles. Multiple LoRA nodes can be linked together.)loraz	load loraz
apply lorazlora loaderz
lora modelc           	         US:X  a	  US:X  a  X4$ [         R                  " SU5      nS nS nU R                  bT  U R                  S   U:X  a:  U R                  S   n[        U R                  5      S:  a  U R                  S   OS nOS U l        Uc*  [        R
                  R                  USSS9u  pxXgU4U l        [        R                  R                  XXtXXS9u  pX4$ )Nr   r  ri   rk   T)	safe_loadreturn_metadata)lora_metadata)	r[  r  r  rn   r   r  load_torch_filer  load_lora_for_models)r7   r  r)   r  r  r  	lora_pathr  r  
model_lora	clip_loras              r   r  LoraLoader.load_lora  s    Q=A#5=  77K	'"i/''*7:4;K;K7Lq7P 0 0 3VZ#' <"'++"="=iSWim"="nD )?D % = =e4an =  !M
&&r   r  N)r:   r;   r<   r=   rU   r_  r>   r.   r@   rA   rB   rC   rD   rE   r  rF   r   r   r   r  r    sI    ,  	
 	
 %LSOHH KKUN'r   r  c                   6    \ rS rSr\S 5       rSrSrSrS r	Sr
g)	LoraLoaderModelOnlyi  c           	      J    SS[         R                  " S5      4SSSSSS	.4S
.0$ )Nr$   r  r  rZ   r[   r  r  r]   r^   )r  r  r  r  r,   s    r   r.   LoraLoaderModelOnly.INPUT_TYPES  s;    z,8,J,J7,S+V18cRXafpt:u0v  ! 	!r   r)  zThis LoRAs loader is used to modify the diffusion model, altering the way in which latents are denoised such as applying styles. Multiple LoRA nodes can be linked together.load_lora_model_onlyc                 2    U R                  US X#S5      S   4$ )Nr   )r  )r7   r  r  r  s       r   r+  (LoraLoaderModelOnly.load_lora_model_only  s    udIqI!LNNr   r   N)r:   r;   r<   r=   r>   r.   r@   rD   rB   r+  rF   r   r   r   r'  r'    s.    ! !
 L AK%HOr   r'  c                   f    \ rS rSr/ SQr/ SQr\S 5       r\S 5       r\	S 5       r
SrSrS	rS
 rSrg)	VAELoaderi  )taehvlighttaew2_2lighttaew2_1lighttaehy1_5taeltx_2)taesdtaesdxltaesd3taef1taef2c                    [         R                  " S5      n[         R                  " S5      n[        5       [        5       pCU H  nUR                  SS5      n[	        U5      S:w  d  US   U R
                  ;  a>  U R                   H,  nUR                  U5      (       d  M  UR                  U5          O   Mu  US   R                  S5      (       a  UR                  US   5        M  US   R                  S5      (       d  M  UR                  US   5        M     X Vs/ s H  oU;   d  M
  UPM     sn-  nUR                  S	5        U$ s  snf )
Nr   
vae_approxrm  ri   rk   r   zencoder.zdecoder.pixel_space)
r[  r  setsplitrn   
image_taes
video_taes
startswithry   add)	r-   vaesapprox_vaeshave_img_encoderhave_img_decodervpartstaeks	            r   vae_listVAELoader.vae_list  s   --e4"44\B-0UCE*AGGCOE5zQ%(!,,"><<C||C((A ( Qx"":.. $$U1X.q$$Z00 $$U1X.  	,F,q5E0E,FFM" Gs   	E*Ec                   ^  0 n[         R                  " S5      n[        [        U 4S jU5      5      n[        [        U 4S jU5      5      n[        R
                  R                  [         R                  " SU5      5      nU H  nXV   USR                  U5      '   M     [        R
                  R                  [         R                  " SU5      5      nU H  nXv   USR                  U5      '   M     T S:X  a4  [        R                  " S5      US'   [        R                  " S	5      US
'   U$ T S:X  a4  [        R                  " S5      US'   [        R                  " S	5      US
'   U$ T S:X  a4  [        R                  " S5      US'   [        R                  " S5      US
'   U$ T S:X  a2  [        R                  " S5      US'   [        R                  " S5      US
'   U$ )Nr;  c                 D   > U R                  SR                  T5      5      $ )Nz{}_encoder.rA  r  anames    r   <lambda>&VAELoader.load_taesd.<locals>.<lambda>      ]5I5I$5O(Pr   c                 D   > U R                  SR                  T5      5      $ )Nz{}_decoder.rO  rP  s    r   rS  rT    rU  r   ztaesd_encoder.{}ztaesd_decoder.{}r5  g{P?	vae_scaler\   	vae_shiftr6  gy&1?r7  grh|?gH.?r8  gxz,C?g=U?)r[  r  nextfilterr   r  r   r  r  rt   r  )rR  r  rD  encoderdecoderencrJ  decs   `       r   
load_taesdVAELoader.load_taesd  s   "44\BvPR]^_vPR]^_kk)),*M*Ml\c*deA/2vB!((+,  kk)),*M*Ml\c*deA/2vB!((+,  7?#ll73B{O#ll3/B{O 	 Y#ll73B{O#ll3/B{O 	 X#ll62B{O#ll62B{O 	 W_#ll62B{O#ll62B{O	r   c                 .    SSU R                  U 5      400$ )Nr$   vae_name)rK  r,   s    r   r.   VAELoader.INPUT_TYPES  s    j1::a=*;<==r   r   load_vaer  c                 t   S nS nUS:X  a  0 n[         R                  " S5      US'   OXR                  ;   a  U R                  U5      nO[        R
                  R                  U5      S   U R                  ;   a  [        R                  " SU5      nO[        R                  " SU5      n[        R                  R                  USS9u  pBUS	:X  a  Uc  S
S0nOSUS
'   [        R                  R                  XBS9nUR                  5         Ub-  [        R                  R                   X2S 44UR"                  l        U4$ )Nr<  r[   pixel_space_vaer   r;  r   T)r  r9  tae_latent_channels   )r  rv  )rt   r  r?  r_  r}  r~  splitextr@  r[  r  r   r  r   r  r   throw_exception_if_invalidload_vae_patcherpatchercached_patcher_init)r7   rb  rv  vae_pathr  r   s         r   rd  VAELoader.load_vae  s   }$B$)LL$5B !(*Bww)!,?'>>|XV'>>uhO ;;66xQU6VLBw13725./hhllbl4&&( /4xx/H/H8_cJd.eCKK+vr   r   N)r:   r;   r<   r=   r@  r?  staticmethodrK  r_  r>   r.   r@   rB   rC   rd  rF   r   r   r   r/  r/    sZ    WJAJ (  : > >LHHr   r/  c                   >    \ rS rSr\S 5       rSrSrSr/ SQr	S r
Srg	)
ControlNetLoaderi:  c                 8    SS[         R                  " S5      400$ )Nr$   control_net_name
controlnetr  r,   s    r   r.   ControlNetLoader.INPUT_TYPES;  s"    0<3Q3QR^3_2bcddr   CONTROL_NETload_controlnetr  )ru  control netcnzload controlnetzcontrolnet loaderc                     [         R                  " SU5      n[        R                  R	                  U5      nUc  [        S5      eU4$ )Nru  zPERROR: controlnet file is invalid and does not contain a valid controlnet model.)r[  r  r   ru  ry  r4   )r7   rt  controlnet_pathru  s       r   ry   ControlNetLoader.load_controlnetE  sE    &==lL\]%%55oF
qrr}r   r   N)r:   r;   r<   r=   r>   r.   r@   rB   rC   rE   ry  rF   r   r   r   rr  rr  :  s1    e e $L HH`Nr   rr  c                   6    \ rS rSr\S 5       rSrSrSrS r	Sr
g)	DiffControlNetLoaderiL  c                 :    SS[         R                  " S5      4S.0$ )Nr$   r)  ru  )r  rt  r  r,   s    r   r.    DiffControlNetLoader.INPUT_TYPESM  s+    z3?3Q3QR^3_2bd e 	er   rw  ry  r  c                 t    [         R                  " SU5      n[        R                  R	                  X15      nU4$ )Nru  )r[  r  r   ru  ry  )r7   r  rt  r}  ru  s        r   ry  $DiffControlNetLoader.load_controlnetW  s3    &==lL\]%%55oM
}r   r   N)r:   r;   r<   r=   r>   r.   r@   rB   rC   ry  rF   r   r   r   r  r  L  s,    e e $L HHr   r  c                   :    \ rS rSr\S 5       rSrSrSrSr	S r
Srg	)
ControlNetApplyi]  c           
      "    SSSSSSSSS	S
.4S.0$ )Nr$   rL   rw  r   rZ   r[   r\   r   r]   r^   )r   control_netimager   r   r,   s    r   r.   ControlNetApply.INPUT_TYPES^  s0    -?,=&1*1s3W[ei3j)k   	 r   rL   apply_controlnetTmodel/conditioning/controlnetc                 B   US:X  a  U4$ / nUR                  SS5      nU Hz  nUS   US   R                  5       /nUR                  5       R                  Xd5      n	SUS   ;   a  U	R                  US   S   5        XS   S'   SUS   S'   UR	                  U5        M|     U4$ )Nr   r   ri   controlTcontrol_apply_to_uncond)movedimrx   set_cond_hintset_previous_controlnetry   )
r7   r   r  r  r   r   control_hintr   r   c_nets
             r   r   ControlNetApply.apply_controlnetk  s    q= ##}}R*A1qtyy{#A$$&44\LEAaD --ad9o>#aDO.2AaD*+HHQK  ur   r   N)r:   r;   r<   r=   r>   r.   r@   rB   r  rC   r  rF   r   r   r   r  r  ]  s/        %L!HJ.Hr   r  c                   J    \ rS rSr\S 5       rSrSrSrSr	/ SQr
S/ 4S	 jrS
rg)ControlNetApplyAdvancedi|  c                 J    SSSSSSSSSS	.4SSSSS
S	.4SSSSS
S	.4S.SS0S.$ )NrL   rw  r   rZ   r[   r\   r   r]   r^   r   )rK  rL  r  r  r   r   r   r   r   r$   optionalr   r,   s    r   r.   #ControlNetApplyAdvanced.INPUT_TYPES}  sc    ););,=&1*1s3W[ei3j)k/6CPS\_in8o.p-4#cZ]gl6m,n #I 
 
	r   )r?   r?   )rK  rL  r  r  )ru  zapply controlnetzuse controlnetrz  Nc
           
         US:X  a  X4$ UR                  SS5      n
0 n/ nX4 H  n/ nU H  nUS   R                  5       nUR                  SS 5      nUU;   a  UU   nO6UR                  5       R                  XXg4XS9nUR	                  U5        UUU'   UUS'   SUS'   US   U/nUR                  U5        M     UR                  U5        M     US   US   4$ )Nr   r   ri   r  )r   extra_concatFr  )r  rx   rq   r  r  ry   )r7   rK  rL  r  r  r   r   r   r   r  r  cnetsrz   r   r   r   r   	prev_cnetr  r   s                       r   r  (ControlNetApplyAdvanced.apply_controlnet  s   q=''}}R*%0LA!aDIIKEE)T2	%!),E',,.<<\VcUqwz<  WE11)<',E)$$)/4+,qT1I " JJqM# 1$ AAr   r   )r:   r;   r<   r=   r>   r.   r@   rW  rB   rC   rE   r  rF   r   r   r   r  r  |  s>      3L+L!H.HXNqu  EG  r   r  c                   6    \ rS rSr\S 5       rSrSrSrS r	Sr
g)	
UNETLoaderi  c                 F    S[         R                  " S5      4/ SQSS04S.0$ )Nr$   diffusion_models)r_   
fp8_e4m3fnfp8_e4m3fn_fastfp8_e5m2r   T)	unet_nameweight_dtyper  r,   s    r   r.   UNETLoader.INPUT_TYPES  s4    L,J,JK],^+a/gjtvzi{.|   	 r   r)  	load_unetr  c                    0 nUS:X  a  [         R                  US'   O8US:X  a  [         R                  US'   SUS'   OUS:X  a  [         R                  US'   [        R                  " SU5      n[
        R                  R                  XCS9nU4$ )	Nr  dtyper  Tfp8_optimizationsr  r  )model_options)rt   float8_e4m3fnfloat8_e5m2r[  r  r   r  load_diffusion_model)r7   r  r  r  	unet_pathr  s         r   r  UNETLoader.load_unet  s    <'%*%8%8M'"..%*%8%8M'"15M-.Z'%*%6%6M'" 778JIV	--i-Uxr   r   N)r:   r;   r<   r=   r>   r.   r@   rB   rC   r  rF   r   r   r   r  r    s*        LHHr   r  c                   >    \ rS rSr\S 5       rSrSrSrSr	S
S jr
Srg	)
CLIPLoaderi  c                 R    [         R                  " S5      4/ SQ4S.SSS/SS040S	.$ )
Ntext_encoders)stable_diffusionstable_cascadesd3stable_audiomochiltxvpixartcosmoslumina2wanhidreamchromaaceomnigen2
qwen_imagehunyuan_imageflux2ovislongcat_image	cogvideoxlenspixeldit	ideogram4)	clip_namers  r  r_   r  r   Tr  r  r,   s    r   r.   CLIPLoader.INPUT_TYPES  sI    ,8,J,J?,[+^ (s  'v  ')U);j$=O(P  	 r   r  	load_clipr  a0  Recipes:
sd: clip-l
stable cascade: clip-g
sd3: t5 xxl / clip-g / clip-l
stable audio: t5 base
mochi: t5 xxl
cogvideox: t5 xxl (226-token padding)
cosmos: old t5 xxl
lumina2: gemma 2 2B
wan: umt5 xxl
hidream: llama-3.1 (Recommend) or t5
omnigen2: qwen vl 2.5 3B
lens: gpt-oss-20b
pixeldit: gemma 2 2B elmc                    [        [        R                  R                  UR	                  5       [        R                  R                  R
                  5      n0 nUS:X  a  [        R                  " S5      =US'   US'   [        R                  " SU5      n[        R                  R                  U/[        R                  " S5      XES9nU4$ )Nr  load_deviceoffload_devicer  r  
ckpt_pathsr  	clip_typer  )getattrr   r  CLIPTypeupperSTABLE_DIFFUSIONrt   r  r[  r  r  r  )r7   r  rs  r  r  r  	clip_pathr)   s           r   r  CLIPLoader.load_clip  s    EHH--tzz|UXX=N=N=_=_`	U?MR\\Z_M``M-(=9I+J 77S	xx!!i[lNkNklxNy  FO!  mwr   r   N)r  r_   r:   r;   r<   r=   r>   r.   r@   rB   rC   rD   r  rF   r   r   r   r  r    s2        LHH RK	r   r  c                   >    \ rS rSr\S 5       rSrSrSrSr	S
S jr
Srg	)DualCLIPLoaderi  c                 ~    [         R                  " S5      4[         R                  " S5      4/ SQ4S.SSS/SS040S	.$ )
Nr  )sdxlr  fluxhunyuan_videor  r  hunyuan_video_15
kandinsky5kandinsky5_imager  newbier  )
clip_name1
clip_name2rs  r  r_   r  r   Tr  r  r,   s    r   r.   DualCLIPLoader.INPUT_TYPES  sZ    -9-K-KO-\,_-9-K-KO-\,_ ({  '~ 
 ')U);j$=O(P	  	 r   r  r  r  zRecipes:
sdxl: clip-l, clip-g
sd3: clip-l, clip-g / clip-l, t5 / clip-g, t5
flux: clip-l, t5
hidream: at least one of t5 or llama, recommended t5 and llama
hunyuan_image: qwen2.5vl 7b and byt5 small
newbie: gemma-3-4b-it, jina clip v2c                    [        [        R                  R                  UR	                  5       [        R                  R                  R
                  5      n[        R                  " SU5      n[        R                  " SU5      n0 nUS:X  a  [        R                  " S5      =US'   US'   [        R                  R                  Xg/[        R                  " S5      XXS9n	U	4$ )Nr  r  r  r  r  r  )r  r   r  r  r  r  r[  r  rt   r  r  r  )
r7   r  r  rs  r  r  
clip_path1
clip_path2r  r)   s
             r   r  DualCLIPLoader.load_clip  s    EHH--tzz|UXX=N=N=_=_`	!88*U
!88*U
U?MR\\Z_M``M-(=9I+Jxx!!j-E[g[x[x  zF  \G  S\!  zwr   r   N)r_   r  r   r   r   r  r    s2        LHH EKr   r  c                   6    \ rS rSr\S 5       rSrSrSrS r	Sr
g)	CLIPVisionLoaderi  c                 8    SS[         R                  " S5      400$ )Nr$   r  clip_visionr  r,   s    r   r.   CLIPVisionLoader.INPUT_TYPES  r  r   r  r  r  c                     [         R                  " SU5      n[        R                  R	                  U5      nUc  [        S5      eU4$ )Nr  zMERROR: clip vision file is invalid and does not contain a valid vision model.)r[  r  r   r  r  r4   )r7   r  r  r  s       r   r  CLIPVisionLoader.load_clip  sD     77yQ	'',,Y7noo~r   r   N)r:   r;   r<   r=   r>   r.   r@   rB   rC   r  rF   r   r   r   r  r    s*        $LHHr   r  c                   6    \ rS rSr\S 5       rSrSrSrS r	Sr
g)	CLIPVisionEncodei  c                     SSSSS/4S.0$ )Nr$   r  r   centernone)r  r  cropr   r,   s    r   r.   CLIPVisionEncode.INPUT_TYPES  s%    -='1(0&'9&;   	 r   CLIP_VISION_OUTPUTr0   r1   c                 :    SnUS:w  a  SnUR                  X$S9nU4$ )NTr  Fr  )encode_image)r7   r  r  r  
crop_imagero  s         r   r0   CLIPVisionEncode.encode  s/    
8J))%)Ayr   r   Nr$  r   r   r   r  r    s*       
 +LH#Hr   r  c                   6    \ rS rSr\S 5       rSrSrSrS r	Sr
g)	StyleModelLoaderi%  c                 8    SS[         R                  " S5      400$ )Nr$   style_model_namestyle_modelsr  r,   s    r   r.   StyleModelLoader.INPUT_TYPES&  s"    0<3Q3QR`3a2deffr   STYLE_MODELload_style_modelr  c                 t    [         R                  " SU5      n[        R                  R	                  U5      nU4$ )Nr  )r[  r  r   r  r  )r7   r
  style_model_pathstyle_models       r   r  !StyleModelLoader.load_style_model/  s3    '>>~O_`hh//0@A~r   r   N)r:   r;   r<   r=   r>   r.   r@   rB   rC   r  rF   r   r   r   r  r  %  s,    g g $L!HHr   r  c                   <    \ rS rSrS/r\S 5       rSrSrSr	S r
Srg	)
StyleModelApplyi5  zstyle transferc           
      *    SSSSSSSSS	S
.4SS/4S.0$ )Nr$   rL   r  r   rZ   r[   r\   r   r   r^   multiply	attn_bias)r   r  clip_vision_outputr   strength_typer   r,   s    r   r.   StyleModelApply.INPUT_TYPES8  s;    -?,=3K*1s3W[ej3k)l0:K/H.K	   	 r   rL   apply_stylemodelr1   c                     UR                  U5      R                  SSS9R                  SS9nUS:X  a  Xd-  nUR                  S   n/ nU GH>  n	U	u  pUR	                  5       nSU;   d  US:X  Ga  US:w  Ga  [
        R                  " [
        R                  " US:X  a  UOS/5      5      nUR                  S	S
5      nUS   US   -  nU
R                  S   nUR                  SS 5      nUc7  [
        R                  " U
R                  S   X-   X-   4[
        R                  S9nUR                  [
        R                  :X  a1  [
        R                  " UR                  [
        R                  S95      n[
        R                  " U
R                  S   X-   U-   X-   U-   4[
        R                  S9nUS S 2S U2S U24   US S 2S U2S U24'   US S 2S U2US 24   US S 2S U2X-   S 24'   US S 2US 2S U24   US S 2X-   S 2S U24'   US S 2US 2US 24   US S 2X-   S 2X-   S 24'   UUS S 2S U2XU-   24'   UUS S 2X-   S 2XU-   24'   UR                  U
R                  5      US'   XS	'   UR                  [
        R                   " X4SS9U/5        GMA     U4$ )Nr   ri   )	start_dimend_dimrl   r  attention_maskr  r[   attention_mask_img_shape)ri   ri   r  )get_condflattenr   rs   rx   rt   logTensorrq   rv   float16r  booltor  ry   ru   )r7   r   r  r  r   r  condr   c_outr   txtkeysr  mask_ref_sizen_refn_txtr   new_masks                     r   r   StyleModelApply.apply_stylemodelE  s   ##$67??!UV?WaafgahJ&DJJqMAKS99;D4'M[,HXY\_ "IIellQ\@\Hbe3f&gh	 $)CV L%a(=+;;		!xx 0$7< ;;		!emU]'S[`[h[hiD ::+ !99TWW5==W%ABD ;;		!ei%6GUZIZ'[chcpcpq.21fuffuf3D.EFUFFUF*+04Q5F0GFUFEGH,-04Q5F0GEGHfuf,-26q%&%&7H2IEGHegh./5>FUFE'M127@EGHe!Gm34)1SZZ)@%&3@/0LL%))SKQ7>?I L xr   r   N)r:   r;   r<   r=   rE   r>   r.   r@   rB   rC   r  rF   r   r   r   r  r  5  s2    &'N    %L!H#H-r   r  c                   6    \ rS rSr\S 5       rSrSrSrS r	Sr
g)	unCLIPConditioningit  c           
      0    SSSSSSSSS	.4SS
S
SSS	.4S.0$ )Nr$   rL   r   rZ   r[   g      $r   r]   r^   r\   )r   r  r   noise_augmentationr   r,   s    r   r.   unCLIPConditioning.INPUT_TYPESu  sA    -?3K*1s5Y]gk3l)m4;UXadnr=s3t   	 r   rL   	apply_admr1   c                 R    US:X  a  U4$ [         R                  " USX#US./0SS9nU4$ )Nr   unclip_conditioning)r  r   r6  T)ry   r   )r7   r   r  r   r6  r   s         r   r8  unCLIPConditioning.apply_adm  sY    q= ##00@U  pB  pB  YC  XD  @E  NR  Sur   r   N)r:   r;   r<   r=   r>   r.   r@   rB   rC   r8  rF   r   r   r   r4  r4  t  s*        %LH#Hr   r4  c                   6    \ rS rSr\S 5       rSrSrSrS r	Sr
g)	GLIGENLoaderi  c                 8    SS[         R                  " S5      400$ )Nr$   gligen_namegligenr  r,   s    r   r.   GLIGENLoader.INPUT_TYPES  s     ml.L.LX.V-YZ[[r   GLIGENload_gligenr  c                 t    [         R                  " SU5      n[        R                  R	                  U5      nU4$ )Nr@  )r[  r  r   r  rD  )r7   r?  gligen_pathr@  s       r   rD  GLIGENLoader.load_gligen  s0    "99(KP%%k2yr   r   N)r:   r;   r<   r=   r>   r.   r@   rB   rC   rD  rF   r   r   r   r=  r=    s,    \ \ LHHr   r=  c                   6    \ rS rSr\S 5       rSrSrSrS r	Sr
g)	GLIGENTextBoxApplyi  c                 ~    SSSSSSSS.4SS	S
[         S
S.4SS	S
[         S
S.4SSS[         S
S.4SSS[         S
S.4S.0$ )Nr$   rL   r  rB  r*   T)r%   r&   r   r   r   r^   r   )rc   r)   gligen_textbox_modelr(   r   r   r   r   r   r,   s    r   r.   GLIGENTextBoxApply.INPUT_TYPES  su    0B&06B'/tW[1\&](-2aP^hi/j'k).BqQ_ij0k(l$)q>cd+e#f$)q>cd+e#f   	 r   rL   ry   zmodel/conditioning/gligenc	                    / n	UR                  UR                  U5      SS9u  pU Hb  nUS   US   R                  5       /nXS-  US-  US-  US-  4/n/ nSUS   ;   a  US   S   S   nSX?U-   4US   S'   U	R                  U5        Md     U	4$ )	Nunprojected)return_pooledr   ri   r   r@  rk   position)encode_from_tokensr5   rx   ry   )r7   rc   r)   rK  r(   r   r   r   r   r   r*  cond_pooledr   r   position_paramsprevs                   r   ry   GLIGENTextBoxApply.append  s     33DMM$4GWd3e A1qtyy{#A +q[%1*a1faSTfUVOD1Q4tH~a((*>@VWAaDNHHQK ! ur   r   Nr   r   r   r   rI  rI    s*    	  	  %LH*Hr   rI  c                   J    \ rS rSr\S 5       rSrSrSrSr	Sr
/ SQrSS	 jrS
rg)EmptyLatentImagei  c           	      P    SSSS[         SSS.4SSS[         SSS.4SS	S	S
SS.4S.0$ )Nr$   r   r      r   z)The width of the latent images in pixels.r  z*The height of the latent images in pixels.ri   r   z)The number of latent images in the batch.r_   r`   ra   r'   )r   r   
batch_sizer   r,   s    r   r.   EmptyLatentImage.INPUT_TYPES  sp     SN\]  kV  "W  X c"^]^  lX  #Y  Z$!Ad  XC  'D  E
 	
r   r   )zThe empty latent image batch.generater   zFCreate a new batch of empty latent images to be denoised via sampling.)emptyzempty latentz
new latentzcreate latentzblank latentblankc                     [         R                  " USUS-  US-  /[        R                  R	                  5       [        R                  R                  5       S9nUSS.4$ )Nr  r   r  r  )r   downscale_ratio_spacial)rt   rv   r   r   intermediate_deviceintermediate_dtype)r7   r   r   r[  r   s        r   r]  EmptyLatentImage.generate  sm    j!Vq[%1*EeNdNdNxNxNz  CH  CY  CY  Cl  Cl  Cn  o"qADDr   r   Nri   )r:   r;   r<   r=   r>   r.   r@   rA   rB   rC   rD   rE   r]  rF   r   r   r   rW  rW    s:    
 
 L8OHHZKfNEr   rW  c                   >    \ rS rSr/ SQr\S 5       rSrSrSr	S r
Srg	)
LatentFromBatchi  )zselect from batchzpick latentzbatch subsetc                 <    SSSS[         * [         S.4SSSSS.4S.0$ )	Nr$   r   r   r   r_   r`   ra   ri   r   )r   batch_indexlengthr   r,   s    r   r.   LatentFromBatch.INPUT_TYPES  s8    .3N?cq5r-s).AaPR0S(T  ! 	!r   r   	frombatchmodel/latent/batchc                    UR                  5       nUS   nUS:  a  X%R                  S   -  n[        S[        UR                  S   S-
  U5      5      n[        UR                  S   U-
  U5      nXRX#-    R	                  5       US'   SU;   a  US   nUR                  S   S:X  a  UR	                  5       US'   OUR                  S   UR                  S   :  aU  UR                  [        R                  " UR                  S   UR                  S   -  5      SSS5      S UR                  S    nXbX#-    R	                  5       US'   SU;  a$  [        X"U-   5       Vs/ s H  owPM     snUS'   U4$ US   X"U-    US'   U4$ s  snf )Nr   r   ri   r2  rk  )	rx   rs   ra   r`   r7  repeatr9  r:  rr   )r7   r   rk  rl  r-   s_inmasksr   s           r   rn  LatentFromBatch.frombatch  s   LLNy!?::a=(K!SA!2K@ATZZ][0&9(<=CCE)7"L)E{{1~""'++-,;;q>DJJqM1!LL4::a=5;;q>3Q)RTUWXZ[\]k^b^h^hij^klE"'K4H"I"O"O"Q,!+0&>P+QR+Qa+QRAm t  '}5kPVBVWAmt  Ss   E>r   N)r:   r;   r<   r=   rE   r>   r.   r@   rB   rC   rn  rF   r   r   r   rh  rh    s/    IN! !
 LH#Hr   rh  c                   >    \ rS rSrSS/r\S 5       rSrSrSr	S r
S	rg
)RepeatLatentBatchi  zduplicate latentzclone latentc                     SSSSSSS.4S.0$ )Nr$   r   r   ri   r   rj  )r   amountr   r,   s    r   r.   RepeatLatentBatch.INPUT_TYPES  s&    ).AaPR0S(T  ! 	!r   r   rq  ro  c           	         UR                  5       nUS   nUR                  U4SUR                  S-
  -  -   5      US'   SU;   a  US   R                  S   S:  a  US   nUR                  S   UR                  S   :  af  UR                  [        R
                  " UR                  S   UR                  S   -  5      4SUR                  S-
  -  -   5      S UR                  S    nUS   R                  U4SUS   R                  S-
  -  -   5      US'   SU;   aX  [        US   5      [        US   5      -
  S-   nUS   [        SU5       VVs/ s H  osS     H	  oXv-  -   PM     M     snn-   US'   U4$ s  snnf )Nr   rf  ri   r2  r   rk  )	rx   rq  ndimrs   r9  r:  ra   r`   rr   )	r7   r   rx  r-   rr  rs  offsetr}   r   s	            r   rq  RepeatLatentBatch.repeat  s   LLNy!{{F9		A0F#GH)7"w|'<'B'B1'E'IL)E{{1~

1-dii

1A0N&O%QUY]b]g]gjk]kUl%mno}ptpzpz{|p}~%l3::F9PWXdPePjPjmnPnHo;pqAlOA=)*S=1A-BBQFF /USTV\M]2xM]ivgwbc
3Cgw3CM]2xxAmt 3ys   E4r   N)r:   r;   r<   r=   rE   r>   r.   r@   rB   rC   rq  rF   r   r   r   rv  rv    s4    (.9N! ! LH#Hr   rv  c                   N    \ rS rSrSS/r/ SQrSS/r\S 5       rSr	S	r
S
rS rSrg)LatentUpscalei  enlarge latentresize latentnearest-exactr,  r   bicubicbislerpdisabledr  c           
      n    SSU R                   4SSS[        SS.4SSS[        SS.4U R                  4S.0$ )	Nr$   r   r   r   r   r   r^   )r   upscale_methodr   r   r  upscale_methodsr   crop_methodsr,   s    r   r.   LatentUpscale.INPUT_TYPES  sQ    IZIZH\(-3qQ_ij/k'l).CR`jk0l(m'(~~&79 : 	:r   r   upscaler   c                    US:X  a  US:X  a  UnU4$ UR                  5       nUS:X  aH  [        SU5      n[        S[        US   R                  S   U-  US   R                  S   -  5      5      nOfUS:X  aH  [        SU5      n[        S[        US   R                  S   U-  US   R                  S   -  5      5      nO[        SU5      n[        SU5      n[        R
                  R                  US   US-  US-  X%5      US'   U4$ )Nr   r   r   r   r   r   )rx   ra   r=  rs   r   r  common_upscale)r7   r   r  r   r   r  r-   s          r   r  LatentUpscale.upscale  s   A:&A+A t AzRBgi&8&>&>r&BV&KgV_N`NfNfgiNj&j kl1BRwy'9'?'?'Ce'KgV_N`NfNfgiNj'j!klBR ;;55gi6H%ST*V\`aVacqxAiLtr   r   N)r:   r;   r<   r=   rE   r  r  r>   r.   r@   rB   rC   r  rF   r   r   r   r  r    sC    &8NQO)L: :
 LHHr   r  c                   F    \ rS rSr/ SQr/ SQr\S 5       rSrSr	Sr
S rS	rg
)LatentUpscaleByi1  )r  r  zscale latentr  c           	      6    SSU R                   4SSSSSS.4S.0$ )	Nr$   r   rZ   g      ?r]          @r^   )r   r  scale_byr  r,   s    r   r.   LatentUpscaleBy.INPUT_TYPES6  s7    IZIZH\+2DY\fj4k*lo p 	pr   r   r  r   c                     UR                  5       n[        US   R                  S   U-  5      n[        US   R                  S   U-  5      n[        R                  R                  US   XVUS5      US'   U4$ )Nr   r   r   r  )rx   r=  rs   r   r  r  )r7   r   r  r  r-   r   r   s          r   r  LatentUpscaleBy.upscale?  sw    LLNgi(..r2X=>wy)//3h>?{{11')2DeUceop)tr   r   N)r:   r;   r<   r=   rE   r  r>   r.   r@   rB   rC   r  rF   r   r   r   r  r  1  s6    HNQOp p LHHr   r  c                   6    \ rS rSr\S 5       rSrSrSrS r	Sr
g)	LatentRotateiF  c                     SS/ SQ4S.0$ )Nr$   r   )r  z
90 degreesz180 degreesz270 degrees)r   rotationr   r,   s    r   r.   LatentRotate.INPUT_TYPESG  s    +_*a  ! 	!r   r   rotatemodel/latent/transformc                     UR                  5       nSnUR                  S5      (       a  SnO1UR                  S5      (       a  SnOUR                  S5      (       a  Sn[        R                  " US   USS/S	9US'   U4$ )
Nr   90ri   180rk   270r   r   )rJ  dims)rx   rA  rt   rot90)r7   r   r  r-   	rotate_bys        r   r  LatentRotate.rotateQ  sz    LLN	t$$I  ''I  ''I{{79#5!QP)tr   r   N)r:   r;   r<   r=   r>   r.   r@   rB   rC   r  rF   r   r   r   r  r  F  s*    ! ! LH'Hr   r  c                   <    \ rS rSrS/r\S 5       rSrSrSr	S r
Srg	)

LatentFlipi^  zmirror latentc                     SSSS/4S.0$ )Nr$   r   zx-axis: verticallyzy-axis: horizontally)r   flip_methodr   r,   s    r   r.   LatentFlip.INPUT_TYPESa  s"    /CE[.\-^  ! 	!r   r   flipr  c                     UR                  5       nUR                  S5      (       a  [        R                  " US   S/S9US'   U4$ UR                  S5      (       a  [        R                  " US   S/S9US'   U4$ )Nr   r   rk   )r  r   r   )rx   rA  rt   r  )r7   r   r  r-   s       r   r  LatentFlip.flipk  sw    LLN!!#&& ::gi&8sCAiL t ##C(( ::gi&8sCAiLtr   r   N)r:   r;   r<   r=   rE   r>   r.   r@   rB   rC   r  rF   r   r   r   r  r  ^  s2    %&N! ! LH'Hr   r  c                   B    \ rS rSr/ SQr\S 5       rSrSrSr	S
S jr
Srg	)LatentCompositeit  )zoverlay latentzlayer latentzpaste latentc                 X    SSSSSS[         SS.4SSS[         SS.4SSS[         SS.4S.0$ )Nr$   r   r   r   r   r^   )
samples_tosamples_fromr   r   featherr   r,   s    r   r.   LatentComposite.INPUT_TYPESw  sP    K.9$)q>cd+e#f$)q>cd+e#f*/QqQ_ij1k)l	  ! 	!r   r   	compositer   c           	         US-  nUS-  nUS-  nUR                  5       nUS   R                  5       nUS   nUS   nUS:X  a`  US S 2S S 2S UR                  S   U-
  2S UR                  S   U-
  24   US S 2S S 2XDUR                  S   -   2X3UR                  S   -   24'   GO.US S 2S S 2S UR                  S   U-
  2S UR                  S   U-
  24   n[        R                  " U5      n	[        U5       GH*  n
US:w  a%  U	S S 2S S 2U
SU
-   2S S 24==   SU-  U
S-   -  -  ss'   XBR                  S   -   UR                  S   :  aE  U	S S 2S S 2U	R                  S   S-
  U
-
  U	R                  S   U
-
  2S S 24==   SU-  U
S-   -  -  ss'   US:w  a%  U	S S 2S S 2S S 2U
SU
-   24==   SU-  U
S-   -  -  ss'   X2R                  S   -   UR                  S   :  d  M  U	S S 2S S 2S S 2U	R                  S   S-
  U
-
  U	R                  S   U
-
  24==   SU-  U
S-   -  -  ss'   GM-     [        R                  " U	5      U	-
  nUS S 2S S 2S UR                  S   U-
  2S UR                  S   U-
  24   U	-  US S 2S S 2XDUR                  S   -   2X3UR                  S   -   24   U-  -   US S 2S S 2XDUR                  S   -   2X3UR                  S   -   24'   XS'   U4$ )Nr   r   r   rk   r   ri   r[   )rx   r7  rs   rt   	ones_likerr   )r7   r  r  r   r   composite_methodr  samples_outr-   r   r   rev_masks               r   r  LatentComposite.composite  s   !VFQ, oo'y!'')	*
#I.a<IUVWXYZr[e[k[klm[nqr[rZr  uMu  vF  vF  GH  vI  LM  vM  uM  WM  JNAa!l((+++A0B0B10E.E,EEF'!,DZ-=-=a-@1-D,DF^zGWGWXYGZ]^G^F^(^_L??<0D7^61QqsU1%3w;1q5*AB%))!,,z/?/?/BB1TZZ]A-q0$**Q-/A!CD#g+Z[^_Z_I`aD61Qq1u%3w;1q5*AB%))!,,z/?/?/BB1Qtzz!}a/!3TZZ]A5EEEFCPWK\]`a\aKbcF $ t,t3HIUVWXYZr[e[k[klm[nqr[rZr  uMu  vF  vF  GH  vI  LM  vM  uM  WM  JN  QU  JU  XY  Z[  \]  ^_  bn  bt  bt  uv  bw  `w  ^w  xy  |H  |N  |N  OP  |Q  zQ  xQ  ZQ  XR  U]  X]  J]Aa!l((+++A0B0B10E.E,EEF!"I~r   r   N)normalr   )r:   r;   r<   r=   rE   r>   r.   r@   rB   rC   r  rF   r   r   r   r  r  t  s/    GN! ! LHHr   r  c                   T    \ rS rSrSS/r\S 5       rSrSrSr	SS\
S	\4S
 jjrS rSrg)LatentBlendi  zmix latentszinterpolate latentsc           	           SSSSSSSSS.4S	.0$ )
Nr$   r   rZ   r1  r   ri   r]   r^   )samples1samples2blend_factorr   r,   s    r   r.   LatentBlend.INPUT_TYPES  s3    ##$	' 	
 	 		r   r   blendr	  r  
blend_modec                 z   UR                  5       nUS   nUS   nUR                  UR                  :w  ab  UR                  SSSS5        [        R                  R                  X!R                  S   UR                  S   SSS9nUR                  SSSS5        U R                  XU5      nX-  USU-
  -  -   nXeS'   U4$ )	Nr   r   r   ri   rk   r  r  r  )rx   rs   permuter   r  r  r  )r7   r  r  r  r  r  samples_blendeds          r   r  LatentBlend.blend  s    mmoI&I&>>X^^+Q1a({{11(NN1<Mx~~^_O`bkrz1{HQ1a(//(jI"1Oq<GW4XX!0I~r   c                 .    US:X  a  U$ [        SU 35      e)Nr  zUnsupported blend mode: )
ValueError)r7   img1img2r/  s       r   r  LatentBlend.blend_mode  s"    8K7v>??r   r   N)r  )r:   r;   r<   r=   rE   r>   r.   r@   rB   rC   r  strr  r  rF   r   r   r   r  r    sI    #%:;N
 
 LHHU   @r   r  c                   >    \ rS rSrSS/r\S 5       rSrSrSr	S r
S	rg
)
LatentCropi  ztrim latentz
cut latentc                 n    SSSSS[         SS.4SSS[         SS.4SSS[         SS.4SSS[         SS.4S	.0$ )
Nr$   r   r   r   r   r   r^   r   )r   r   r   r   r   r   r,   s    r   r.   LatentCrop.INPUT_TYPES  s`    (-3rR`jk/l'm).CSakl0m(n$)q>cd+e#f$)q>cd+e#f	  ! 	!r   r   r  r  c                 *   UR                  5       nUS   nUS-  nUS-  nXAR                  S   S-
  :  a  UR                  S   S-
  nXQR                  S   S-
  :  a  UR                  S   S-
  nUS-  nUS-  nX-   n	Xu-   n
US S 2S S 2XZ2XI24   US'   U4$ )Nr   r   r   rk   )rx   rs   )r7   r   r   r   r   r   r-   
new_height	new_widthto_xto_ys              r   r  LatentCrop.crop  s    LLN)$!VF a 1$%a 1$Aa 1$%a 1$Aq[
QJ	}~q161612)tr   r   N)r:   r;   r<   r=   rE   r>   r.   r@   rB   rC   r  rF   r   r   r   r  r    s4    #\2N! ! LH'Hr   r  c                   6    \ rS rSr\S 5       rSrSrSrS r	Sr
g)	SetLatentNoiseMaski  c                     SSSS.0$ )Nr$   r   r   )r   r   r   r,   s    r   r.   SetLatentNoiseMask.INPUT_TYPES  s    iJKKr   r   set_maskr   c                     UR                  5       nUR                  SSUR                  S   UR                  S   45      US'   U4$ )Nr   ri   r   r2  )rx   r   rs   )r7   r   r   r-   s       r   r  SetLatentNoiseMask.set_mask  s?    LLN,,Atzz"~tzz"~'NO,tr   r   N)r:   r;   r<   r=   r>   r.   r@   rB   rC   r  rF   r   r   r   r  r    s*    L LLHHr   r  c                    US   n[         R                  R                  XUR                  SS 5      UR                  SS 5      5      nU
(       a:  [        R
                  " UR                  5       UR                  UR                  SS9nO-SU;   a  US   OS n[         R                  R                  XU5      nS nSU;   a  US   n[        R                  " X5      n[         R                  R                  (       + n[         R                  R                  XX#XEXgUXXUUUUUS9nUR                  5       nUR                  SS 5        UR                  SS 5        UUS'   U4$ )	Nr   rb  downscale_ratio_temporalr  )r  layoutr  rk  r2  )	denoisedisable_noise
start_step	last_stepforce_full_denoiser2  callbackdisable_pbarseed)r   samplefix_empty_latent_channelsrq   rt   rv   r.  r  r  prepare_noiselatent_previewprepare_callbackr  PROGRESS_BAR_ENABLEDrx   pop)r  r  stepscfgsampler_name	schedulerrK  rL  r   r  r  r  r  r  latent_imagenoise
batch_indsr2  r  r  r   rz   s                         r   common_ksamplerr    sj   )$L<<99%vzzZsuyOz  }C  }G  }G  Hb  dh  }i  jLL--/|7I7IR^ReRenst.;v.EVM*4
**<zJJvL)
..u<H{{777Lll!!%LU]iu*1[e5GT^iq  AM  TX " YG ++-CGG%t,GG&-C	N7Nr   c                   J    \ rS rSr\S 5       rSrSrSrSr	Sr
/ SQrSS	 jrS
rg)KSampleri  c                    SSSS04SSSSSS	S
.4SSSSSS.4SSSSSSSS.4[         R                  R                  R                  SS04[         R                  R                  R                  SS04SSS04SSS04SSS04SSSSSS S!.4S".
0$ )#Nr$   r  r'   z.The model used for denoising the input latent.r   r       Tz,The random seed used for creating the noise.)r_   r`   ra   control_after_generater'      ri   '  z2The number of steps used in the denoising process.rZ  rZ   r  r\   r  皙?r]   zThe Classifier-Free Guidance scale balances creativity and adherence to the prompt. Higher values result in images more closely matching the prompt however too high values will negatively impact quality.)r_   r`   ra   rb   r=  r'   zhThe algorithm used when sampling, this can affect the quality, speed, and style of the generated output.zHThe scheduler controls how noise is gradually removed to form the image.r?   zLThe conditioning describing the attributes you want to include in the image.zNThe conditioning describing the attributes you want to exclude from the image.r   zThe latent image to denoise.r[   zThe amount of denoising applied, lower values will maintain the structure of the initial image allowing for image to image sampling.r  )
r  r  r  r  r  r  rK  rL  r  r  r   samplersr  SAMPLERS
SCHEDULERSr,   s    r   r.   KSampler.INPUT_TYPES  s/    !I/_#`aAa@Rnr  @n  !o  pR%  UI  "J  KSUSVae  s@  "A  B!&!8!8!A!AI  Pz  D{  !|#nn55@@9  OY  CZ  [+i  :H  .I  J+i  :J  .K  L!)I7U+V W#SVZ  hn  &o  p
 	
r   r   )zThe denoised latent.r  model/samplingzXUses the provided model, positive and negative conditioning to denoise the latent image.)samplerr  r]  r  diffusetxt2imgimg2imgc                     [        XX4XVXxXS9
$ )N)r  r  )r7   r  r  r  r  r  r  rK  rL  r  r  s              r   r  KSampler.sample/  s    uEQYeq  D  	Dr   r   Nr[   )r:   r;   r<   r=   r>   r.   r@   rA   rB   rC   rD   rE   r  rF   r   r   r   r  r    s:    
 
  L/OHHlKbNDr   r  c                   :    \ rS rSr\S 5       rSrSrSrS	S jr	Sr
g)
KSamplerAdvancedi2  c                    SSSS/SS04SSSS	SS
.4SSSSS.4SSSSSSS.4[         R                  R                  R                  4[         R                  R                  R                  4SSSSSSSSS.4SSSSSS.4SS/SS04S.0$ )Nr$   r)  enabledisabler   Tr   r   r  )r_   r`   ra   r  r  ri   r  rj  rZ   r  r\   r  r  r]   )r_   r`   ra   rb   r=  rL   r   )r_   r`   ra   r   )r  	add_noise
noise_seedr  r  r  r  rK  rL  r  start_at_stepend_at_stepreturn_with_leftover_noiser  r,   s    r   r.   KSamplerAdvanced.INPUT_TYPES3  s    (#+Y"7*d9K!L#(aJ\x|*}"~#Ae%LM#SWZei%jk%*^^%<%<%E%E$H"'.."9"9"D"D!G 2 2$0&+1U`d-e%f$)uQubf+g#h4=x3H:W[J\2] 	r   r   r  r  c                 J    SnUS:X  a  SnSnUS:X  a  Sn[        XXEXgXXUXUS9$ )NTr  Fr  )r  r  r  r  r  r  )r7   r  r  r  r  r  r  r  rK  rL  r  r  r  r  r  r  r  s                    r   r  KSamplerAdvanced.sampleK  sX    !%1!&	! Mu%lW_kw  Yf  s@  l~    	r   r   Nr  )r:   r;   r<   r=   r>   r.   r@   rB   rC   r  rF   r   r   r   r  r  2  s+     $ LHHr   r  c                   T    \ rS rSrS r\S 5       rSrSrSr	Sr
SrS	r/ S
QrSS jrSrg)	SaveImageiT  c                 b    [         R                  " 5       U l        SU l        SU l        SU l        g )Nro  rl  r  )r[  r\  r]  rs  prefix_appendcompress_levelr^  s    r   r_  SaveImage.__init__U  s)    &;;=	r   c                 *    SSS04SSSS.4S.S	S
S.S.$ )Nr   r'   zThe images to save.r*   r  zThe prefix for the file to save. This may include formatting information such as %date:yyyy-MM-dd% or %Empty Latent Image.width% to include values from nodes.rJ  )r   rb  rc  rd  re  rg  r   r,   s    r   r.   SaveImage.INPUT_TYPES[  sE     #Y0E$FG$,)  Qq  /r  $s
 #_
 	
r   r   save_imagesTr  Basicsz8Saves the input images to your ComfyUI output directory.)rj  z
save imagezexport imageoutput imagezwrite imagedownloadNc           	         X R                   -  n[        R                  " X R                  US   R                  S   US   R                  S   5      u  pVpxn[        5       n	[        U5       GHn  u  pSUR                  5       R                  5       -  n[        R                  " [        R                  " USS5      R                  [        R                  5      5      nS n[        R                   (       dg  [#        5       nUb&  UR%                  S[&        R(                  " U5      5        Ub1  U H+  nUR%                  U[&        R(                  " XO   5      5        M-     UR+                  S[-        U
5      5      nU SUS S	3nUR/                  [0        R2                  R5                  UU5      XR6                  S
9  U	R9                  UUU R:                  S.5        US-  nGMq     SSU	00$ )Nr   ri        o@   r2   z%batch_num%rm  rn  z_.png)pnginfor%  rp  rw  r   )r$  r[  ry  r]  rs   list	enumerater  numpyr   	fromarraynpr)   astypeuint8r   r|  r   add_textrz  r{  replacer  rj  r}  r~  r  r%  ry   rs  )r7   r   rb  r2   rf  r  rq  r  rr  r  batch_numberr  r}   imgrv  r   filename_with_batch_numr  s                     r   r)  SaveImage.save_imagesq  s   ---LXLlLlm|  N  N  PV  WX  PY  P_  P_  `a  Pb  dj  kl  dm  ds  ds  tu  dv  MwIg/&%.v%6!\uyy{((**A//"''!Q"4";";BHH"EFCH(("9%%%h

60BC ,* ))!TZZ8H-IJ + '/&6&6}c,FW&X#-.a|5ADHHRWW\\"4d;X^q^qHrNN &		 
 qLG) &7, 7,..r   r%  r]  r$  rs  r  )r:   r;   r<   r=   r_  r>   r.   r@   rB   r  rC   rU   rD   rE   r)  rF   r   r   r   r"  r"  T  sF      	
 	
 LHKH"LKfN/r   r"  c                   2    \ rS rSrS r/ SQr\S 5       rSrg)PreviewImagei  c                     [         R                  " 5       U l        SU l        SSR	                  S [        S5       5       5      -   U l        SU l        g )Ntemp_temp_rl  c              3   N   #    U  H  n[         R                  " S 5      v   M     g7f)abcdefghijklmnopqrstupvxyzN)randomchoice).0r   s     r   	<genexpr>(PreviewImage.__init__.<locals>.<genexpr>  s      /nem`a>Z0[0[ems   #%r   ri   )r[  get_temp_directoryr]  rs  r  rr   r$  r%  r^  s    r   r_  PreviewImage.__init__  sD    &99;	%/nejklem/n(nnr   )previewzpreview imagez
show imagez
view imagezdisplay imagezimage viewerc                     SS0SSS.S.$ )Nr   r   rc  rd  re  rg  r   r,   s    r   r.   PreviewImage.INPUT_TYPES  s     {-%-P 	r   r>  N)	r:   r;   r<   r=   r_  rE   r>   r.   rF   r   r   r   r@  r@    s!      oN r   r@  c                   b    \ rS rSr\S 5       rSrSr/ SQrSr	Sr
S r\S	 5       r\S
 5       rSrg)	LoadImagei  c           	      ^   [         R                  " 5       n[        R                  " U5       Vs/ s HH  n[        R                  R                  [        R                  R                  X5      5      (       d  MF  UPMJ     nn[         R                  " US/5      nSS[        U5      SS0400$ s  snf )Nr  r$   image_uploadT)	r[  r  r}  r  r~  r  r  filter_files_content_typesr  r  s       r   r.   LoadImage.INPUT_TYPES  s     446	JJy1`1qRWW^^BGGLLQZD^5_1`77yIve}~t.DEF 	 as   AB*7B*r  r*  )z
load imagez
open imagezimport imagezimage inputzupload imagez
read imagezimage loaderr   r   
load_imagec                    [         R                  " U5      n[        R                  R	                  5       n[        R                  R                  5       n[        R                  " U5      R                  5       nUR                  R                  S   S:  au  UR                  R                  XCS9UR                  b   SUR                  S   -
  R                  XCS94$ [        R                  " UR                  R                  S   SS4X4S94$ [        R                   " ["        R$                  U5      n/ n/ nSu  p[&        R(                  " U5       GH  n[        R                   " [*        R,                  U5      nUR/                  S5      n[1        U5      S:X  a  UR2                  S   n	UR2                  S	   n
UR2                  S   U	:w  d  UR2                  S	   U
:w  a  M  [4        R6                  " U5      R9                  [4        R:                  5      S
-  n[        R<                  " U5      S   nSUR?                  5       ;   a_  [4        R6                  " URA                  S5      5      R9                  [4        R:                  5      S
-  nS[        R<                  " U5      -
  nO$[        R                  " S[        R:                  SS9nURC                  UR                  US95        URC                  URE                  S5      R                  US95        GM     [        RF                  " USS9n[        RF                  " USS9nUR                  XCS9UR                  XCS94$ )Nr   ra  r[   ).r   r   r  r  )NNRGBri   r.  r   A)r   r   r  r"  rl   )$r[  r  r   r   rd  rc  r   VideoFromFileget_componentsr   rs   r)  alphart   rv   r   pillowr   r  r   Iteratorr   exif_transposeconvertrn   r.  r5  arrayr6  float32
from_numpygetbands
getchannelry   r   ru   )r7   r  r  r  r  
componentsr;  output_imagesoutput_maskswhr}   r   output_imageoutput_masks                  r   rW  LoadImage.load_image  s   !88?
&&99;'';;=,,Z8GGI
""1%)%%(((D  KU  K[  K[  KgsZM]M]^eMfGfFjFjrxFj  GG  {  {  mr  mx  mx  zD  zK  zK  zQ  zQ  RS  zT  VX  Z\  y]  ej  mz  {  { !!%**j9'',A##H$;$;Q?AIIe$E=!Q&JJqMJJqMzz!}!UZZ]a%7HHUO**2::6>E$$U+E2Eajjl"xxS 1299"**EME,,T22{{85==O  !67q 1 4 45 4 AB) -, yyA6ii!4v;[^^SY^=ghhr   c                    [         R                  " U5      n[        R                  " 5       n[	        US5       nUR                  UR                  5       5        S S S 5        UR                  5       R                  5       $ ! , (       d  f       N,= fr  r  )r-   r  r  rD  r  s        r   r  LoadImage.IS_CHANGED  s]    !88?
NN*d#qHHQVVX $xxz~~ $#r  c                 \    [         R                  " U5      (       d  SR                  U5      $ g)NzInvalid image file: {}Tr  )r-   r  s     r   r  LoadImage.VALIDATE_INPUTS  s'    55e<<+22599r   r   N)r:   r;   r<   r=   r>   r.   rC   rU   rE   r@   rB   rW  r  r  rF   r   r   r   rQ  rQ    s_      H"~N$LH*iX      r   rQ  c                   t   ^  \ rS rSrSr/ SQr/ SQr\U 4S j5       rSr	Sr
SrU 4S	 jr\U 4S
 j5       rSrU =r$ )LoadImageMaski  Image Tools)zimport maskz
alpha maskzchannel mask)r^  redgreenbluec                 P   > [         TU ]  5       nS0 US   ESU R                  40E0$ )Nr$   channel)superr.   _color_channels)r-   types	__class__s     r   r.   LoadImageMask.INPUT_TYPES  sB    #% 
#A--0
 	
r   r  r   load_image_maskc                 N  > [         TU ]  U5      u  p4US   R                  5       nUS:X  a  U4$ SSSS.R                  US5      nXcR                  S   :  a  USU4   R                  5       4$ [        R                  " UR                  S S UR                  UR                  S9nU4$ )	Nr   r[  ri   rk   )RGBr   .rY  )
r|  rW  r  rq   rs   r7  rt   rv   r  r  )	r7   r  r{  image_tensormask_tensorr   channel_idx
empty_maskr  s	           r   r  LoadImageMask.load_image_mask  s    $)G$6u$=!AJ8>!AA.221a8++B// k!1288:<<""3B'"((#**J
 = r   c                 "   > [         TU ]  U5      $ r   )r|  r  )r-   r  r{  r  s      r   r  LoadImageMask.IS_CHANGED  s    w!%((r   r   )r:   r;   r<   r=   rU   rE   r}  r>   r.   rC   r@   rB   r  r  rF   __classcell__)r  s   @r   ru  ru    sO    'BN7O
 
 HL H!& ) )r   ru  c                   8    \ rS rSrSS/r\S 5       rSrSrSr	Sr
g	)
LoadImageOutputi  r+  zprevious generationc           	      "    SSSSSSSSS.S	.400$ )
Nr$   r  COMBOTro  z/internal/files/outputfirst)routerefresh_buttoncontrol_after_refresh)rS  image_folderremoter   r,   s    r   r.   LoadImageOutput.INPUT_TYPES  s9     '$($,!9*.18$ 

 	
r   zLoad an image from the output folder. When the refresh button is clicked, the node will update the image list and automatically select the first image, allowing for easy iteration.TrW  r   N)r:   r;   r<   r=   rE   r>   r.   rD   EXPERIMENTALrB   rF   r   r   r   r  r    s1    $&;<N
 
 IKLHr   r  c                   R    \ rS rSr/ SQrSS/r\S 5       rSrSr	Sr
S	r/ S
QrS rSrg)
ImageScalei.  r  r,  r   r  lanczosr  r  c           
      n    SSU R                   4SSS[        SS.4SSS[        SS.4U R                  4S.0$ )	Nr$   r   r   r   r   ri   r^   )r  r  r   r   r  r  r,   s    r   r.   ImageScale.INPUT_TYPES2  sQ    zaFWFWEY(-3qQ_ij/k'l).CR`jk0l(m'(~~&79 : 	:r   r   r  image/upscalingrv  )resizezresize imagezscale imagezimage resizezoomzzoom inzchange sizec                    US:X  a  US:X  a  UnU4$ UR                  SS5      nUS:X  a6  [        S[        UR                  S   U-  UR                  S   -  5      5      nO;US:X  a5  [        S[        UR                  S   U-  UR                  S   -  5      5      n[        R
                  R                  XsXBU5      nUR                  SS5      nU4$ )Nr   r   ri   r   rk   )r  ra   r=  rs   r   r  r  )r7   r  r  r   r   r  r-   r   s           r   r  ImageScale.upscale?  s    A:&A+A t mmBq)GzAuW]]1%5%>qAQ%QRS1QgmmA&6&>qAQ&Q RS**76SWXA		!BAtr   r   N)r:   r;   r<   r=   r  r  r>   r.   r@   rB   rC   rU   rE   r  rF   r   r   r   r  r  .  sD    QO)L: :
 LH H'pNr   r  c                   B    \ rS rSrSr/ SQr\S 5       rSrSr	Sr
S rS	rg
)ImageScaleByiN  rv  r  c           	      6    SSU R                   4SSSSSS.4S.0$ )	Nr$   r   rZ   r[   r]   r  r^   )r  r  r  r  r,   s    r   r.   ImageScaleBy.INPUT_TYPESR  s7    zaFWFWEY+2DY\fj4k*lo p 	pr   r   r  r  c                     UR                  SS5      n[        UR                  S   U-  5      n[        UR                  S   U-  5      n[        R                  R                  XEXbS5      nUR                  SS5      nU4$ )Nr   ri   r   rk   r  )r  r=  rs   r   r  r  )r7   r  r  r  r   r   r   r-   s           r   r  ImageScaleBy.upscale[  sp    --1%gmmA&12w}}Q'(23KK&&wvzZIIaOtr   r   N)r:   r;   r<   r=   rU   r  r>   r.   r@   rB   rC   r  rF   r   r   r   r  r  N  s7    'QOp p LH Hr   r  c                   @    \ rS rSrS/rSr\S 5       rSrSr	Sr
S rS	rg
)ImageInvertic  zreverse colorsrv  c                     SSS00$ )Nr$   r  r   r   r,   s    r   r.   ImageInvert.INPUT_TYPESg  s    gz233r   r   invertzimage/colorc                     SU-
  nU4$ )Nr[   r   )r7   r  r-   s      r   r  ImageInvert.invertp  s    %Ktr   r   N)r:   r;   r<   r=   rE   rU   r>   r.   r@   rB   rC   r  rF   r   r   r   r  r  c  s8    &'N'4 4 LHHr   r  c                   B    \ rS rSr/ SQr\S 5       rSrSrSr	Sr
S rS	rg
)
ImageBatchit  )zcombine imageszmerge imageszstack imagesc                     SSSS.0$ )Nr$   r   )image1image2r   r,   s    r   r.   ImageBatch.INPUT_TYPESw  s    
jIJJr   r   batchzimage/batchTc                 X   UR                   S   UR                   S   :w  au  UR                   S   UR                   S   :  a+  [        R                  R                  R	                  USSSS9nO*[        R                  R                  R	                  USSSS9nUR                   SS  UR                   SS  :w  a]  [
        R                  R                  UR                  SS5      UR                   S   UR                   S   SS	5      R                  SS5      n[        R                  " X4S
S9nU4$ )Nr   )r   ri   constantr[   )r/  r   ri   rk   r,  r  r   rl   )
rs   rt   r4  r5  padr   r  r  r  ru   )r7   r  r  r-   s       r   r  ImageBatch.batch  s   <<v||B//||B&,,r"22,,00ZWZ0[,,00ZWZ0[<<v||AB//[[//r!0DfllSToW]WcWcdeWfhrt|}  F  F  GH  IK  LFIIv&A.tr   r   N)r:   r;   r<   r=   rE   r>   r.   r@   rB   rC   r  r  rF   r   r   r   r  r  t  s6    GNK K LHHJ	r   r  c                   D    \ rS rSrS
S jr\S 5       rSrSrSr	SS jr
Srg	)
EmptyImagei  c                     Xl         g r   r  )r7   r  s     r   r_  EmptyImage.__init__  s    r   c                 \    SSSS[         SS.4SSS[         SS.4SSSSS.4SSSS	SS
S.4S.0$ )Nr$   r   r   ri   r^   r   rj  r   i color)r_   r`   ra   rb   display)r   r   r[  r  r   r,   s    r   r.   EmptyImage.INPUT_TYPES  s^    3qQ_ij/k'l).CR`jk0l(m-2!TX4Y,Z(-1Qxabov/w'x  ! 	!r   r   r]  r  c                 p   [         R                  R                  5       n[         R                  R                  5       n[        R
                  " X2US/US-	  S-  S-  XeS9n[        R
                  " X2US/US-	  S-  S-  XeS9n[        R
                  " X2US/US-  S-  XeS9n	[        R                  " XxU	4SS94$ )Nri   rY  r/  ra  r   r   rl   )r   r   rd  rc  rt   fullru   )
r7   r   r   r[  r  r  r  rgbs
             r   r]  EmptyImage.generate  s    &&99;'';;=JJ
E15"8LPT7T]cqJJ
E15!t8Kt7S\bpJJ
E15$$7NW]k		1),//r   r  N)r  )ri   r   )r:   r;   r<   r=   r_  r>   r.   r@   rB   rC   r]  rF   r   r   r   r  r    s1     ! ! LHH0r   r  c                   >    \ rS rSrSS/r\S 5       rSrSrSr	S r
S	rg
)ImagePadForOutpainti  zextend canvaszexpand imagec                     SSSSS[         SS.4SSS[         SS.4SSS[         SS.4SSS[         SS.4SSS[         SS	S
.4S.0$ )Nr$   r   r   r   r   r^   (   ri   Tr   )r  lefttoprightbottom
featheringr   r,   s    r   r.   ImagePadForOutpaint.INPUT_TYPES  sv     #AaXY Z[1Q~WXYZQqYZ![\ a.Z["\]$"Q~_`nr&st	
 		
r   rV  expand_imagezimage/transformc                    UR                  5       u  pxp[        R                  " XxU-   U-   X-   U-   U
4[        R                  S9S-  nXS S 2X3U-   2X"U	-   2S S 24'   [        R                  " X-   U-   X-   U-   4[        R                  S9n[        R                  " X4[        R                  S9nUS:  a  US-  U:  a  US-  U	:  aw  [        U5       Hh  n[        U	5       HV  nUS:w  a  UOUnUS:w  a  X-
  OUnUS:w  a  UOU	nUS:w  a  X-
  OU	n[        UUUU5      nUU:  a  ME  UU-
  U-  nUU-  XU4'   MX     Mj     XX3U-   2X"U	-   24'   XR                  S5      4$ )Nr"  r1  r   rk   )r.  rt   r8  rd  rv   rr   r`   r   )r7   r  r  r  r  r  r  d1d2d3d4	new_imager   r   r}   jdtdbdldrr   rG  s                         r   r   ImagePadForOutpaint.expand_image  s   JJcF"BI$5r:--
 	
 9>!Sr\4r	>145zzX	E 12--

 KKH--

 >j1nr1j1nr6I2YrA!QhBB#)Q;BB"aiRB#(A:2BBB+AJ #a:5A!eAdG # " ./Sr\4r	>)*>>!,--r   r   N)r:   r;   r<   r=   rE   r>   r.   r@   rB   rC   r  rF   r   r   r   r  r    s4    %~6N

 

 %LH H).r   r  )r   r  r  r=  rI  rG  r  r  r  rY  r   r   r'  zKSampler (Advanced)z(Load Checkpoint With Config (DEPRECATED)zLoad CheckpointzLoad VAEzLoad LoRA (Model and CLIP)z	Load LoRAz	Load CLIPzLoad CLIP (Dual)zLoad ControlNet ModelzLoad ControlNet Model (diff)zLoad Style ModelzLoad CLIP VisionzLoad Diffusion ModelzLoad unCLIP CheckpointzLoad GLIGEN Modelz!Load Diffusers Model (DEPRECATED)zCLIP Vision EncodezApply Style ModelzCLIP Text Encode (Prompt)zCLIP Set Last LayerzConditioning (Combine)zConditioningAverage zConditioning (Average)zConditioning (Concat)zConditioning (Set Area)z'Conditioning (Set Area with Percentage)z Conditioning (Set Area Strength)zConditioning (Set Mask)zApply ControlNet (DEPRECATED)zApply ControlNetzApply GLIGEN Text BoxzConditioning Zero OutzVAE Encode (for Inpainting)zSet Latent Noise Maskz
VAE Decodez
VAE EncodezRotate LatentzFlip LatentzCrop LatentzEmpty Latent ImagezUpscale LatentzUpscale Latent ByzLatent CompositezLatent BlendzGet Latent From BatchzRepeat Latent BatchzEmpty Imagez
Save ImagezPreview Imagez
Load ImagezLoad Image (as Mask)zLoad Image (from Outputs)zUpscale ImagezUpscale Image ByzInvert Image ColorszPad Image for OutpaintingzBatch Images (DEPRECATED)	ImageCropz
Crop ImageImageStitchzStitch Images
ImageBlendzBlend Images	ImageBlurz
Blur ImageImageQuantizezQuantize ImageImageSharpenzSharpen ImageImageScaleToTotalPixelszScale Image to Total PixelsGetImageSizezGet Image SizezVAE Decode (Tiled)zVAE Encode (Tiled)module_pathr"   c                     [         R                  R                  U 5      n[         R                  R                  U 5      (       a"  [         R                  R	                  U5      S   nU$ )ak  
Returns the module name based on the given module path.
Examples:
    get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node.py") -> "my_custom_node"
    get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node") -> "my_custom_node"
    get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/") -> "my_custom_node"
    get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/__init__.py") -> "my_custom_node"
    get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/__init__") -> "my_custom_node"
    get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/__init__/") -> "my_custom_node"
    get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node.disabled") -> "custom_nodes
Args:
    module_path (str): The path of the module.
Returns:
    str: The module name.
r   )r}  r~  basenamer  ri  )r  	base_paths     r   get_module_namer  ~  sJ        -I	ww~~k""GG$$Y/2	r   custom_nodesc           	        #    [        U 5      n[        R                  R                  U 5      (       a'  [        R                  R	                  U 5      nUS   nUnO6[        R                  R                  U 5      (       a  U R                  SS5      n [        R                  " SR                  U 5      5        [        R                  R                  U 5      (       aC  [        R                  R                  WU 5      n[        R                  R                  U 5      S   nO@[        R                  R                  W[        R                  R                  U S5      5      nU n[        R                  R                  U5      nU[         R"                  U'   UR$                  R'                  U5        [        R                  R)                  U5      [*        U'    SSKJn	  U	R1                  U 5      n
U
R2                  R4                  nU(       a  [        R                  R                  X5      n[        R                  R                  U5      (       aD  U
R6                  R8                  nU[:        U'   [        R<                  " SR                  X5      5        [C        US	5      (       a  [E        US	5      bt  [        R                  R)                  [        R                  R                  U[E        US	5      5      5      n[        R                  R                  U5      (       a	  U[:        U'   [C        US
5      (       a  [E        US
5      b  URF                  RI                  5        H7  u  nnUU;  d  M  U[F        U'   SR                  U[        U 5      5      Ul%        M9     [C        US5      (       a,  [E        US5      b  [L        RO                  URL                  5        g[C        US5      (       Ga  [E        US5      n[Q        U5      (       d  [        R@                  " SU  S35        g [R        RT                  " U5      (       a  U" 5       I S h  vN nOU" 5       n[W        U[X        5      (       d  [        R@                  " SU  S35        gUR[                  5       I S h  vN   UR]                  5       I S h  vN n[W        U[^        5      (       d  [        R@                  " SU  S35        gU H  nURa                  5       nURb                  U;  a3  U[F        URb                  '   SR                  U[        U 5      5      Ul%        URd                  c  Me  URd                  [L        URb                  '   M     g[        R@                  " SU  S35        g! [>         a$  n[        R@                  " SU 35         S nAGNS nAff = f GNr GN% GN! [>         a&  n[        R@                  " SU  SU 35         S nAgS nAff = f! [>         aO  n[        R@                  " [f        Rh                  " 5       5        [        R@                  " SU  SU 35         S nAgS nAff = f7f)Nr   ._x_zTrying to load custom node {}z__init__.py)config_parserz+Automatically register web folder {} for {}zwUnable to parse pyproject.toml due to lack dependency pydantic-settings, please run 'pip install -r requirements.txt': WEB_DIRECTORYNODE_CLASS_MAPPINGSz{}.{}NODE_DISPLAY_NAME_MAPPINGSTcomfy_entrypointzcomfy_entrypoint in z is not callable, skipping.Fz+ did not return a ComfyExtension, skipping.z* did not return a list of nodes, skipping.z(Error while calling comfy_entrypoint in z: zSkip z_ module for custom nodes due to the lack of NODE_CLASS_MAPPINGS or comfy_entrypoint (need one).zCannot import z module for custom nodes: )5r  r}  r~  r  ri  isdirr9  ro   debugr  	importlibutilspec_from_file_locationr>  r  module_from_specsysmodulesloaderexec_moduleabspathLOADED_MODULE_DIRScomfy_configr  extract_node_configuration
tool_comfywebprojectrR  EXTENSION_WEB_DIRSinfo	Exceptionrp   hasattrr  r  itemsRELATIVE_PYTHON_MODULEr  r  callableinspectiscoroutinefunction
isinstancer   on_loadget_node_listr1  
GET_SCHEMAnode_iddisplay_name	traceback
format_exc)r  ignoremodule_parentmodule_namespsys_module_namemodule_spec
module_dirmoduler  project_configweb_dir_nameweb_dir_pathproject_nameeweb_dirrR  node_cls
entrypoint	extension	node_listschemas                         r   load_custom_noder-    s    !+.K	ww~~k""WWk*e%	{	#	#%--c59U5<<[IJ77>>+&&#..@@R]^K{3A6J#..@@RTRYRYR^R^_jlyRz{K$J00='-O$&&v.*,''//**E;'	[2*EEkRN)4488L!ww||KF77==..#1#9#9#>#>L7C&|4LL!N!U!UVb!qr 6?++0P0\ggoobggll:wv?_&`aGww}}W%%29";/ 6011gfF[6\6h"("<"<"B"B"Dhv%08'-6=nn]TcdoTp6qH3 #E v;<<QmAnAz*11&2S2STV/00 );<JJ''"6{mC^ _`..z::&0l 2I *I!)^<<OO&:;-Gr$st '')))"+"9"9";;	!)T22OO&:;-Gq$rs  )H%002F~~V3>F+FNN;:A..XghsXt:u7**6EKEXEX26>>B !* 
 OOeK=  1P  Q  Re  	[OO  V  WX  VY  Z  [  [	[2 !3 *;  "J;-WYZ[Y\ ]^  	,,./.5OPQsSTs  BYD?W+ B;U> CW+ #A*W+ YAW+ Y%V8 =V/>;V8 9Y:V8 V2V8 %V5&3V8 YA#V8 !V8 "Y#W+ =Y>
V,V'!W+ 'V,,W+ /V8 2V8 5V8 8
W(W#W+ "Y#W((W+ +
Y5AX?:Y?YYc            	        #    [        [        R                  5       5      n [        R                  " S5      n/ nU GH  n[
        R                  " [
        R                  R                  U5      5      nSU;   a  UR                  S5        U GHh  n[
        R                  R                  X55      n[
        R                  R                  U5      (       a(  [
        R                  R                  U5      S   S:w  a  Mo  UR                  S5      (       a  M  [        R                  (       a0  U[        R                   ;  a  ["        R$                  " SU S35        M  [        R&                  (       a7  [(        R*                  " U5      (       a  ["        R$                  " SU 35        GM  [,        R.                  " 5       n[1        X`SS	9I S
h  vN nUR3                  [,        R.                  " 5       U-
  Xh45        GMk     GM     [5        U5      S:  az  ["        R$                  " S5        [7        U5       H>  n	U	S   (       a  Sn
OSn
["        R$                  " SR9                  U	S   XS   5      5        M@     ["        R$                  " S5        g
g
 N7f)z
Initializes the external custom nodes.

This function loads custom nodes from the specified folder paths and imports them into the application.
It measures the import times for each custom node and logs the results.

Returns:
    None
r  __pycache__ri   z.pyz	.disabledz	Skipping z; due to disable_all_custom_nodes and whitelist_custom_nodeszBlocked by policy: r  Nr   z
Import times for custom nodes:rk   rl  z (IMPORT FAILED)z{:6.1f} seconds{}: {})r=  r  r-  r[  r  r}  r  r~  realpathremover  r  ri  r  r   disable_all_custom_nodeswhitelist_custom_nodesro   r
  enable_managercomfyui_managershould_be_disabledtimeperf_counterr-  ry   rn   r  r  )base_node_names
node_pathsnode_import_timescustom_node_pathpossible_modulespossible_moduler  time_beforesuccessr   import_messages              r   init_external_custom_nodesrC    s     -2245O..~>J&::bgg&6&67G&HI,,##M2/O'',,'7IKww~~k**rww/?/?/LQ/OSX/X##K00,,HcHc1cy(99tuv"""55kBBLL#6{m!DE++-K,[YghhG$$d&7&7&9K&G%^_#  0 '0 !78)*At!#!3LL077!nPQdST + 	R " is   GJJCJc                  z  #    [         R                  R                  [         R                  R                  [         R                  R	                  [
        5      5      S5      n / SQn/ nU HJ  n[        [         R                  R                  X5      SS9I Sh  vN (       a  M9  UR                  U5        ML     U$  N"7f)a  
Initializes the built-in extra nodes in ComfyUI.

This function loads the extra node files located in the "comfy_extras" directory and imports them into ComfyUI.
If any of the extra node files fail to import, a warning message is logged.

Returns:
    None
comfy_extras)uznodes_latent.pyznodes_hypernetwork.pyznodes_upscale_model.pyznodes_post_processing.pyznodes_mask.pyznodes_compositing.pyznodes_rebatch.pyznodes_model_merging.pyznodes_tomesd.pyznodes_clip_sdxl.pyznodes_canny.pyznodes_freelunch.pyznodes_custom_sampler.pyznodes_hypertile.pyznodes_model_advanced.pyznodes_model_downscale.pyznodes_images.pyznodes_video_model.pyznodes_ideogram4.pyznodes_train.pyznodes_dataset.pyznodes_sag.pyznodes_perpneg.pyznodes_stable3d.pyznodes_sdupscale.pyznodes_photomaker.pyznodes_pixart.pyznodes_cond.pyznodes_morphology.pyznodes_stable_cascade.pyznodes_differential_diffusion.pyznodes_ip2p.pyz%nodes_model_merging_model_specific.pyznodes_pag.pyznodes_align_your_steps.pyznodes_attention_multiply.pyznodes_advanced_samplers.pyznodes_webcam.pyznodes_audio.pyznodes_sd3.pyznodes_gits.pyznodes_controlnet.pyznodes_hunyuan.pyznodes_eps.pyznodes_flux.pyznodes_lora_extract.pyznodes_torch_compile.pyznodes_mochi.pyznodes_slg.pyznodes_mahiro.pyznodes_lt_upsampler.pyznodes_lt_audio.pyznodes_lt.pyznodes_hooks.pyznodes_multigpu.pyznodes_load_3d.pyznodes_cosmos.pyznodes_video.pyznodes_lumina2.pyznodes_wan.pyznodes_bernini.pyznodes_lotus.pyznodes_hunyuan3d.pyznodes_primitive.pyznodes_cfg.pyznodes_optimalsteps.pyznodes_hidream.pyznodes_fresca.pyznodes_apg.pyznodes_preview_any.pyznodes_ace.pyznodes_string.pyznodes_camera_trajectory.pyznodes_edit_model.pyznodes_tcfg.pyznodes_context_windows.pyznodes_qwen.pyznodes_chroma_radiance.pyznodes_pid.pyznodes_model_patch.pyznodes_easycache.pyznodes_audio_encoder.pyznodes_rope.pyznodes_logic.pyznodes_resolution.pyznodes_nop.pyznodes_kandinsky5.pyznodes_wanmove.pyznodes_ar_video.pyznodes_image_compare.pyznodes_zimage.pyznodes_glsl.pyznodes_lora_debug.pyznodes_textgen.pyznodes_color.pyznodes_toolkit.pyznodes_replacements.pyznodes_nag.pyznodes_sdpose.pyznodes_math.pyznodes_number_convert.pyznodes_painter.pyznodes_curve.pyznodes_bg_removal.pyznodes_rtdetr.pyznodes_frame_interpolation.pyznodes_sam3.pyznodes_scail.pyznodes_void.pyznodes_wandancer.pyznodes_hidream_o1.pyznodes_save_3d.pyznodes_moge.pyznodes_mediapipe.pyznodes_gaussian_splat.pyznodes_triposplat.pyznodes_depth_anything_3.pyr0  N)r}  r~  r  dirnamer1  __file__r-  ry   )
extras_dirextras_filesimport_failed	node_files       r   init_builtin_extra_nodesrL  #	  s      bggoobgg.>.>x.HI>ZJvLp M!	%bggll:&IYghhh  + "  is   BB;B9B;"B;c                    #    [         R                  R                  [         R                  R                  [         R                  R	                  [
        5      5      S5      n [        [        R                  " [         R                  R                  U S5      5      5      n/ nU HJ  n[        USS9I S h  vN (       a  M  UR                  [         R                  R                  U5      5        ML     U$  N?7f)Ncomfy_api_nodesz
nodes_*.pyr0  )r}  r~  r  rF  r1  rG  r  globr-  ry   r  )api_nodes_dirapi_nodes_filesrJ  rK  s       r   init_builtin_api_nodesrR  	  s     GGLL1A1A(1K!LN_`MTYYrww||M<'PQROM$	%i?PQQQ  !1!1)!<= %  Rs   B0C42C23C4>5C4c                  z   #    [        [         V s/ s H  n [        [        U S5      U S9PM     sn 5        g s  sn f 7f)NVERSION)version	api_class)r   r   r   r  )rG  s    r   init_public_apisrW  	  sE      &	 &a 	Ay)	
 &	  s   ;6;c                   #    [        5       I S h  vN   [        5       I S h  vN n/ nU(       a  [        5       I S h  vN nU (       a  [        5       I S h  vN   O[        R
                  " S5        [        U5      S:  a  [        R                  " S5        U H(  n[        R                  " SR                  U5      5        M*     [        R                  " S5        [        R                  (       a  [        R                  " S5        O[        R                  " S5        [        R                  " S5        [        U5      S:  a  [        R                  " S	5        U H(  n[        R                  " SR                  U5      5        M*     [        R                  " S5        [        R                  (       a  [        R                  " S5        O[        R                  " S5        [        R                  " S5        U$  GN GN GN GN7f)
Nz Skipping loading of custom nodesr   zwWARNING: some comfy_api_nodes/ nodes did not import correctly. This may be because they are missing some dependencies.
zIMPORT FAILED: {}z`
This issue might be caused by new missing dependencies added the last time you updated ComfyUI.z7Please run the update script: update/update_comfyui.batz,Please do a: pip install -r requirements.txtrl  ztWARNING: some comfy_extras/ nodes did not import correctly. This may be because they are missing some dependencies.
)rW  rL  rR  rC  ro   r
  rn   rp   r  r   windows_standalone_build)init_custom_nodesinit_api_nodesrJ  import_failed_apinodes        r   init_extra_nodesr^  	  sc    

244M"8"::(***78
!  S  	T%DOO/66t<= &{|((OOUVOOJK
=A  P  	Q!DOO/66t<= "{|((OOUVOOJKG 4 ; 	+sB   HG6HG9HG<HG?F H9H<H?HrV  )r[   FNNFr  )rt   r}  r  rz  rO  r  r  r  r9  r8  rF  ro   PILr   r   r   PIL.PngImagePluginr   r3  r5  safetensors.torchr  r~  insertr  rF  r1  rG  comfy.diffusers_loadr   comfy.samplerscomfy.samplecomfy.sdcomfy.utilscomfy.controlnetcomfy.comfy_typesr   r	   r
   r   comfy_api.internalr   r   comfy_api.version_listr   comfy_api.latestr   r   r   comfy.clip_visioncomfy.model_managementcomfy.cli_argsr   r  r[  r  r   r5  r6  r   r   r   r    rH   rW   r   r   r   r   r   r   r   r   r   r  r  r&  rG  rY  r  r  r  r  r  r  r  r'  r/  rr  r  r  r  r  r  r  r  r  r  r  r4  r=  rI  rW  rh  rv  r  r  r  r  r  r  r  r  r  r  r  r"  r@  rQ  ru  r  r  r  r  r  r  r  r  r  r	  r  r  r  r=  r(  r-  rC  rL  rR  rW  r^  r   r   r   <module>rp     s
    
 
          . . &   277<<0@0@0J KWU V       J J E 5 : :       G? =\ =03 3& &P 8 . *   6 2   6 B! !" "$&R &RR1, 1,h20 20j# #Ld d$ .p p<   -' -'^O* O] ]~ $ " >0  0 f 2 6 < " &  = =~ (  >E E." "H 8" "H * 0 ,* *X)@ )@V! !F 2D D:   D7/ 7/r9  J JZ))I ))Xi 0 @ * " 00 00>. >.BDD4D nD (	D
 D D .D D (D ]D D D *D D LD  !D" ]#D$ %D& *'D( L)D* ;+D, *-D. ./D0 *1D2 .3D4 .5D6 ,7D8 .9D: $%B;D< "#>=D> .?D@ (ADB ,CDD EDF ;GDH LIDJ *KDL *MDN *ODP *QDR *SDT nUDV (WDX YDZ ,[D\ ]D^ 6_D` (aDb 0cDd (eDf (gDh %$4 , 8(&.$@.GD LK
K -K
 BK /K K .K ;K +K (K /K :K *K *K  (!K" 6#K$ '%K& :'K* ,+K, *-K. 1/K0 -1K2 33K4 45K6 37K8 19K: 4;K< $%N=K> "#E?K@ 4AKB 6CKD 1EKF 1GKH 2IKL 8MKN 1OKP QKR SKT OUKV -WKX -YKZ ,[K\ %]K^ *_K` )aKb >cKd /eKf .gKj -kKl mKn OoKp qKr +sKt 2uKv /wKx &yKz ({K| 6}K~ -K@ AKB ?CKD .EKF GKH %IKJ OKKL <MKN $OKR *SKT *UK Z      , 58E ^ ^\` ^@-^HV	$r   