
    +j_[                    J   d dl Z d dlmZ d dlmZmZmZ d dlmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ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,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4  e j5        d          Z6 G d dej7                  Z8 G d	 d
ej7                  Z9 G d dej7                  Z: G d dej7                  Z; G d dej7                  Z< G d dej7                  Z= G d dej7                  Z> G d dej7                  Z? G d dej7                  Z@ G d dej7                  ZA G d dej7                  ZB G d dej7                  ZC G d d ej7                  ZD G d! d"ej7                  ZE G d# d$e          ZFd%eFfd&ZGdS )'    N)override)IOComfyExtensionInput)Image2ImageInputFieldImage2ImageParametersFieldImage2ImageTaskCreationRequestImage2VideoInputFieldImage2VideoParametersFieldImage2VideoTaskCreationRequestImageTaskStatusResponseReference2VideoInputFieldReference2VideoParametersField"Reference2VideoTaskCreationRequestTaskCreationResponseText2ImageInputFieldText2ImageTaskCreationRequestText2VideoInputFieldText2VideoParametersFieldText2VideoTaskCreationRequestTxt2ImageParametersFieldVideoTaskStatusResponseWan27ImageToVideoInputField Wan27ImageToVideoParametersField$Wan27ImageToVideoTaskCreationRequestWan27MediaItemWan27ReferenceVideoInputField"Wan27ReferenceVideoParametersField&Wan27ReferenceVideoTaskCreationRequestWan27Text2VideoParametersField"Wan27Text2VideoTaskCreationRequestWan27VideoEditInputFieldWan27VideoEditParametersField!Wan27VideoEditTaskCreationRequest)ApiEndpointaudio_to_base64_stringdownload_url_to_image_tensordownload_url_to_video_outputget_number_of_imagespoll_opsync_optensor_to_base64_stringupload_audio_to_comfyapiupload_image_to_comfyapiupload_video_to_comfyapivalidate_audio_durationvalidate_stringvalidate_video_durationu   \((\d+)\s*[x×]\s*(\d+)\)c                   j    e Zd Zed             Ze	 	 	 	 	 	 ddeded	ed
ededededefd            ZdS )WanTextToImageApic                 R   t          j        ddddt           j                            ddgd          t           j                            d	d
dd          t           j                            dd
ddd
          t           j                            dddddd
          t           j                            dddddd
          t           j                            dddddt           j        j        d
dd
	  	        t           j                            dd
dd
d
           t           j                            d!d"d#d
d
           gt           j	        
                                gt           j        j        t           j        j        t           j        j        gd
t          j        d$%          &	  	        S )'Nr4   zWan Text to Imagepartner/image/Wanz*Generates an image based on a text prompt.modelzwan2.5-t2i-previewModel to use.optionstooltippromptT QPrompt describing the elements and visual features. Supports English and Chinese.	multilinedefaultr;   negative_prompt)Negative prompt describing what to avoid.r@   rA   r;   optionalwidth   i   i      )rA   minmaxsteprE   heightseedr      Seed to use for generation.rA   rI   rJ   rK   display_modecontrol_after_generater;   rE   prompt_extend1Whether to enhance the prompt with AI assistance.rA   r;   rE   advanced	watermarkF7Whether to add an AI-generated watermark to the result.{"type":"usd","usd":0.03}expr	node_iddisplay_namecategorydescriptioninputsoutputshiddenis_api_nodeprice_badge)r   SchemaCombor   StringIntNumberDisplaynumberBooleanImageOutputHiddenauth_token_comfy_orgapi_key_comfy_org	unique_id
PriceBadgeclss    9/home/wildlama/comfy/ComfyUI/comfy_api_nodes/nodes_wan.pydefine_schemazWanTextToImageApi.define_schema;   s   y',(D12+   
 	"o	     	%"G!      !     !    "!#!1!8+/9!  
 
 
  # O!! !   
  !U!! !  k<| !! 	.	+	#
 4  WN
 N
 N
 N	
    r=   rG   r   TFr7   r<   rB   rF   rL   rM   rT   rX   c	                    K   t          | t          dd          t          t          |t	          ||          t          | d| |||                               d {V }	|	j        st          d	|	j         d
|	j	                   t          | t          d|	j        j                   t          d dd           d {V }
t          j        t          t!          |
j        j        d         j                             d {V           S )Nz:/proxy/wan/api/v1/services/aigc/text2image/image-synthesisPOSTpathmethodr<   rB   *)sizerM   rT   rX   r7   input
parametersresponse_modeldataAn unknown error occurred:  - /proxy/wan/api/v1/tasks/r}   c                     | j         j        S Noutputtask_statusxs    rw   <lambda>z+WanTextToImageApi.execute.<locals>.<lambda>       qx'; ry   	      r   status_extractorestimated_durationpoll_intervalr   )r+   r%   r   r   r   r   r   	Exceptioncodemessager*   task_idr   r   
NodeOutputr'   strresultsurl)rv   r7   r<   rB   rF   rL   rM   rT   rX   initial_responseresponses              rw   executezWanTextToImageApi.execute   s~      ")Ybhiii/.*&/ZZZ3!,,F,,"/'	  	 	 		"
 "
 "
 
 
 
 
 
 
  & 	pn:J:OnnTdTlnnooo Y8H8O8WYYZZZ2;; 
 
 
 
 
 
 
 
 
 }#?HOD[\]D^Db@c@c#d#dddddddeeery   N)r=   rG   rG   r   TF)	__name__
__module____qualname__classmethodrx   r   intboolr    ry   rw   r4   r4   :   s        O
 O
 [O
b 
  ""$f $f$f $f 	$f
 $f $f $f $f $f $f $f [$f $f $fry   r4   c                   f    e Zd Zed             Ze	 	 	 ddedej        deded	ed
e	fd            Z
dS )WanImageToImageApic                    t          j        ddddt           j                            ddgdd          t           j                            d	d
          t           j                            dddd          t           j                            ddddd          t           j                            dddddt           j        j        ddd	  	        t           j	                            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Wan Image to Imager6   zGenerates an image from one or two input images and a text prompt. The output image is currently fixed at 1.6 MP, and its aspect ratio matches the input image(s).r7   zwan2.5-i2i-previewr8   r:   rA   r;   imagez=Single-image editing or multi-image fusion. Maximum 2 images.r;   r<   Tr=   r>   r?   rB   rC   rD   rM   r   rN   rO   rP   rQ   rX   FrY   rV   rZ   r[   r]   )r   rg   rh   r   rn   ri   rj   rk   rl   rm   ro   rp   rq   rr   rs   rt   ru   s    rw   rx   z WanImageToImageApi.define_schema   s   y(-(n 120+	    [    	"o	     	%"G!    0 "!#!1!8+/9!  
 
 
  !U!! !  i;z !! 	.	+	#
 4  WN
 N
 N
 N	
ry   r=   r   Fr7   r   r<   rB   rM   rX   c                   K   t          |          }|dvrt          d| d          g }|D ])}	|                    dt          |	d          z              *t	          | t          dd	          t          t          |t          |||
          t          ||                               d {V }
|
j
        st          d|
j         d|
j                   t          | t          d|
j
        j                   t           d dd           d {V }t#          j        t'          t)          |j
        j        d         j                             d {V           S )N)rO      z&Expected 1 or 2 input images, but got .data:image/png;base64,i   total_pixelsz;/proxy/wan/api/v1/services/aigc/image2image/image-synthesisr{   r|   )r<   rB   images)rM   rX   r   r   r   r   r   r   c                     | j         j        S r   r   r   s    rw   r   z,WanImageToImageApi.execute.<locals>.<lambda>.  r   ry   *      r   r   )r)   
ValueErrorappendr,   r+   r%   r   r	   r   r   r   r   r   r   r*   r   r   r   r   r'   r   r   r   )rv   r7   r   r<   rB   rM   rX   n_imagesr   ir   r   s               rw   r   zWanImageToImageApi.execute  s      (..6!!QhQQQRRR 	k 	kAMM25LQ]h5i5i5iijjjj!(Zcijjj//+6?cijjj5'    	"
 "
 "
 
 
 
 
 
 
  & 	pn:J:OnnTdTlnnooo Y8H8O8WYYZZZ2;;!
 
 
 
 
 
 
 
 
 }#?HOD[\]D^Db@c@c#d#dddddddeeery   N)r=   r   F)r   r   r   r   rx   r   r   rn   r   r   r   r   ry   rw   r   r      s        O
 O
 [O
b   " )f )f)f {)f 	)f
 )f )f )f )f )f [)f )f )fry   r   c                       e Zd Zed             Ze	 	 	 	 	 	 	 	 	 dd
edededededej        dz  dede	de	de	defd            Z
dS )WanTextToVideoApic                 v   t          j        ddddt           j                            dddgdd	          t           j                            d
ddd          t           j                            ddddd          t           j                            dg ddd          t           j                            dddddt           j        j        dd          t           j                            ddd          t           j                            dddd d!t           j        j        dd"d#	  	        t           j	                            d$d%dd&d'          t           j	                            d(dd)dd*          t           j	                            d+d%d,dd*          t           j                            d-d.d/gd0dd1          gt           j
                                        gt           j        j        t           j        j        t           j        j        gdt          j        t          j        ddg2          d34          5	  	        S )6Nr   zWan Text to Videopartner/video/Wanz)Generates a video based on a text prompt.r7   wan2.5-t2v-preview
wan2.6-t2vr8   r   r<   Tr=   r>   r?   rB   rC   rD   r   )z480p: 1:1 (624x624)z480p: 16:9 (832x480)z480p: 9:16 (480x832)720p: 1:1 (960x960)720p: 16:9 (1280x720)720p: 9:16 (720x1280)720p: 4:3 (1088x832)720p: 3:4 (832x1088)1080p: 1:1 (1440x1440)1080p: 16:9 (1920x1080)1080p: 9:16 (1080x1920)1080p: 4:3 (1632x1248)1080p: 3:4 (1248x1632)r   r:   rA   rE   duration      z=A 15-second duration is available only for the Wan 2.6 model.rA   rI   rJ   rK   rR   r;   rE   audioUAudio must contain a clear, loud voice, without extraneous noise or background music.rE   r;   rM   r   rN   rO   rP   rQ   generate_audioF<If no audio input is provided, generate audio automatically.rA   rE   r;   rW   rT   rU   rV   rX   rY   	shot_typesinglemultiSpecifies the shot type for the generated video, that is, whether the video is a single continuous shot or multiple shots with cuts. This parameter takes effect only when prompt_extend is True.r:   r;   rE   rW   widgetsaJ  
                (
                  $ppsTable := { "480p": 0.05, "720p": 0.1, "1080p": 0.15 };
                  $resKey := $substringBefore(widgets.size, ":");
                  $pps := $lookup($ppsTable, $resKey);
                  { "type": "usd", "usd": $round($pps * widgets.duration, 2) }
                )
                
depends_onr\   r]   )r   rg   rh   r   ri   rj   rk   rl   Audiorm   Videoro   rp   rq   rr   rs   rt   PriceBadgeDependsru   s    rw   rx   zWanTextToVideoApi.define_schema6  s   y',(C1<@(+	    	"o	     	%"G!        2!%   ( !#!1!8[!  	 	 !s   
 "!#!1!8+/9!  
 
 
  $!!Z! !   
  # O!! !   
  !U!! !   %w/S "!   o`D !! 	.	+	#
 /V8LMMM
 
 
_z
 z
 z
 z	
ry   r=   r   r   Nr   FTr   r7   r<   rB   r   r   r   rM   r   rT   rX   r   c                 6  K   d|v r|dk    rt          d          |dk    r|dk    rt          d          t                              |                                          \  }}d }|%t	          |dd           d	t          |d
d          z   }t          | t          dd          t          t          |t          |||          t          | d| ||||	|
|                               d {V }|j        st          d|j         d|j                   t!          | t          d|j        j                   t$          d dt'          |dz            z  d           d {V }t)          j        t-          |j        j                   d {V           S )N480pr   z(The Wan 2.6 model does not support 480p.r   r   <A 15-second duration is supported only by the Wan 2.6 model.      @      =@data:audio/mp3;base64,mp3
libmp3lame@/proxy/wan/api/v1/services/aigc/video-generation/video-synthesisr{   r|   r<   rB   	audio_urlr   )r   r   rM   r   rT   rX   r   r   r   r   r   r   r   c                     | j         j        S r   r   r   s    rw   r   z+WanTextToVideoApi.execute.<locals>.<lambda>  r   ry   x   r      r   )r   RES_IN_PARENSsearchgroupsr0   r&   r+   r%   r   r   r   r   r   r   r   r   r*   r   r   r   r   r   r(   	video_url)rv   r7   r<   rB   r   r   r   rM   r   rT   rX   r   rF   rL   r   r   r   s                    rw   r   zWanTextToVideoApi.execute  s(      T>>e|33GHHHr>>e';;;[\\\%,,T2299;;v	#E355503I%QVXd3e3eeI!(_hnooo/.*&/enooo4!,,F,,%("/''    	"
 "
 "
 
 
 
 
 
 
$  & 	pn:J:OnnTdTlnnooo Y8H8O8WYYZZZ2;;"SA%6%66
 
 
 
 
 
 
 
 
 }#?@Y#Z#ZZZZZZZ[[[ry   )	r=   r   r   Nr   FTFr   )r   r   r   r   rx   r   r   r   r   r   r   r   ry   rw   r   r   5  s        {
 {
 [{
z 
  ")$($"!4\ 4\4\ 4\ 	4\
 4\ 4\ {T!4\ 4\ 4\ 4\ 4\ 4\ 4\ 4\ [4\ 4\ 4\ry   r   c                       e Zd Zed             Ze	 	 	 	 	 	 	 	 	 dd
edej        dededededej	        dz  dede
de
de
defd            ZdS )WanImageToVideoApic                    t          j        ddddt           j                            dddgdd	          t           j                            d
          t           j                            dddd          t           j                            ddddd          t           j                            dg ddd          t           j                            dddddt           j        j        dd          t           j	                            ddd          t           j                            dd d d!d"t           j        j        dd#d$	  	        t           j
                            d%d&dd'd(          t           j
                            d)dd*dd+          t           j
                            d,d&d-dd+          t           j                            d.d/d0gd1dd2          gt           j                                        gt           j        j        t           j        j        t           j        j        gdt          j        t          j        ddg3          d45          6	  	        S )7Nr   zWan Image to Videor   z9Generates a video from the first frame and a text prompt.r7   wan2.5-i2v-preview
wan2.6-i2vr8   r   r   r<   Tr=   r>   r?   rB   rC   rD   
resolution)480P720P1080Pr  r   r   r   r   z,Duration 15 available only for WAN2.6 model.r   r   r   r   rM   r   rN   rO   rP   rQ   r   Fr   r   rT   rU   rV   rX   rY   r   r   r   r   r   r   a  
                (
                  $ppsTable := { "480p": 0.05, "720p": 0.1, "1080p": 0.15 };
                  $pps := $lookup($ppsTable, widgets.resolution);
                  { "type": "usd", "usd": $round($pps * widgets.duration, 2) }
                )
                r   r]   )r   rg   rh   r   rn   ri   rj   rk   rl   r   rm   r   ro   rp   rq   rr   rs   rt   r   ru   s    rw   rx   z WanImageToVideoApi.define_schema  s   y(-(S1<@(+	      	"o	     	%"G!        
 #!  	 	 !#!1!8J!  	 	 !s   
 "!#!1!8+/9!  
 
 
  $!!Z! !   
  # O!! !   
  !U!! !   %w/S "!   aYv !! 	.	+	#
 /\8RSSS	 	 	Qr
 r
 r
 r	
ry   r=   r  r   Nr   FTr   r7   r   r<   rB   r   r   r   rM   r   rT   rX   r   c                 <  K   t          |          dk    rt          d          d|v r|dk    rt          d          |dk    r|dk    rt          d          d	t          |d
          z   }d }|%t          |dd           dt	          |dd          z   }t          | t          dd          t          t          |t          ||||          t          ||||	|
||                               d {V }|j        st          d|j         d|j                   t          | t          d|j        j                   t"          d dt%          |dz            z  d            d {V }t'          j        t+          |j        j                   d {V           S )!NrO   z$Exactly one input image is required.r   r   z(The Wan 2.6 model does not support 480P.r   r   r   r   i 	= r   r   r   r   r   r   r   r{   r|   )r<   rB   img_urlr   )r   r   rM   r   rT   rX   r   r   r   r   r   r   r   c                     | j         j        S r   r   r   s    rw   r   z,WanImageToVideoApi.execute.<locals>.<lambda>  r   ry   r   r   r   r   )r)   r   r,   r0   r&   r+   r%   r   r   r
   r   r   r   r   r   r*   r   r   r   r   r   r(   r   )rv   r7   r   r<   rB   r   r   r   rM   r   rT   rX   r   	image_urlr   r   r   s                    rw   r   zWanImageToVideoApi.executec  s?        &&!++CDDDZE\$9$9GHHHr>>e';;;[\\\,/Fu[f/g/g/gg		#E355503I%QVXd3e3eeI!(_hnooo//+!?Iaj   6)%("/''    	"
 "
 "
 
 
 
 
 
 
(  & 	pn:J:OnnTdTlnnooo Y8H8O8WYYZZZ2;;"SA%6%66
 
 
 
 
 
 
 
 
 }#?@Y#Z#ZZZZZZZ[[[ry   )	r=   r  r   Nr   FTFr   )r   r   r   r   rx   r   r   rn   r   r   r   r   r   ry   rw   r   r     s       s
 s
 [s
j   " $($"!8\ 8\8\ {8\ 	8\
 8\ 8\ 8\ {T!8\ 8\ 8\ 8\ 8\ 8\ 8\ 8\ [8\ 8\ 8\ry   r   c                   t    e Zd Zed             Zededededej        j        dede	de	d	ed
e
fd            ZdS )WanReferenceVideoApic                 N   t          j        ddddt           j                            ddg          t           j                            dd	d
d          t           j                            dd	d
d          t           j                            dt           j                            t           j                            d          g dd                    t           j                            dg d          t           j                            dddddt           j	        j
                  t           j                            dddddt           j	        j        d	          t           j                            dd d!gd"d	#          t           j                            d$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Wan Reference to Videor   zUse the character and voice from input videos, combined with a prompt, to generate a new video that maintains character consistency.r7   z
wan2.6-r2vr:   r<   Tr=   zPrompt describing the elements and visual features. Supports English and Chinese. Use identifiers such as `character1` and `character2` to refer to the reference characters.r?   rB   rC   reference_videosreference_video)
character1
character2
character3rO   namesrI   templater   )
r   r   r   r   r   r   r   r   r   r   r   r   
   rA   rI   rJ   rK   rR   rM   r   rN   )rA   rI   rJ   rK   rR   rS   r   r   r   zSpecifies the shot type for the generated video, that is, whether the video is a single continuous shot or multiple shots with cuts.)r:   r;   rW   rX   FrY   rA   r;   rW   r   a  
                (
                  $rate := $contains(widgets.size, "1080p") ? 0.15 : 0.10;
                  $inputMin := 2 * $rate;
                  $inputMax := 5 * $rate;
                  $outputPrice := widgets.duration * $rate;
                  {
                    "type": "range_usd",
                    "min_usd": $inputMin + $outputPrice,
                    "max_usd": $inputMax + $outputPrice
                  }
                )
                r   r]   )r   rg   rh   r   ri   AutogrowTemplateNamesr   rj   rk   sliderrl   rm   ro   rp   rq   rr   rs   rt   r   ru   s    rw   rx   z"WanReferenceVideoApi.define_schema  sF   y*1(L w??	"r	     	%"G	     !!&[66'899HHH 7   "         !#!1!8    "!#!1!8+/    %w/J!    
  !U!	 !  }DL !! 	.	+	#
 /8LMMM  id
 d
 d
 d	
ry   r7   r<   rB   r  r   r   rM   r   rX   c
                   K   g }
|D ]}t          ||         dd           |D ]1}|
                    t          | ||                    d {V            2t                              |                                          \  }}t          | t          dd          t          t          |t          |||
          t          | d| |||	|	          
                     d {V }|j        st          d|j         d|j                   t!          | t          d|j        j                   t$          d d           d {V }t'          j        t+          |j        j                   d {V           S )Nr      min_durationmax_durationr   r{   r|   )r<   rB   reference_video_urlsr   )r   r   r   rX   rM   r   r   r   r   r   r   c                     | j         j        S r   r   r   s    rw   r   z.WanReferenceVideoApi.execute.<locals>.<lambda>3  r   ry   r   r   r   r   )r2   r   r/   r   r   r   r+   r%   r   r   r   r   r   r   r   r   r*   r   r   r   r   r(   r   )rv   r7   r<   rB   r  r   r   rM   r   rX   r  r   rF   rL   r   r   s                   rw   r   zWanReferenceVideoApi.execute  s       "! 	Z 	ZA#$4Q$7aVXYYYYY! 	b 	bA ''.FsL\]^L_.`.`(`(`(`(`(`(`aaaa%,,T2299;;v!(_hnooo/3/!?Ym   :!,,F,,%''    	"
 "
 "
 
 
 
 
 
 
$  & 	pn:J:OnnTdTlnnooo Y8H8O8WYYZZZ2;;
 
 
 
 
 
 
 
 
 }#?@Y#Z#ZZZZZZZ[[[ry   N)r   r   r   r   rx   r   r   r  Typer   r   r   r   ry   rw   r  r    s        e
 e
 [e
N -\-\ -\ 	-\
 +*-\ -\ -\ -\ -\ -\ -\ -\ [-\ -\ -\ry   r  c                   d    e Zd Zed             Ze	 d	dededededej	        dz  f
d            Z
dS )
Wan2TextToVideoApic                 P   t          j        ddddt           j                            dt           j                            dt           j                            ddd	d
          t           j                            ddd	d          t           j                            dddg          t           j                            dg d          t           j                            dddddt           j        j	                  g          g          t           j
                            ddd          t           j                            dddddt           j        j	        dd !          t           j                            d"dd#d$          t           j                            d%d&d'd$          gt           j                                        gt           j        j        t           j        j        t           j        j        gdt          j        t          j        g d()          d*+          ,	  	        S )-Nr$  zWan 2.7 Text to Videor   zAGenerates a video based on a text prompt using the Wan 2.7 model.r7   z
wan2.7-t2vr<   Tr=   r>   r?   rB   rC   r   r  r  r
  ratioz16:9z9:16z1:1z4:3z3:4r   r   r   r   rO   r  r   zAudio for driving video generation (e.g., lip sync, beat-matched motion). Duration: 3s-30s. If not provided, the model automatically generates matching background music or sound effects.r   rM   r   rN   rP   rA   rI   rJ   rK   rR   rS   r;   rT   rU   r  rX   FrY   r7   model.resolutionzmodel.durationr   ^  
                (
                  $res := $lookup(widgets, "model.resolution");
                  $dur := $lookup(widgets, "model.duration");
                  $ppsTable := { "720p": 0.1, "1080p": 0.15 };
                  $pps := $lookup($ppsTable, $res);
                  { "type": "usd", "usd": $pps * $dur }
                )
                r   r]   )r   rg   DynamicCombor   Optionri   rh   rj   rk   rl   r   rm   r   ro   rp   rq   rr   rs   rt   r   ru   s    rw   rx   z Wan2TextToVideoApi.define_schema:  sV   y(0([%%..( "	$,.2,.-D	 !0 !" !" !#	$5.2,.,W	 !0 !" !" !#$0-3W,= !/ !" !" !#$+,Q,Q,Q !/ !" !" !#$.,-()(*)*131A1H !- !" !"-! !# & & &N !9    "!#!1!8+/9  	 	 
  # O!	 !   
  !U!	 !  EN !! 	.	+	#
 /8g8g8ghhh  i`
 `
 `
 `	
ry   Nr7   rM   rT   rX   r   c                   K   t          |d         dd           d }|+t          |dd           t          | |ddd	
           d {V }t          | t	          dd          t
          t          |d         t          |d         |d         pd |          t          |d         |d         |d         |||                               d {V }|j	        st          d|j         d|j                   t          | t	          d|j	        j                   t          d d           d {V }t!          j        t%          |j	        j                   d {V           S )Nr<   FrO   strip_whitespace
min_lengthg      ?g      N@r   r   
audio/mpegcontainer_format
codec_name	mime_typer   r{   r|   r7   rB   r   r   r&  r   )r   r&  r   rM   rT   rX   r   r   r   r   r   r   c                     | j         j        S r   r   r   s    rw   r   z,Wan2TextToVideoApi.execute.<locals>.<lambda>  r   ry      r!  )r1   r0   r-   r+   r%   r   r!   r   r    r   r   r   r   r*   r   r   r   r   r(   r   )	rv   r7   rM   rT   rX   r   r   r   r   s	            rw   r   zWan2TextToVideoApi.execute  s      	h%ANNNN	#E35556UU|Wc        I ")W   03Gn* ?$)*;$<$D'  
 :$\2.":."/'    "
 "
 "
 
 
 
 
 
 
0  & 	pn:J:OnnTdTlnnooo Y8H8O8WYYZZZ2;;
 
 
 
 
 
 
 
 
 }#?@Y#Z#ZZZZZZZ[[[ry   r   )r   r   r   r   rx   dictr   r   r   r   r   r   ry   rw   r$  r$  9  s        a
 a
 [a
F  %)0\ 0\0\ 0\ 	0\
 0\ {T!0\ 0\ 0\ [0\ 0\ 0\ry   r$  c                       e Zd Zed             Ze	 	 ddedej        dede	de	dej        dz  d	ej
        dz  fd
            ZdS )Wan2ImageToVideoApic                    t          j        ddddt           j                            dt           j                            dt           j                            ddd	d
          t           j                            ddd	d          t           j                            dddg          t           j                            dddddt           j        j	                  g          g          t           j
                            dd          t           j
                            ddd          t           j                            ddd          t           j                            d d!d!d"dt           j        j	        dd#$          t           j                            d%dd&d'          t           j                            d(d)d*d'          gt           j                                        gt           j        j        t           j        j        t           j        j        gdt          j        t          j        g d+,          d-.          /	  	        S )0Nr;  zWan 2.7 Image to Videor   zTGenerate a video from a first-frame image, with optional last-frame image and audio.r7   
wan2.7-i2vr<   Tr=   r>   r?   rB   rC   r   r  r  r
  r   r   r   r   rO   r  first_frameFFirst frame image. The output aspect ratio is derived from this image.r   
last_framezULast frame image. The model generates a video transitioning from first to last frame.r   r   zAudio for driving video generation (e.g., lip sync, beat-matched motion). Duration: 2s-30s. If not provided, the model automatically generates matching background music or sound effects.rM   r   rN   rP   r(  rT   rU   r  rX   FrY   r)  r   r+  r   r]   )r   rg   r,  r   r-  ri   rh   rj   rk   rl   rn   r   rm   r   ro   rp   rq   rr   rs   rt   r   ru   s    rw   rx   z!Wan2ImageToVideoApi.define_schema  ss   y)1(n%%..( "	$,.2,.-D	 !0 !" !" !#	$5.2,.,W	 !0 !" !" !#$0-3W,= !/ !" !" !#$.,-()(*)*131A1H !- !" !"%  & " "F !d     !s   
 !9    "!#!1!8+/9  	 	 
  # O!	 !   
  !U!	 !  IJX !! 	.	+	#
 /8g8g8ghhh  se
 e
 e
 e	
ry   Nr7   r>  rM   rT   rX   r@  r   c                   K   t          dt          | |           d {V           g}|9|                    t          dt          | |           d {V                      |Ot          |dd           t	          | |ddd	
           d {V }	|                    t          d|	                     t          | t          dd          t          t          |d         t          |d         pd |d         pd |          t          |d         |d         |||                               d {V }
|
j        st          d|
j         d|
j                   t          | t          d|
j        j                   t"          d d           d {V }t%          j        t)          |j        j                   d {V           S )Nr>  r   typer   r@  g       @g      >@r   r   r2  r3  driving_audior   r{   r|   r7   r<   rB   r<   rB   mediar   r   r   r   rM   rT   rX   r   r   r   r   r   r   c                     | j         j        S r   r   r   s    rw   r   z-Wan2ImageToVideoApi.execute.<locals>.<lambda>w  r   ry   r8  r!  )r   r.   r   r0   r-   r+   r%   r   r   r   r   r   r   r   r   r*   r   r   r   r   r(   r   )rv   r7   r>  rM   rT   rX   r@  r   rG  r   r   r   s               rw   r   zWan2ImageToVideoApi.execute<  s      "23kJJJJJJJJJ  
 !LL%6s*MMMMMMMMM     #E35556UU|Wc        I LL_)LLLMMM!(W   05Gn1 ?2d$)*;$<$D  
 <$\2":."/'    "
 "
 "
 
 
 
 
 
 
.  & 	pn:J:OnnTdTlnnooo Y8H8O8WYYZZZ2;;
 
 
 
 
 
 
 
 
 }#?@Y#Z#ZZZZZZZ[[[ry   )NN)r   r   r   r   rx   r9  r   rn   r   r   r   r   r   ry   rw   r;  r;    s        f
 f
 [f
P  *.$(=\ =\=\ [=\ 	=\
 =\ =\ K$&=\ {T!=\ =\ =\ [=\ =\ =\ry   r;  c                       e Zd Zed             Ze	 	 	 	 	 	 ddedej        d	ed
edej	        dz  de
dedefd            ZdS )Wan2VideoContinuationApic                 N   t          j        ddddt           j                            dt           j                            dt           j                            ddd	d
          t           j                            ddd	d          t           j                            dddg          t           j                            dddddt           j        j	        d          g          g          t           j
                            dd          t           j                            ddd          t           j                            dd d d!dt           j        j	        dd"#          t           j                            d$dd%d&          t           j                            d'd(d)d&          gt           j
                                        gt           j        j        t           j        j        t           j        j        gdt          j        t          j        g d*+          d,-          .	  	        S )/NrK  zWan 2.7 Video Continuationr   zJContinue a video from where it left off, with optional last-frame control.r7   r=  r<   Tr=   r>   r?   rB   rC   r   r  r  r
  r   r   r   r   rO   zsTotal output duration in seconds. The model generates continuation to fill the remaining time after the input clip.)rA   rI   rJ   rK   rR   r;   
first_clipzcInput video to continue from. Duration: 2s-10s. The output aspect ratio is derived from this video.r   r@  zFLast frame image. The continuation will transition towards this frame.r   rM   r   rN   rP   r(  rT   rU   r  rX   FrY   r)  r   a  
                (
                  $res := $lookup(widgets, "model.resolution");
                  $dur := $lookup(widgets, "model.duration");
                  $ppsTable := { "720p": 0.1, "1080p": 0.15 };
                  $pps := $lookup($ppsTable, $res);
                  $outputPrice := $pps * $dur;
                  {
                    "type": "range_usd",
                    "min_usd": 2 * $pps + $outputPrice,
                    "max_usd": 5 * $pps + $outputPrice
                  }
                )
                r   r]   )r   rg   r,  r   r-  ri   rh   rj   rk   rl   r   rn   rm   ro   rp   rq   rr   rs   rt   r   ru   s    rw   rx   z&Wan2VideoContinuationApi.define_schema~  sT   y.5(d%%..( "	$,.2,.,	 !0 !" !" !#	$5.2,.,W	 !0 !" !" !#$0-3W,= !/ !" !" !#$.,-()(*)*131A1H-W !- 	!" 	!"#   & # #H  J   
  !d   
 "!#!1!8+/9  	 	 
  # O!	 !   
  !U!	 !  EN !! 	.	+	#
 /8g8g8ghhh  ie
 e
 e
 e	
ry   r=   Nr   TFr7   rM  r<   rB   r@  rM   rT   rX   c	                   K   t          |dd           t          dt          | |           d {V           g}	|9|	                    t          dt	          | |           d {V                      t          | t          dd	
          t          t          |d         t          |d         pd |d         pd |	          t          |d         |d         |||                               d {V }
|
j        st          d|
j         d|
j                   t          | t          d|
j        j                   t"          d d           d {V }t%          j        t)          |j        j                   d {V           S )Nr   r  r  rM  rC  r@  rB  r   r{   r|   r7   r<   rB   rF  r   r   rH  r   r   r   r   r   r   c                     | j         j        S r   r   r   s    rw   r   z2Wan2VideoContinuationApi.execute.<locals>.<lambda>  r   ry   r8  r!  )r2   r   r/   r   r.   r+   r%   r   r   r   r   r   r   r   r   r*   r   r   r   r   r(   r   )rv   r7   rM  r<   rB   r@  rM   rT   rX   rG  r   r   s               rw   r   z Wan2VideoContinuationApi.execute  s=      	 
LLLL!23
CCCCCCCC  
 !LL%6s*MMMMMMMMM     ")W   05Gn1 ?2d$)*;$<$D  
 <$\2":."/'    "
 "
 "
 
 
 
 
 
 
.  & 	pn:J:OnnTdTlnnooo Y8H8O8WYYZZZ2;;
 
 
 
 
 
 
 
 
 }#?@Y#Z#ZZZZZZZ[[[ry   )r=   r=   Nr   TF)r   r   r   r   rx   r9  r   r   r   rn   r   r   r   r   ry   rw   rK  rK  }  s        f
 f
 [f
P 
 !)-"9\ 9\9\ K9\ 	9\
 9\ K$&9\ 9\ 9\ 9\ 9\ 9\ [9\ 9\ 9\ry   rK  c                   Z    e Zd Zed             Zededej        dede	de
f
d            ZdS )	Wan2VideoEditApic                    t          j        ddddt           j                            dt           j                            dt           j                            ddd	d
          t           j                            dddg          t           j                            dg dd          t           j                            dg ddd          t           j                            dt           j                            t           j	                            d          g dd                    g          g          t           j
                            dd !          t           j                            d"ddd#d$t           j        j        dd%&          t           j                            d'dd(gdd)d*          t           j                            d+d,d-d.          gt           j
                                        gt           j        j        t           j        j        t           j        j        gdt          j        t          j        g d/0          d12          3	  	        S )4NrQ  zWan 2.7 Video Editr   zJEdit a video using text instructions, reference images, or style transfer.r7   zwan2.7-videoeditr<   Tr=   4Editing instructions or style transfer requirements.r?   r   r  r  r
  r&  r'  AAspect ratio. If not changed, approximates the input video ratio.r9   r   )
auto2345678910rU  z|Output duration in seconds. 'auto' matches the input video duration. A specific value truncates from the start of the video.r   reference_imagesreference_image)image1image2image3image4r   r  r  videoThe video to edit.r   rM   rN   rO   rP   r(  audio_settingoriginz'auto': model decides whether to regenerate audio based on the prompt. 'origin': preserve the original audio from the input video.)r:   rA   r;   rW   rX   FrY   r  r)  r   a  
                (
                  $res := $lookup(widgets, "model.resolution");
                  $dur := $lookup(widgets, "model.duration");
                  $ppsTable := { "720p": 0.1, "1080p": 0.15 };
                  $pps := $lookup($ppsTable, $res);
                  { "type": "usd", "usd": $pps, "format": { "suffix": "/second", "note": "(input + output)" } }
                )
                r   r]   r   rg   r,  r   r-  ri   rh   r  r  rn   r   rj   rk   rl   rm   ro   rp   rq   rr   rs   rt   r   ru   s    rw   rx   zWan2VideoEditApi.define_schema%  s   y&-(d%%... "	$,.2,.,b	 !0 !" !" !#$0-3W,= !/ !" !" !#$+,Q,Q,Q,o !/ !" !"
 !#$.,b,b,b,2-^	 !/ !" !" !# 1 1$6-/[-F-F(*7H(I(I/* /* /* -. .G 	.& 	.& !2 !" !"/$' ') & , ,Z 0    "!#!1!8+/9  	 	 ##X."R!    
  !U!	 !  IJX !! 	.	+	#
 /8g8g8ghhh  se
 e
 e
 e	
ry   r7   re  rM   rg  rX   c                   K   t          |d         dd           t          |dd           |d         d	k    rd
nt          |d                   }t          dt	          | |           d {V           g}|                    di           }|D ]A}	|                    t          dt          | ||	                    d {V                      Bt          | t          dd          t          t          |d         t          |d         |          t          |d         |d         ||||                               d {V }
|
j        st          d|
j         d|
j                   t%          | t          d|
j        j                   t(          d d            d {V }t+          j        t/          |j        j                   d {V           S )!Nr<   FrO   r/  r   r  r  r   rU  r   re  rC  r_  r`  rB  r   r{   r|   r7   r<   rG  r   r&  )r   r&  r   rg  rX   rM   r   r   r   r   r   r   c                     | j         j        S r   r   r   s    rw   r   z*Wan2VideoEditApi.execute.<locals>.<lambda>  r   ry   r8  r!  )r1   r2   r   r   r/   getr   r.   r+   r%   r   r$   r"   r#   r   r   r   r   r*   r   r   r   r   r(   r   )rv   r7   re  rM   rg  rX   r   rG  r_  keyr   r   s               rw   r   zWan2VideoEditApi.execute  s      	h%ANNNNABGGGGj)V3311U:=N9O9OW8PQTV[8\8\2\2\2\2\2\2\]]]^ 99%7<<# 	 	CLL*6NsZjknZo6p6p6p0p0p0p0p0p0p     
 ")W   02Gn.eHoUSSS8$\2.%"/'    "
 "
 "
 
 
 
 
 
 
(  & 	pn:J:OnnTdTlnnooo Y8H8O8WYYZZZ2;;
 
 
 
 
 
 
 
 
 }#?@Y#Z#ZZZZZZZ[[[ry   N)r   r   r   r   rx   r9  r   r   r   r   r   r   r   ry   rw   rQ  rQ  $  s        f
 f
 [f
P 0\0\ {0\ 	0\
 0\ 0\ 0\ 0\ [0\ 0\ 0\ry   rQ  c                   H    e Zd Zed             Zedededefd            ZdS )Wan2ReferenceVideoApic                 F   t          j        ddddt           j                            dt           j                            dt           j                            ddd	d
          t           j                            ddd	d          t           j                            dddg          t           j                            dg d          t           j                            dddddt           j        j	                  t           j
                            dt           j
                            t           j                            d          g dd                    t           j
                            d t           j
                            t           j                            d!          g d"d                    g          g          t           j                            d#ddd$dt           j        j	        dd%&          t           j                            d'd(d)d*          gt           j                                        gt           j        j        t           j        j        t           j        j        gdt          j        t          j        g d+,          d-.          /	  	        S )0Nrp  zWan 2.7 Reference to Videor   zGenerate a video featuring a person or object from reference materials. Supports single-character performances and multi-character interactions.r7   z
wan2.7-r2vr<   Tr=   xPrompt describing the video. Use identifiers such as 'character1' and 'character2' to refer to the reference characters.r?   rB   rC   r   r  r  r
  r&  r'  r   r   r   r  rO   r  r  r  )video1video2video3r   r  r  r_  r`  ra  rb  rc  rd  image5rM   rN   rP   r(  rX   FrY   r  r)  r   a
  
                (
                  $res := $lookup(widgets, "model.resolution");
                  $dur := $lookup(widgets, "model.duration");
                  $ppsTable := { "720p": 0.1, "1080p": 0.15 };
                  $pps := $lookup($ppsTable, $res);
                  $outputPrice := $pps * $dur;
                  {
                    "type": "range_usd",
                    "min_usd": $outputPrice,
                    "max_usd": 5 * $pps + $outputPrice
                  }
                )
                r   r]   )r   rg   r,  r   r-  ri   rh   rj   rk   rl   r  r  r   rn   rm   ro   rp   rq   rr   rs   rt   r   ru   s    rw   rx   z#Wan2ReferenceVideoApi.define_schema  s   y+5(W %%..( "	$,.2,.-Y	 !0 !" !" !#	$5.2,.,W	 !0 !" !" !#$0-3W,= !/ !" !" !#$+,Q,Q,Q !/ !" !" !#$.,-()(*)*131A1H !- !" !" !# 1 1$6-/[-F-F(*7H(I(I.L.L.L,- .G .& .& !2 !" !" !# 1 1$6-/[-F-F(*7H(I(I.`.`.`,- .G .& .& !2 !" !"M.1 13 & 6 6n "!#!1!8+/9  	 	 
  !U!	 !  EHT !! 	.	+	#
 /8g8g8ghhh  qi
 i
 i
 i	
ry   r7   rM   rX   c                 V  K   t          |d         dd           g }|                    di           }|D ]@}|                    t          dt	          | ||                    d {V                      A|                    di           }|D ]A}|                    t          d	t          | ||         
           d {V                      B|st          d          t          |          dk    r t          dt          |           d          t          | t          dd          t          t          |d         t          |d         |d         pd |          t          |d         |d         |d         ||                               d {V }|j        st          d|j         d|j                   t%          | t          d|j        j                   t(          d d !           d {V }	t+          j        t/          |	j        j                   d {V           S )"Nr<   FrO   r/  r  r  rC  r_  r`  rB  zAAt least one reference video or reference image must be provided.r   zToo many references (z9). The maximum total of reference videos and images is 5.r   r{   r|   r7   rB   rF  r   r&  r   r   r&  r   rX   rM   r   r   r   r   r   r   c                     | j         j        S r   r   r   s    rw   r   z/Wan2ReferenceVideoApi.execute.<locals>.<lambda>j  r   ry   r8  r!  )r1   rm  r   r   r/   r.   r   lenr+   r%   r   r   r   r   r   r   r   r   r*   r   r   r   r   r(   r   )
rv   r7   rM   rX   rG  r  rn  r_  r   r   s
             rw   r   zWan2ReferenceVideoApi.execute0  s      	h%ANNNN 99%7<<# 	 	CLL$5AYZ]_ops_tAuAu;u;u;u;u;u;uvvv    !99%7<<# 	 	CLL*6sBRSVBWXXXXXXXXX       	b`aaau::>>mE

mmm   ")W   07Gn3 ?$)*;$<$D  
 >$\2.":.'    "
 "
 "
 
 
 
 
 
 
.  & 	pn:J:OnnTdTlnnooo Y8H8O8WYYZZZ2;;
 
 
 
 
 
 
 
 
 }#?@Y#Z#ZZZZZZZ[[[ry   N	r   r   r   r   rx   r9  r   r   r   r   ry   rw   rp  rp    sv        j
 j
 [j
X <\<\ <\ 	<\ <\ <\ [<\ <\ <\ry   rp  c                   H    e Zd Zed             Zedededefd            ZdS )HappyHorseTextToVideoApic                    t          j        ddddt           j                            dt           j                            dt           j                            ddd	d
          t           j                            dddg          t           j                            dg d          t           j                            dddddt           j        j	                  g          g          t           j                            dddddt           j        j	        dd          t           j
                            dddd           gt           j                                        gt           j        j        t           j        j        t           j        j        gdt          j        t          j        g d!"          d#$          %	  	        S )&Nr~  zHappyHorse Text to Videor   zDGenerates a video based on a text prompt using the HappyHorse model.r7   zhappyhorse-1.0-t2vr<   Tr=   r>   r?   r   r  r  r
  r&  r'  r   r   r   r   rO   r  rM   r   rN   rP   r(  rX   FrY   r  r)  r   _  
                (
                  $res := $lookup(widgets, "model.resolution");
                  $dur := $lookup(widgets, "model.duration");
                  $ppsTable := { "720p": 0.14, "1080p": 0.24 };
                  $pps := $lookup($ppsTable, $res);
                  { "type": "usd", "usd": $pps * $dur }
                )
                r   r]   )r   rg   r,  r   r-  ri   rh   rj   rk   rl   rm   r   ro   rp   rq   rr   rs   rt   r   ru   s    rw   rx   z&HappyHorseTextToVideoApi.define_schemaq  s   y.3(^%%..0 "	$,.2,.-D	 !0 !" !" !#$0-3W,= !/ !" !" !#$+,Q,Q,Q !/ !" !" !#$.,-()(*)*131A1H !- !" !"!  &    B "!#!1!8+/9  	 	 
  !U!	 !  Y2h !! 	.	+	#
 /8g8g8ghhh  CM
 M
 M
 M	
ry   r7   rM   rX   c                 R  K   t          |d         dd           t          | t          dd          t          t	          |d         t          |d         d 	          t          |d
         |d         |d         ||                               d {V }|j        st          d|j	         d|j
                   t          | t          d|j        j                   t          d d           d {V }t          j        t!          |j        j                   d {V           S )Nr<   FrO   r/  r   r{   r|   r7   r   r   r&  r   )r   r&  r   rM   rX   r   r   r   r   r   r   c                     | j         j        S r   r   r   s    rw   r   z2HappyHorseTextToVideoApi.execute.<locals>.<lambda>  r   ry   r8  r!  )r1   r+   r%   r   r!   r   r    r   r   r   r   r*   r   r   r   r   r(   r   )rv   r7   rM   rX   r   r   s         rw   r   z HappyHorseTextToVideoApi.execute  s      	h%ANNNN!(W   03Gn* ?$(   :$\2.":.'    "
 "
 "
 
 
 
 
 
 
,  & 	pn:J:OnnTdTlnnooo Y8H8O8WYYZZZ2;;
 
 
 
 
 
 
 
 
 }#?@Y#Z#ZZZZZZZ[[[ry   Nr|  r   ry   rw   r~  r~  p  sv        N
 N
 [N
` &\&\ &\ 	&\ &\ &\ [&\ &\ &\ry   r~  c            	       V    e Zd Zed             Zededej        dede	fd            Z
dS )HappyHorseImageToVideoApic                    t          j        ddddt           j                            dt           j                            dt           j                            ddd	d
          t           j                            dddg          t           j                            dddddt           j        j	                  g          g          t           j
                            dd          t           j                            dddddt           j        j	        dd          t           j                            ddd d!          gt           j                                        gt           j        j        t           j        j        t           j        j        gdt          j        t          j        g d"#          d$%          &	  	        S )'Nr  zHappyHorse Image to Videor   zEGenerate a video from a first-frame image using the HappyHorse model.r7   zhappyhorse-1.0-i2vr<   Tr=   r>   r?   r   r  r  r
  r   r   r   r   rO   r  r>  r?  r   rM   r   rN   rP   r(  rX   FrY   r  r)  r   r  r   r]   )r   rg   r,  r   r-  ri   rh   rj   rk   rl   rn   rm   r   ro   rp   rq   rr   rs   rt   r   ru   s    rw   rx   z'HappyHorseImageToVideoApi.define_schema  s   y/4(_%%..0 "	$,.2,.-D	 !0 !" !" !#$0-3W,= !/ !" !" !#$.,-()(*)*131A1H !- !" !"  &  : !d    "!#!1!8+/9  	 	 
  !U!	 !  Y2h !! 	.	+	#
 /8g8g8ghhh  CM
 M
 M
 M	
ry   r7   r>  rM   rX   c                 h  K   t          dt          | |           d {V           g}t          | t          dd          t          t          |d         t          |d         pd d |	          t          |d
         |d         ||                               d {V }|j        st          d|j
         d|j                   t          | t          d|j        j                   t          d d           d {V }t          j        t#          |j        j                   d {V           S )Nr>  rB  rC  r   r{   r|   r7   r<   rF  r   r   )r   r   rM   rX   r   r   r   r   r   r   c                     | j         j        S r   r   r   s    rw   r   z3HappyHorseImageToVideoApi.execute.<locals>.<lambda>h  r   ry   r8  r!  )r   r.   r+   r%   r   r   r   r   r   r   r   r   r*   r   r   r   r   r(   r   )rv   r7   r>  rM   rX   rG  r   r   s           rw   r   z!HappyHorseImageToVideoApi.execute>  s      "23kJJJJJJJJJ  
 ")W   05Gn1 ?2d$(  
 <$\2":.'	    "
 "
 "
 
 
 
 
 
 
,  & 	pn:J:OnnTdTlnnooo Y8H8O8WYYZZZ2;;
 
 
 
 
 
 
 
 
 }#?@Y#Z#ZZZZZZZ[[[ry   N)r   r   r   r   rx   r9  r   rn   r   r   r   r   ry   rw   r  r    s        N
 N
 [N
` ,\,\ [,\ 	,\
 ,\ ,\ ,\ [,\ ,\ ,\ry   r  c            	       V    e Zd Zed             Zededej        dede	fd            Z
dS )HappyHorseVideoEditApic                     t          j        ddddt           j                            dt           j                            dt           j                            ddd	d
          t           j                            dddg          t           j                            dg dd          t           j                            dt           j                            t           j	                            d          g dd                    g          g          t           j
                            dd          t           j                            dddddt           j        j        dd !          t           j                            d"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HappyHorse Video Editr   zEdit a video using text instructions or reference images with the HappyHorse model. Output duration is 3-15s and matches the input video; inputs longer than 15s are truncated.r7   zhappyhorse-1.0-video-editr<   Tr=   rS  r?   r   r  r  r
  r&  r'  rT  r9   r_  r`  rv  r   r  r  re  rf  r   rM   rN   rO   rP   r(  rX   FrY   r  r*  r   a=  
                (
                  $res := $lookup(widgets, "model.resolution");
                  $ppsTable := { "720p": 0.14, "1080p": 0.24 };
                  $pps := $lookup($ppsTable, $res);
                  { "type": "usd", "usd": $pps, "format": { "suffix": "/second" } }
                )
                r   r]   ri  ru   s    rw   rx   z$HappyHorseVideoEditApi.define_schemao  s4   y,0(j %%..7 "	$,.2,.,b	 !0 !" !" !#$0-3W,= !/ !" !" !#$+,Q,Q,Q,o !/ !" !"
 !# 1 1$6-/[-F-F(*7H(I(I/* /* /* -. .G 
.& 
.& !2 !" !"!! !# & & &N 0    "!#!1!8+/9  	 	 
  !U!	 !  m<| !! 	.	+	#
 /BT8UVVV
 
 
YW
 W
 W
 W	
ry   r7   re  rM   rX   c                 j  K   t          |d         dd           t          |dd           t          dt          | |           d {V 	          g}|                    d
i           }|D ]A}|                    t          dt          | ||                    d {V 	                     Bt          | t          dd          t          t          |d         t          |d         |          t          |d         |d         d ||                               d {V }|j        st          d|j         d|j                   t#          | t          d|j        j                   t&          d d           d {V }	t)          j        t-          |	j        j                   d {V           S )Nr<   FrO   r/  r   <   r  re  rC  r_  r`  rB  r   r{   r|   r7   rk  r   r&  ry  r   r   r   r   r   r   c                     | j         j        S r   r   r   s    rw   r   z0HappyHorseVideoEditApi.execute.<locals>.<lambda>  r   ry   r8  r!  )r1   r2   r   r/   rm  r   r.   r+   r%   r   r$   r"   r#   r   r   r   r   r*   r   r   r   r   r(   r   )
rv   r7   re  rM   rX   rG  r_  rn  r   r   s
             rw   r   zHappyHorseVideoEditApi.execute  sY      	h%ANNNNABGGGGW8PQTV[8\8\2\2\2\2\2\2\]]]^ 99%7<<# 	 	CLL*6NsZjknZo6p6p6p0p0p0p0p0p0p     
 ")W   02Gn.eHoUSSS8$\2.!'  
 
 
"
 "
 "
 
 
 
 
 
 
&  & 	pn:J:OnnTdTlnnooo Y8H8O8WYYZZZ2;;
 
 
 
 
 
 
 
 
 }#?@Y#Z#ZZZZZZZ[[[ry   N)r   r   r   r   rx   r9  r   r   r   r   r   r   ry   rw   r  r  n  s        X
 X
 [X
t -\-\ {-\ 	-\
 -\ -\ -\ [-\ -\ -\ry   r  c                   H    e Zd Zed             Zedededefd            ZdS )HappyHorseReferenceVideoApic                 D   t          j        ddddt           j                            dt           j                            dt           j                            ddd	d
          t           j                            dddg          t           j                            dg d          t           j                            dddddt           j        j	                  t           j
                            dt           j
                            t           j                            d          g dd                    g          g          t           j                            dddddt           j        j	        dd !          t           j                            d"d#d$d%          gt           j                                        gt           j        j        t           j        j        t           j        j        gdt          j        t          j        g d&'          d()          *	  	        S )+Nr  zHappyHorse Reference to Videor   zGenerate a video featuring a person or object from reference materials with the HappyHorse model. Supports single-character performances and multi-character interactions.r7   zhappyhorse-1.0-r2vr<   Tr=   rr  r?   r   r  r  r
  r&  r'  r   r   r   r   rO   r  r_  r`  )	ra  rb  rc  rd  rw  image6image7image8image9r  r  rM   r   rN   rP   r(  rX   FrY   r  r)  r   r  r   r]   )r   rg   r,  r   r-  ri   rh   rj   rk   rl   r  r  rn   rm   r   ro   rp   rq   rr   rs   rt   r   ru   s    rw   rx   z)HappyHorseReferenceVideoApi.define_schema  sH   y18(^ %%..0 "	$,.2,.-Y	 !0 !" !" !#$0-3W,= !/ !" !" !#$+,Q,Q,Q !/ !" !" !#$.,-()(*)*131A1H !- !" !" !# 1 1$6-/[-F-F(*7H(I(I
/* 
/* 
/* -. .G .& .& !2 !" !"1*- -/ & 2 2f "!#!1!8+/9  	 	 
  !U!	 !  }DL !! 	.	+	#
 /8g8g8ghhh  i`
 `
 `
 `	
ry   r7   rM   rX   c                 .  K   t          |d         dd           g }|                    di           }|D ]A}|                    t          dt	          | ||                    d {V                      B|st          d	          t          | t          d
d          t          t          |d         t          |d         d |          t          |d         |d         |d         ||                               d {V }|j        st          d|j         d|j                   t!          | t          d|j        j                   t$          d d           d {V }t'          j        t+          |j        j                   d {V           S )Nr<   FrO   r/  r_  r`  rB  rC  z8At least one reference reference image must be provided.r   r{   r|   r7   rF  r   r&  r   ry  r   r   r   r   r   r   c                     | j         j        S r   r   r   s    rw   r   z5HappyHorseReferenceVideoApi.execute.<locals>.<lambda>  r   ry   r8  r!  )r1   rm  r   r   r.   r   r+   r%   r   r   r   r   r   r   r   r   r*   r   r   r   r   r(   r   )	rv   r7   rM   rX   rG  r_  rn  r   r   s	            rw   r   z#HappyHorseReferenceVideoApi.execute`  s?      	h%ANNNN 99%7<<# 	 	CLL*6sBRSVBWXXXXXXXXX       	YWXXX!(W   07Gn3 ?$(  
 >$\2.":.'    "
 "
 "
 
 
 
 
 
 
.  & 	pn:J:OnnTdTlnnooo Y8H8O8WYYZZZ2;;
 
 
 
 
 
 
 
 
 }#?@Y#Z#ZZZZZZZ[[[ry   Nr|  r   ry   rw   r  r    sv        a
 a
 [a
F 3\3\ 3\ 	3\ 3\ 3\ [3\ 3\ 3\ry   r  c                   L    e Zd Zedeeej                          fd            ZdS )WanApiExtensionreturnc                    K   t           t          t          t          t          t
          t          t          t          t          t          t          t          t          gS r   )r4   r   r   r   r  r$  r;  rK  rQ  rp  r~  r  r  r  )selfs    rw   get_node_listzWanApiExtension.get_node_list  s<        $!$%"'
 	
ry   N)	r   r   r   r   listrD  r   	ComfyNoder  r   ry   rw   r  r    sE        
T$r|*<%= 
 
 
 X
 
 
ry   r  r  c                  "   K   t                      S r   )r  r   ry   rw   comfy_entrypointr    s      ry   )Hretyping_extensionsr   comfy_api.latestr   r   r   comfy_api_nodes.apis.wanr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   comfy_api_nodes.utilr%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   compiler   r  r4   r   r   r   r  r$  r;  rK  rQ  rp  r~  r  r  r  r  r  r   ry   rw   <module>r     s   				 & & & & & & 6 6 6 6 6 6 6 6 6 6                                                               @                               " 
788xf xf xf xf xf xf xf xfv}f }f }f }f }f }f }f }f@t\ t\ t\ t\ t\ t\ t\ t\np\ p\ p\ p\ p\ p\ p\ p\fW\ W\ W\ W\ W\2< W\ W\ W\tV\ V\ V\ V\ V\ V\ V\ V\rh\ h\ h\ h\ h\", h\ h\ h\Vd\ d\ d\ d\ d\r| d\ d\ d\N[\ [\ [\ [\ [\r| [\ [\ [\|k\ k\ k\ k\ k\BL k\ k\ k\\y\ y\ y\ y\ y\r| y\ y\ y\x\ \ \ \ \ \ \ \DJ\ J\ J\ J\ J\R\ J\ J\ J\ZY\ Y\ Y\ Y\ Y\", Y\ Y\ Y\x
 
 
 
 
n 
 
 
*      ry   