
    
3jK                        % S r SSKrSSKJr  \R                  R                  S5      (       d  S\R                  S'   \R                  R                  S5      (       d  S\R                  S'   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  SS	KJr  SS
KJr  SrSr SSKJr  SrSSKJr  SSKJr  SSKJrJrJrJrJr  SSKJ r J!r!  0 r"\#\$\%4   \&S'   0 r'\#\$\$4   \&S'   0 r(\#\$\$S-  4   \&S'   Sr)S\4S jr*S r+S r,S\$4S jr-S\$4S jr.\!S-  r/0 r0\/Rc                  5       (       aX  \/Re                  5       (       aC  \/S-  Rg                  S 5       V s0 s H#  n \-" U Rh                  5      U Rk                  S!S"9_M%     sn r0\R                  R                  S#5      r6\+" 5       u  r7r8\7 GH}  r9\9Rt                  r;\$\&S$'   \0R                  \;5      r<\=" \9S%5      (       d  \<(       a  \R|                  " S&\; S'35        \<\9l?        O\9R                  (       aY  \R|                  " S(\; 35        \9R                  \9l?        \6(       a+  \." \;5      rA\/S-  \AS)-   -  R                  \9R                  S!S"9rCO\R|                  " S*\; 35        \" \;5       S+3rD\9\"\D'   \D\'\;'   \9R                  \(\D'   \R                  R                  S#5      (       d  GM  \E" \!S,-  S-5       rF\FR                  \	R                  " \I" \(R                  5       5       Vs0 s H	  nU\(U   _M     snS.S/95      rCSSS5        GM     \R|                  " S0S1R                  S2 \(R                  5        5       5      -   5        \R                  " S3\" \$" \N" \75      5      5       S435        \8(       ab  \R                  " \P5         \R                  5       u  rRrS\R                  " S5\N" \85       S6\R S7\S S835        \R|                  " \85        SSS5        S9 rT\(       a  \=" \S:5      (       a  \T" 5         S;S<S=S>S?S@.rUg! \ a    Sr GNf = fs  sn f s  snf ! , (       d  f       GM  = f! , (       d  f       Nb= f)Az0.5.4    N)RequestTF_FORCE_GPU_ALLOW_GROWTHtrueTF_GPU_ALLOCATORcuda_malloc_async)reload)Path)webF)PromptServerT   )endlog)get_node_dependencies)	blue_text	cyan_text	get_labelget_summarylog)	comfy_dirhereNODE_CLASS_MAPPINGSNODE_DISPLAY_NAME_MAPPINGSNODE_CLASS_MAPPINGS_DEBUGz./webfilenamec                 :   SnU R                  SS9n/ n [        R                  " U5      n[        R                  " U5       GH*  n[	        U[        R
                  5      (       d  M%  [        UR                  5      S:X  d  M@  UR                  S   n[	        U[        R                  5      (       d  Mp  UR                  S:X  d  M  [        R                  " XR                  5      nU(       d  M  [        R                  " U5      R                  S   R                  n[	        U[        R                  [        R                  -  5      (       a"  UR                  S UR                    5       5          U$     U$ ! ["         a    [$        R&                  " SU  35         U$ f = f)	N utf-8encodingr   r   	__nodes__c              3      #    U  H;  n[        U[        R                  5      (       d  M$  [        UR                  5      v   M=     g 7fN)
isinstanceastNamestrid).0elements     ?/home/wildlama/comfy/ComfyUI/custom_nodes/comfy_mtb/__init__.py	<genexpr>,extract_nodes_from_source.<locals>.<genexpr>I   s1      )/>G#-gsxx#@ !0GJJ/>s
   #AAzFailed to parse ast from: )	read_textr#   parsewalkr"   Assignlentargetsr$   r&   get_source_segmentvaluebodyListTupleextendeltsSyntaxErrorr   error)r   source_codenodesparsednodetargetr3   
node_values           r)   extract_nodes_from_sourcerA   :   s;   K$$g$6KE;;'HHV$D$

++DLL0AQ0Fafchh//FII4L22;

KEu%(YYu%5%:%:1%=%C%C
%j#((SYY2FGG!LL )/9) 
  L! %  L  ;		.xj9:L;s7   AE3 &E3 ,E3 1E3 %E3 ,B E3 .E3 3#FFc                     / n / n/ n[         S-  R                  5        Hv  nUR                  S:X  d  M  UR                  n [        R
                  " SU 3[        S9n[        US/ 5      nUR                  U5        [        R                  " SU S35        Mx     U (       a1  [        R                  " SSR%                  U 5      -   S-   S-   S-   5        X4$ ! [         a    [        R                  " SU 35         M  [         a\    [        R                  " 5       R                  5       S	   nU R!                  S
U SU 35        UR                  [#        U5      5         GM?  f = f)Nr<   z.pyz.nodes.)packager   z	Imported z nodeszSkipping wip module zFailed to import module z	 because zSome nodes failed to load:
	
	z

z4Check that you properly installed the dependencies.
zmIf you think this is a bug, please report it on the github page (https://github.com/melMass/comfy_mtb/issues))r   iterdirsuffixstem	importlibimport_module__package__getattrr7   r   debugAttributeError	Exception	traceback
format_exc
splitlinesappendrA   join)errorsr<   nodes_failedr   module_namemodule_nodeserror_messages           r)   
load_nodesr[   T   sc   FE LG^,,.??e#"--KI"00k]+[ !b9V$		Ik]&9: /0 		,kk&!" FF ~	~	
   + " 		0>? I ) 4 4 6 A A CB G.{m9]OT ##$=h$GHHIs    AC#E9A EEc                  `   [         S-  S-  n U S-  nUR                  5       (       aT  [        [        S5      (       a>   UR	                  5       (       a  UR                  5         g [        R                  " U5        g g g ! [         a'  n[        R                  " SU SU S35         S nAg S nAff = f)Nr
   
extensionsmtbEXTENSION_WEB_DIRSz$Failed to remove web mtb directory: z&
Please manually remove it from disk (z) and restart the server.)r   existshasattrr<   
is_symlinkunlinkshutilrmtreerO   r   warning)web_extensions_rootweb_mtbes      r)   uninstall_old_web_extensionsrj   ~   s    #e+l:!E)G~~GE+?@@		!!## g& A  	KK8 <&&-Y.GK 	s   %A< #A< <
B-B((B-sc                     U R                  SSS5      nSSR                  UR                  S5       Vs/ s H  o"R                  5       PM     sn5      -   $ s  snf )Nnodes-r   r   MTB_-)replacerT   split
capitalize)rk   	wiki_nameparts      r)   wiki_to_classnameru      sQ    		(B*IBGG'0s';<';t	';<  <s   A
c                 H   U R                  SS5      n/ nSn[        S[        U5      5       H?  nX   R                  5       (       d  M  UR	                  XU R                  5       5        UnMA     UR	                  XS  R                  5       5        SSR                  U5      -   $ )Nrn   r   r   r   rm   ro   )rp   ranger0   isupperrS   lowerrT   )rk   	classnamepartsstartis        r)   classname_to_wikir~      s    		&"%IEE1c)n%<!!LL+1134E & 
LL6"((*+chhuo%%    wikir<   z*.mdr   r   
MTB_EXPORT
class_nameDESCRIPTIONzFound linked doc for z
, using itz!Using __doc__ as description for z.mdz5None of the methods could retrieve documentation for z (mtb)znode_list.jsonw   )indentzLoaded the following nodes:
	rE   c              #   |   #    U  H2  u  p[        U5       S U(       a  [        [        U5      5      OS 3v   M4     g7f)z: ro   N)r   r   r   )r'   kdocs      r)   r*   r*      s7      7FA Q<.#9[%563GH7s   :<zloaded z nodes successfulyzSome nodes (z=) could not be loaded. This can be ignored, but go to http://:z"/mtb if you want more information.c                    ^	^
^^^^^^^^^ [         (       d  [        R                  " S5        [         R                  R                  R
                  (       a  [        R                  " S5        g S mS mSS KmSS KmSSK	J
m	  SSKJm
  [        R                  " [        5         SSKJn   U " SSS	9mU " SSS	9mS S S 5        [%        5       m[         R                  R                  R&                  R)                  S
[*        S-  R-                  5       S9  [         R                  R                  R/                  [0        R2                  " S[*        S-  R-                  5       5      /5        [         R                  R4                  R7                  S5      S 5       n[         R                  R4                  R7                  S5      U4S j5       n[         R                  R4                  R9                  S5      S[:        4U4S jj5       n[         R                  R4                  R7                  S5      S[:        4S j5       nS&S[<        4U
UUUU4S jjjmST
R                  4U	4S jjmST
R                  S[<        4U	U
4S jjm S&S[<        4UU4S jjjm[         R                  R4                  R7                  S 5      S[:        4U
UU4S! jj5       n[         R                  R4                  R7                  S5      S[:        4U4S" jj5       n[         R                  R4                  R7                  S#5      S[:        4S$ j5       n[         R                  R4                  R9                  S#5      S[:        4S% j5       ng ! , (       d  f       GN= f)'Nz'No prompt server, are you inside comfy?z`The router is frozen and cannot be further edited.If you are hot reloading mtb this is expected.r   )BytesIO)Image)TTLCached      )maxsizettlz/mtb-assets/html)pathz
/mtb_async	web_asyncz/mtb/managec                 P  #    SSK Jn  [        U5        [        R                  " S5        SU R
                  R                  SS5      ;   aD  UR                  5       nUR                  US9n[        R                  " UR                  SU5      SS	9$ [        R                  " S
S05      $ 7f)Nr   endpointzInitializing Manager	text/htmlAcceptr   )StylesMTBtextcontent_typemessagez"manage only has a POST api for now)r   r   r   r   rM   headersget
csv_editorrender_tab_viewr
   Responserender_base_templatejson_response)requestr   r   tabviews       r)   manageregister_routes.<locals>.manage  s     x+,'//--h;;!,,.J..j.AG<<225'B( 
   ?
 	
s   B$B&z/mtb/statusc                   >#    SSK Jn  [        U5        [        R                  " S5        SU R
                  R                  SS5      ;   a  UR                  [        SS9nX!R                  [         Vs0 s H/  nUTR                  U5      (       a  S	TR                  U5      0OS
_M1     snSS9-  n[        R                  " UR                  SU5      SS9$ [        R                  " [        [        S.5      $ s  snf 7f)Nr   r   z Getting node registration statusr   r   r   
Registered)titledependenciesro   zFailed to loadr   r   )
registeredfailed)r   r   r   r   rM   r   r   render_tabler   r   r
   r   r   r   )r   r   html_responser   node_dependency_mappings       r)   get_full_library)register_routes.<locals>.get_full_library4  s    x78'//--h;;$11) 2 M 22
 $	 $ .22155 '(?(C(CA(FG $	 ' 3  M <<225-H( 
   7 
 	
s   A/C;26C6
(AC;z/mtb/server-infor   c                   >#    U R                  5       I S h  vN nUR                  S5      nU(       aJ  STR                  S'   [        R                  " [
        R                  5        [        R                  " S5        OOSTR                  ;   a?  TR                  R                  S5      n[        R                  " [
        R                  5        [        R                  " SSU(       a  SOS 305      $  N7f)	NrM   r   	MTB_DEBUGz/Debug mode set from API (/mtb/debug POST route)r   zDebug mode setunset)jsonr   environr   setLevelloggingDEBUGrM   popINFOr
   r   )r   	json_dataenabled_oss       r)   set_server_info(register_routes.<locals>.set_server_infoW  s     +2<<>%9	--(&,BJJ{#LL'IIGHBJJ&

{+ALL&  +weG%DEF
 	
 &:s   C3C1CC3z/mtbc                    #    SSK Jn  [        U5      nSU R                  R	                  SS5      ;   a'  Sn[
        R                  " UR                  SU5      SS9$ [
        R                  " S	S
05      $ 7f)Nr   r   r   r   r   z
            <div class="flex-container menu">
                <a href="/mtb/manage">manage</a>
                <a href="/mtb/server-info">Server Info</a>
                <a href="/mtb/status">status</a>
            </div>
            r   r   r   zWelcome to MTB!)	r   r   r   r   r   r
   r   r   r   )r   r   r   r   s       r)   get_home!register_routes.<locals>.get_homei  sq     8'//--h;;M <<225-H(    )->!?@@s   A1A3	file_pathc                 d  > XU4nT(       a  UT;   a  TU   $ TR                  U 5       nUR                  nU(       a  T	" XA5      nU(       a  T" XB5      nT
(       a  UT
U'   T(       a!  UR                  5       TU'   TU   sS S S 5        $ UR                  5       sS S S 5        $ ! , (       d  f       g = fr!   )openinfogetvalue)r   preview_paramschannel	cache_keyimgr   r   	img_cacheprocess_channelprocess_previewprompt_caches         r)   get_cached_image)register_routes.<locals>.get_cached_image  s    8	)y0Y''ZZ	"c88D%c:%c3*.Y''*||~	)$ + #" <<> #""s   AB!B!!
B/r   c                   > Uu  p#n[        U5      nU(       a@  [        U5      nU R                  U[        X@R                  -  U R                  -  5      45        T" 5       nU R	                  XRX0R
                  S9  UR                  S5        U$ )N)formatqualitymetadatar   )int	thumbnailheightwidthsaver   seek)r   r   image_formatr   r   bufferr   s         r)   r   (register_routes.<locals>.process_preview  s{    '5$ug,JEMM5#ejj&8399&D"EFG88 	 	
 	Ar   r   c                   > US:X  aJ  U R                   S:X  a(  U R                  5       u  p#pET	R                  SX#U45      n OU R                  S5      n OuUS:X  ao  U R                   S:X  a  U R                  5       u      pVOT	R	                  SU R
                  S5      nT	R	                  SU R
                  5      n U R                  U5        T" 5       nU R                  USS9  UR                  S	5      nU$ )
NrgbRGBARGBaL   PNG)r   r   )	moderq   mergeconvertnewsizeputalphar   r   )
r   r   rgbr   r   r   r   r   s
           r)   r   (register_routes.<locals>.process_channel  s    exx6! YY[
akk%!3kk%(^xx6! YY[
1aIIc388S1))FCHH-CLLO&KKNr   r   c                    >#    TR                  TXU5      I S h  vN n[        R                  " UU(       a  SOSSSU S30S9$  N)7f)Nz
image/webpz	image/pngzContent-Dispositionz
filename="")r4   r   r   )	to_threadr
   r   )filer   preview_infor   r   asyncior   s        r)   get_image_response+register_routes.<locals>.get_image_response  sW      %%d'
 
 ||)5;*j
!,DE
 	

s   AA*Az	/mtb/viewc                   >#    SS K nU R                  R                  R                  S5      nU(       d  [        R
                  " SS9$ UR                  U5      u  p#US   S:X  d  SU;   a  [        R
                  " SS9$ Uc7  U R                  R                  R                  SS	5      nUR                  U5      nUc  [        R
                  " SS9$ S
U R                  R                  ;   a  TR                  R                  X0R                  R                  S
   5      nTR                  R                  TR                  R                  U5      U45      U:w  a  [        R
                  " SS9$ UnTR                  R                  U5      nTR                  R                  X25      nTR                  R                  U5      (       d  [        R
                  " SS9$ U R                  R                  R                  S5      nU(       a  TR                  U5      nUR                  R                  SS5      n	UR                  R                  SS5      n
U
(       a  [         R"                  " U
5      n
U	(       a  [         R"                  " U	5      n	[        R$                  " U	U
S.5      $ S nSU R                  R                  ;   a  U R                  R                  S   R'                  S5      nUS   S;   a  US   OSn[)        U5      S:  a&  US   R+                  5       (       a  [-        US   5      OSnU R                  R                  R                  S5      nXU4nU R                  R                  R                  S5      nT" XbUU5      I S h  vN $  N7f)Nr   r   i  )status/z..i  typeoutput	subfolderi  workflowpromptr   )r  r  preview;)webpjpegr  r   Z   r   r   )folder_pathsrel_urlqueryr   r
   r   annotated_filepathget_directory_by_typer   rT   
commonpathabspathbasenameisfiler   r   r   loadsr   rq   r0   isdigitr   )r   r  r   
output_dirrtypefull_output_dirr   ret_workflowimager  r  r   r   r   r   r   r   r   r   r   s                    r)   
view_image#register_routes.<locals>.view_image  s    ??((,,Z8<<s+++>>xHA;#!1<<s++OO))--fh?E%;;EBJ<<s++'///// ggllOO11+>O ""WW___5zB 
 ||3//(J77##H-ww||J1ww~~d##<<s++,,00<JJt$EZZ^^Hb1Fzz~~j"5H::h/F+$$$ (  ---$__229=CCCHN "!$(88 q!  ~&*~a/@/H/H/J/J N1%& 
 OO))--g6E(59L//''++I6'gNNNNs   N N
NN
c                   >#    SSK Jn  [        U5      nSTR                  ;   nSTR                  ;   nS[        S[        4S jnSU R
                  R                  S	S
5      ;   aO  S
nXe" SU(       a  SOS5      -  nXe" S[	        U5      5      -  n[        R                  " UR                  SU5      SS9$ [        R                  " XCS.5      $ 7f)Nr   r   r   
MTB_EXPOSEnamevalc                     SU  SU S3$ )Nz<strong>z3:</strong>
                <p>
                    z
                </p> )r"  r#  s     r)   render_property;register_routes.<locals>.get_debug.<locals>.render_property  s"    v &E  r   r   r   r   DebugEnabledDisabledExposedzServer Infor   )exposedrM   )r   r   r   r   r%   r   r   r
   r   r   r   )r   r   r   isdebugr,  r&  r   r   s          r)   	get_debug"register_routes.<locals>.get_debug  s     8+"**,	# 	C 	 '//--h;;M_g: M _YGEEM<<22!= )	    W!GHHs   CCz/mtb/actionsc                    #    SSK Jn  SU R                  R                  SS5      ;   a'  Sn[        R
                  " UR                  SU5      SS9$ [        R                  " S	S
05      $ 7f)Nr   r   r   r   r   z@
            <h1>Actions has no get for now...</h1>
            Actionsr   r   zactions has no get for now)r   r   r   r   r
   r   r   r   )r   r   r   s      r)   no_route!register_routes.<locals>.no_route5  sg     '//--h;;M <<229mL(    )-I!JKKs   A&A(c                 b   #    SSK Jn  [        U5        UR                  U 5      I S h  vN $  N7f)Nr   r   )r   r   r   	do_action)r   r   s     r)   r5  "register_routes.<locals>.do_actionC  s'     x''0000s   &/-/)NN)r   r   r:   instanceappfrozenrf   r   r   ior   PILr   
contextlibsuppressImportError
cachetoolsr   r   router
add_staticr   as_posix
add_routesr
   staticroutesr   postr   r%   )r   r   r   r   r   r  r.  r2  r5  r   r   r   r   r   r   r   r   r   r   r   s            @@@@@@@@@@@r)   register_routesrG     s   <		;<  ''=	
 	IL			[	)'Sa0	3	 
* 45$$//dVm557 0  ((	L4+#5"?"?"A	BC !!%%m4
 5
* !!%%m4 
 5 
D !!&&'9:
w 
 ;
" !!%%f-A A .A,"C " "&U[[ U[[ 3  * 9=



 

 !!%%k2KO' KO KO 3KOZ !!%%&89 I  I : ID !!%%n5L L 6L !!&&~61 1 71q	 
*	)s   M--
M<r7  z	MTB Nodes)r   r   r   zMel Massadianz$https://github.com/melMass/comfy_mtba|  Set of nodes that enhance your animation workflow and provide a range of useful tools including features such as manipulating bounding boxes, perform color corrections, swap faces in images, interpolate frames for smooth animation, export to ProRes format, apply various image operations, work with latent spaces, generate QR codes, and create normal and height maps for textures.)r"  versionauthorprojectdescription)V__version__r   aiohttp.web_requestr   r   r   r#   r<  rI   r   r   rd   rP   r   pathlibr	   aiohttpr
   IN_COMFYr   serverModuleNotFoundErrorr   r   installr   r   r   r   r   r   utilsr   r   r   dictr%   r  __annotations__r   r   WEB_DIRECTORYrA   r[   rj   ru   r~   r   	node_docsr`   is_dirglobrH   r,   r   r<   r   
node_class__name__r   
linked_docra   rM   r   __doc__rs   
write_textr   
node_labelr   fwritedumpssortedkeysrT   itemsr   r0   r=  rO   get_server_infobase_urlportrG  MANIFEST)xr   s   00r)   <module>rl     sn   g 	 ' 
zz~~122.4BJJ*+	zz~~())%8BJJ!" 
         #H
  * B B "') T#t)_ )-/ DcN /35 4S4Z0 5 4&!T* 	& 	& f}	;;==T[[]] .&&v..A 	!&&!1;;;#@@.I ZZ^^L)
vJ ))J)z*J:}--II-j\DE%/J"II9*FG%/%7%7J"-j9	G^y5'89EE&& F 
 IIG
|T j)*&1J&0
#-7z*,6,>,>j) 
zz~~l##$))3/1

 "((A(F(F(H!I!IA 4Q77!I A 0/C X 		%kk /557  79SU_-..@	A B				Y	'..0$3v;-'demdnnoptou  vX  Y	
 			& 
(Q1h
 j11
 5 RM  H|\ 0/, 
(	'sC   P *P+0P5P0
P5$AQP('P(0P55
Q	
Q