
    
3j
                         S SK r S SKrS SKrS SKJr  S SKrS SKrSSKJr  SSKJ	r	  S r
SS\R                  4S jjrSS	 jrSS
 jrSS jrSS jr " S S5      r " S S5      r\R                  \\\\\\\0r\\/rg)    N)Path   )log)
tensor2pilc           
         / n[        U 5      R                  nUR                  SU 35        [        U [        R
                  5      (       ao  UR                  SU R                   3SU R                   3SU R                   3SU R                   3SU R                  5        3SU R                  5        3/5        U$ [        U [        [        45      (       aU  UR                  S[        U 5       3S	U 3/5        U (       a*  UR                  S
[        U S   5      R                   35        U$ [        U [         5      (       a;  UR                  S[        U 5       3S[        U R#                  5       5       3/5        U$ [%        U S5      (       aF  ['        U 5       Vs/ s H  o3R)                  S5      (       a  M  UPM     nnUR                  SU 35        U$ s  snf )NzType: zShape: zDtype: zDevice: zRequires grad: zStride: zContiguous: zLength: zContainer type: zElement type: r   zKeys: __dict___zAttributes: )type__name__append
isinstancetorchTensorextendshapedtypedevicerequires_gradstrideis_contiguouslisttuplelendictkeyshasattrdir
startswith)obj	type_info	type_nameattr
attributess        B/home/wildlama/comfy/ComfyUI/custom_nodes/comfy_mtb/nodes/debug.pyget_detailed_type_infor%      s   IS	""Ivi[)*#u||$$#))%#))%3::,'!#"3"3!453::<.)s00234		
< ) 
C$	'	'3s8*%"9+.	
 ~d3q6l.C.C-DEF  
C		3s8*%chhj)*+	
 	 
j	!	!'*3xLxts7Kdx
L<
|45 Ms   G5Gtensorc                 P   [         R                  " SU R                   35        U(       a  SSU R                   SU R                   3/0$ [	        U R                  5      S:H  nU(       a#  U R                  S5      R                  SSSS5      n [        U 5      n/ nU H  nU(       a  UR                  S5      n[        R                  " 5       nUR                  US	S
9  UR                  S[        R                  " UR                  5       5      R!                  S5      -   5        M     SU0$ )NzTensor: textzTensor of shape z	 of type       LPNG)formatzdata:image/png;base64,zutf-8
b64_images)r   debugr   r   r   	unsqueezerepeatr   convertioBytesIOsaver   base64	b64encodegetvaluedecode)r&   as_typeis_maskimageb64_imgsimbuffereds          r$   process_tensorrA   6   s   II'('~Yv||nMN
 	
 &,,1$G!!"%,,Q1a8vEHCB::<
'$x0023::7CD	
  (##    c                 P   / nU (       d  S/ 0$ U(       a,  [        U 5      nUR                  [        U S   5      5        SU0$ U S   n[        U[        5      (       a[  U(       aT  [        US   [        R
                  5      (       a2  UR                  SUS   R                   S[        U 5       S35        SU0$ [        U[        R
                  5      (       a/  UR                  SUR                   S[        U 5       S35        SU0$ UR                  S[        U 5       SU  35        SU0$ )	Nr(   r   zList of List of Tensors: z (x)zList of Tensors: zArray (z): )	r%   r   r   r   r   r   r   r   r   )anythingr;   r(   r    first_elements        r$   process_listrG   S   s!   D|*84	/<=	""QKM=$''}Q'66'Q%%&c#h-;	
 D> 
M5<<	0	0 3 34CHaH	
 D> 	gc(m_Cz:;D>rB   c                    / nU(       a  S[        U 5      0$ SU ;   aI  [        R                  " U S   5      S:X  a  SOSnUR                  SU S   R                   SU 35        SU0$ SU ;   aN  [        R                  " U S   5      S:X  a  S	OSnUR                  S
U S   R                   U SU S    35        SU0$ [
        R                  " SU R                  5        35        UR                  [        R                  " U SS95        SU0$ )Nr(   samplesr   z(empty) zLatent Samples:  waveformz(empty) zAudio Samples: z | sample rate sample_ratezUnhandled dict: r   )indent)
r%   r   count_nonzeror   r   r   r0   r   jsondumps)rE   r;   r(   is_emptys       r$   process_dictrS   r   s#   D.x899H,,Xi-@AQFIB 	 	&x	':'@'@&A8*MN D> 
x	--hy.ABaGJR 	 	hz2889(?S[\iSjRkl	
 D> 			$X]]_$567DJJx23D>rB   c                 "    SU (       a  S/0$ S/0$ )Nr(   TrueFalse rE   r;   s     r$   process_boolrY      s    xV566W566rB   c                 F    U(       a  S[        U 5      0$ S[        U 5      /0$ )Nr(   )r%   strrX   s     r$   process_textr\      s'    .x899S]O$$rB   c                   J    \ rS rSrSr\S 5       rSrSrSr	Sr
S\S	\4S
 jrSrg)	MTB_Debug   z]Experimental node to debug any Comfy values.

support for more types and widgets is planned.
c                 $    SSSS040SSSS040S.$ )Noutput_to_consoleBOOLEANdefaultFas_detailed_typesrequiredoptionalrW   clss    r$   INPUT_TYPESMTB_Debug.INPUT_TYPES   s2     -y9e:L.MN,y9e:L.MN
 	
rB   rW   do_debug	mtb/debugTra   rd   c                 J   SS/ 00nU(       a4  UR                  5        H   u  pV[        R                  " U SU 35        M"     UR                  5        HM  u  px[        R	                  [        U5      [        5      n	U	" X5      n
SU0U
EnUS   S   R                  U5        MO     U$ )Nuiitemsz: input)rp   r   info
processorsgetr
   r\   r   )selfra   rd   kwargsoutputkv
input_namerE   	processor	processeditems               r$   rl   MTB_Debug.do_debug   s     "&A3b% ' %+LLN J"tH~|DI!(>I D 4L!((. %3 rB   N)r   
__module____qualname____firstlineno____doc__classmethodrj   RETURN_TYPESFUNCTIONCATEGORYOUTPUT_NODEboolrl   __static_attributes__rW   rB   r$   r^   r^      sF    
 
 
 LHHK!%:>rB   r^   c                       \ rS rSrSrS r\S 5       rSrSr	Sr
Sr   SS
\R                  S	-  S\R                  S	-  S\R                  S	-  4S jjrSrg	)MTB_SaveTensors   z[Save torch tensors (image, mask or latent) to disk.

useful to debug things outside comfy.
c                 F    [         R                  " 5       U l        SU l        g )Nrm   )folder_pathsget_output_directory
output_dirr
   )ru   s    r$   __init__MTB_SaveTensors.__init__   s    &;;=	rB   c                      SSSS040SSSS.S	.$ )
Nfilename_prefixSTRINGrc   ComfyPickle)IMAGE)MASK)LATENT)r=   masklatentre   rW   rh   s    r$   rj   MTB_SaveTensors.INPUT_TYPES   s2     "Hy-.H#I $!%		
 		
rB   r6   TrW   rm   Nr=   r   r   c                 R   [         R                  " XR                  5      u  nnnnn[        U5      nUb"  U SUS S3n	[        R
                  " X%U	-  5        Ub"  U SUS S3n
[        R
                  " X5U
-  5        Ub"  U SUS S3n[        R
                  " XEU-  5        U SUS 3$ )N_image_05z.pt_mask__latent_r	   )r   get_save_image_pathr   r   r   r6   )ru   r   r=   r   r   full_output_folderfilenamecounter	subfolder
image_file	mask_filelatent_files               r$   r6   MTB_SaveTensors.save   s     ,,_ooN	
!"45$:WWRL<JJJu:=> #*F72,c:IJJt);< %Jhwrl#>KJJvK?@ ""!GB<00rB   )r   r
   )NNN)r   r   r   r   r   r   r   rj   r   r   r   r   r   r   r6   r   rW   rB   r$   r   r      s    
  

 

 HKLH
 &*$(&*"1 ||d""1 llT!	"1
 t#"1 "1rB   r   )F)r7   r4   rP   pathlibr   r   r   r   utilsr   r%   r   rA   rG   rS   rY   r\   r^   r   r   r   r   rs   	__nodes__rW   rB   r$   <module>r      s     	      %R$5<< $:>67%& &R>1 >1D 
LL.,,,	
 (	rB   