
    +j>                        d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z	m
Z
mZmZmZmZ d dlmZmZmZmZmZmZ dZdZdddd	d
eej                 dedededeej                 deej                 dee         dej        fdZ G d dej                  Z G d dej                  Z  G d dej                  Z! G d dej                  Z" G d de          Z#de#fdZ$dS )    )OptionalN)override)IOComfyExtension)MinimaxFileRetrieveResponseMiniMaxModelMinimaxTaskResultResponseMinimaxVideoGenerationRequestMinimaxVideoGenerationResponseSubjectReferenceItem)ApiEndpointdownload_url_to_video_outputpoll_opsync_opupload_images_to_comfyapivalidate_stringr      )imagesubjectaverage_durationclsprompt_textseedmodelr   r   r   returnc                ^  K   |t          |d           d }|t          | |d           d {V d         }d }|/t          | |d           d {V d         }	t          |	          g}t          | t	          dd	          t
          t          t          |          |d ||d 
                     d {V }
|
j        }|st          d|
j
                   t          | t	          dd|i          t          d |           d {V }|j        }|t          d          t          | t	          ddt          |          i          t                     d {V }|j        j        }|$t          d|                                           |j        j        rn	 t)          j        t-          |dd           d {V           S # t          $ r6 t)          j        t-          |j        j        d           d {V           cY S w xY wt)          j        t-          |           d {V           S )Nr   
field_name   
max_imagesr   )r   /proxy/minimax/video_generationPOSTpathmethod)r   promptcallback_urlfirst_frame_imagesubject_referenceprompt_optimizerresponse_modeldataMiniMax generation failed: %/proxy/minimax/query/video_generationtask_idr&   query_paramsc                     | j         j        S Nstatusvaluexs    =/home/wildlama/comfy/ComfyUI/comfy_api_nodes/nodes_minimax.py<lambda>z$_generate_mm_video.<locals>.<lambda>H   s
    18>     r.   status_extractorestimated_duration,Request was not successful. Missing file ID./proxy/minimax/files/retrievefile_idr.   3No video was found in the response. Full response: 
      timeoutmax_retries   rK   )r   r   r   r   r   r   r
   r   r2   	Exception	base_respr   r	   rD   intr   filedownload_url
model_dumpbackup_download_urlr   
NodeOutputr   )r   r   r   r   r   r   r   	image_urlr+   subject_urlresponser2   task_resultrD   file_resultfile_urls                   r<   _generate_mm_videor\      s#      }>>>>I4S%ANNNNNNNNNPQR	 6sGPQRRRRRRRRRTUV1DDDE:6JJJ5*u%%'/!
 
 
	        H G LJh6HJJKKK@PY[bOcddd011+        K !GFGGG8	SVW^S_S_G`aaa2        K ,HhkNdNdNfNfhhiii+ 	='CHVXfg'h'h'h!h!h!h!h!h!hiii 	 	 	=2;3C3Wefggggggggg    	 =;HEEEEEEEEFFFs   )G =HHc            
       l    e Zd Zedej        fd            Ze	 	 d
dedededej	        fd            Z
d	S )MinimaxTextToVideoNoder   c                    t          j        ddddt           j                            dddd	          t           j                            d
ddgdd          t           j                            dddddddd          gt           j                                        gt           j        j	        t           j        j
        t           j        j        gdt          j        d          	  	        S )Nr^   zMiniMax Text to Videopartner/video/MiniMaxzJGenerates videos synchronously based on a prompt, and optional parameters.r   T )Text prompt to guide the video generation	multilinedefaulttooltipr   T2V-01zT2V-01-Director!Model to use for video generationoptionsre   rf   r   r       r    ,The random seed used for creating the noise.re   minmaxstepcontrol_after_generaterf   optional{"type":"usd","usd":0.43}expr	node_iddisplay_namecategorydescriptioninputsoutputshiddenis_api_nodeprice_badge)r   SchemaStringInputComboIntVideoOutputHiddenauth_token_comfy_orgapi_key_comfy_org	unique_id
PriceBadger   s    r<   define_schemaz$MinimaxTextToVideoNode.define_schemac   s    y,0,d	!"G	     %'89$?	    *+/J!  	 	0 X__&&'	.	+	#
 4  I'
 '
 '
 '	
r>   rg   r   r   r   r   c           	      H   K   t          | |||d d t                     d {V S N)r   r   r   r   r   r   r\   T2V_AVERAGE_DURATION)r   r   r   r   s       r<   executezMinimaxTextToVideoNode.execute   sR       (#1
 
 
 
 
 
 
 
 
 	
r>   N)rg   r   )__name__
__module____qualname__classmethodr   r   r   strrP   rU   r    r>   r<   r^   r^   b   s        (
bi (
 (
 (
 [(
T  	
 

 
 	

 

 
 
 [
 
 
r>   r^   c                   z    e Zd Zedej        fd            Ze	 	 ddej        de	de	de
dej        f
d	            Zd
S )MinimaxImageToVideoNoder   c                    t          j        ddddt           j                            dd          t           j                            dd	d
d          t           j                            dg ddd          t           j                            dddddd	dd	          gt           j                                        gt           j	        j
        t           j	        j        t           j	        j        gd	t          j        d          	  	        S )Nr   zMiniMax Image to Videor`   UGenerates videos synchronously based on an image and prompt, and optional parameters.r   z/Image to use as first frame of video generationrf   r   Tra   rb   rc   r   )zI2V-01-DirectorI2V-01zI2V-01-liver   rh   ri   r   r   rk   r    rl   rm   rs   rt   rv   )r   r   Imager   r   r   r   r   r   r   r   r   r   r   r   s    r<   r   z%MinimaxImageToVideoNode.define_schema   s   y-1,oM    	!"G	     HHH$?	    *+/J!  	 	#8 X__&&'	.	+	#
 4  Q+
 +
 +
 +	
r>   r   r   r   r   r   r   c           	      H   K   t          | ||||d t                     d {V S r   )r\   I2V_AVERAGE_DURATION)r   r   r   r   r   s        r<   r   zMinimaxImageToVideoNode.execute   sR       (#1
 
 
 
 
 
 
 
 
 	
r>   N)r   r   r   r   r   r   r   r   r   torchTensorr   rP   rU   r   r   r>   r<   r   r      s        ,
bi ,
 ,
 ,
 [,
\ 
 
 
|
 
 	

 
 

 
 
 [
 
 
r>   r   c                   z    e Zd Zedej        fd            Ze	 	 ddej        de	de	de
dej        f
d	            Zd
S )MinimaxSubjectToVideoNoder   c                    t          j        ddddt           j                            dd          t           j                            dd	d
d          t           j                            ddgdd          t           j                            dddddd	dd	          gt           j                                        gt           j	        j
        t           j	        j        t           j	        j        gd	          S )Nr   zMiniMax Subject to Videor`   r   r   z2Image of subject to reference for video generationr   r   Tra   rb   rc   r   S2V-01rh   ri   r   r   rk   r    rl   rm   )rw   rx   ry   rz   r{   r|   r}   r~   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   s    r<   r   z'MinimaxSubjectToVideoNode.define_schema   s   y/3,oP    	!"G	     %J$?	    *+/J!  	 	#8 X__&&'	.	+	#
 O(
 (
 (
 (	
r>   r   r   r   r   r   r   c           	      H   K   t          | |||d |t                     d {V S r   r   )r   r   r   r   r   s        r<   r   z!MinimaxSubjectToVideoNode.execute  sR       (#1
 
 
 
 
 
 
 
 
 	
r>   N)r   r   r   r   r>   r<   r   r      s        )
bi )
 )
 )
 [)
V 
 
 

 
 	

 
 

 
 
 [
 
 
r>   r   c                       e Zd Zedej        fd            Ze	 	 	 	 	 	 dd	ed
ede	e
j                 dededededej        fd            ZdS )MinimaxHailuoVideoNoder   c                    t          j        ddddt           j                            dddd	          t           j                            d
ddddddd          t           j                            ddd          t           j                            dddd          t           j                            dddgddd          t           j                            dddgddd          gt           j        	                                gt           j
        j        t           j
        j        t           j
        j        gdt          j        t          j        ddg          d !          "	  	        S )#Nr   zMiniMax Hailuo Videor`   z^Generates videos from prompt, with optional start frame using the new MiniMax Hailuo-02 model.r   Tra   z*Text prompt to guide the video generation.rc   r   r   rk   r    rl   rm   r*   z=Optional image to use as the first frame to generate a video.)rf   rr   r,   z:Optimize prompt to improve generation quality when needed.)re   rf   rr   duration   rG   z*The length of the output video in seconds.)rj   re   rf   rr   
resolution768P1080PzJThe dimensions of the video display. 1080p is 1920x1080, 768p is 1366x768.)widgetsa  
                (
                  $prices := {
                    "768p": {"6": 0.28, "10": 0.56},
                    "1080p": {"6": 0.49}
                  };
                  $resPrices := $lookup($prices, $lowercase(widgets.resolution));
                  $price := $lookup($resPrices, $string(widgets.duration));
                  {"type":"usd","usd": $price ? $price : 0.43}
                )
                )
depends_onru   rv   )r   r   r   r   r   r   Booleanr   r   r   r   r   r   r   r   PriceBadgeDependsr   s    r<   r   z$MinimaxHailuoVideoNode.define_schema$  s   y,/,x	!"H	     *+/J!  	 	 '[!   
 
  & X!	 !   GH!     #W-"h!   G*V X__&&'	.	+	#
 /z8RSSS
  oE
 E
 E
 E	
r>   r   NTr   r   MiniMax-Hailuo-02r   r   r*   r,   r   r   r   c                 t  K   |t          |d           |dk    r-|                                dk    r|dk    rt          d          d }|t          | |d           d {V d	         }t	          | t          d
d          t          t          t          |          |d ||||                     d {V }	|	j	        }
|
st          d|	j
                   |dk    rdnd}t          | t          dd|
i          t          d |           d {V }|j        }|t          d          t	          | t          ddt          |          i          t                     d {V }|j        j        }|$t          d|                                           |j        j        rn	 t)          j        t-          |dd           d {V           S # t          $ r6 t)          j        t-          |j        j        d !           d {V           cY S w xY wt)          j        t-          |           d {V           S )"Nr   r   r   r   r   zZWhen model is MiniMax-Hailuo-02 and resolution is 1080P, duration is limited to 6 seconds.r    r!   r   r#   r$   r%   )r   r(   r)   r*   r,   r   r   r-   r0   r   x      r1   r2   r3   c                     | j         j        S r6   r7   r:   s    r<   r=   z0MinimaxHailuoVideoNode.execute.<locals>.<lambda>  s
    qx~ r>   r?   rB   rC   rD   rE   rF   rG   rH   rI   rL   rM   )r   upperrN   r   r   r   r   r
   r   r2   rO   r   r	   rD   rP   r   rQ   rR   rS   rT   r   rU   r   )r   r   r   r*   r,   r   r   r   rV   rX   r2   r   rY   rD   rZ   r[   s                   r<   r   zMinimaxHailuoVideoNode.executem  s1      $KMBBBB'''J,<,<,>,>',I,IhZ[mml  
 	(8>O\]^^^^^^^^^`abI >vNNN9."5))"!"+!1!%  	
 
 
 
 
 
 
 
 
 " 	PN(:LNNOOO","6"633C#DT]_fSghhh455/
 
 
 
 
 
 
 
 
 %?JKKK#<IWZ[bWcWcKdeee6
 
 
 
 
 
 
 
 
 #0lR]RhRhRjRjllmmm/ 	}+GZ\jk+l+l+l%l%l%l%l%l%lmmm   }6{7G7[ijkkkkkkkkk     }#?#I#IIIIIIIJJJs   &)G =HH)r   NTr   r   r   )r   r   r   r   r   r   r   r   rP   r   r   r   boolrU   r   r   r>   r<   r   r   #  s        F
bi F
 F
 F
 [F
P  48!% (GK GKGK GK $EL1	GK
 GK GK GK GK 
GK GK GK [GK GK GKr>   r   c                   L    e Zd Zedeeej                          fd            ZdS )MinimaxExtensionr   c                 .   K   t           t          t          gS r6   )r^   r   r   )selfs    r<   get_node_listzMinimaxExtension.get_node_list  s       ##"	
 	
r>   N)	r   r   r   r   listtyper   	ComfyNoder   r   r>   r<   r   r     sE        
T$r|*<%= 
 
 
 X
 
 
r>   r   c                  "   K   t                      S r6   )r   r   r>   r<   comfy_entrypointr     s      r>   )%typingr   r   typing_extensionsr   comfy_api.latestr   r   comfy_api_nodes.apis.minimaxr   r   r	   r
   r   r   comfy_api_nodes.utilr   r   r   r   r   r   r   r   r   r   r   rP   r   rU   r\   r^   r   r   r   r   r   r   r>   r<   <module>r      s          & & & & & & / / / / / / / /                                  %)&*&*CG CG CG	bl	CG CG 	CG
 CG EL!CG el#CG smCG ]CG CG CG CGL;
 ;
 ;
 ;
 ;
R\ ;
 ;
 ;
|@
 @
 @
 @
 @
bl @
 @
 @
F=
 =
 =
 =
 =
 =
 =
 =
@RK RK RK RK RKR\ RK RK RKj
 
 
 
 
~ 
 
 
 0      r>   