
    +j@                        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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 dZdZdZd	eej                 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% ej&         ej'        g d          d          Z( G d de          Z)de)fdZ*dS )    N)override)IOComfyExtension)PixverseTextVideoRequestPixverseImageVideoRequestPixverseTransitionVideoRequestPixverseImageUploadResponsePixverseVideoResponse PixverseGenerationStatusResponsePixverseAspectRatioPixverseQualityPixverseDurationPixverseMotionModePixverseStatus
PixverseIOpixverse_templates)ApiEndpointdownload_url_to_video_outputpoll_opsync_optensor_to_bytesiovalidate_string       4   clsimagec           	         K   t          | t          dd          t          dt          |          id           d {V }|j        t          d|j         d          |j        j        S )	Nz/proxy/pixverse/image/uploadPOSTpathmethodr   zmultipart/form-data)response_modelfilescontent_typez'PixVerse image upload request failed: '')r   r   r	   r   Resp	ExceptionErrMsgimg_id)r   r   response_uploads      >/home/wildlama/comfy/ComfyUI/comfy_api_nodes/nodes_pixverse.pyupload_image_to_pixverser-   !   s      #7GGG2)%001*        O #[/BX[[[\\\&&    c                   b    e Zd ZdZedej        fd            Zededej	        fd            Z
dS )PixverseTemplateNodez8
    Select template for PixVerse Video generation.
    returnc                    t          j        dddt           j                            dt	          t          j                                        gt          j        t          j	                  
                    d          g          S )	Nr0   zPixVerse Templatepartner/video/PixVersetemplateoptionspixverse_template)display_name)node_idr8   categoryinputsoutputs)r   SchemaComboInputlistr   keysCustomr   TEMPLATEOutputr   s    r,   define_schemaz"PixverseTemplateNode.define_schema3   sw    y*,-z48J8O8Q8Q3R3RSS Yz233::H[:\\]
 
 
 	
r.   r4   c                 ~    t          j        |d           }|t          d| d          t          j        |          S )Nz
Template 'z' is not recognized.)r   getr(   r   
NodeOutput)r   r4   template_ids      r,   executezPixverseTemplateNode.execute?   sD    (,Xt<<GGGGHHH}[)))r.   N)__name__
__module____qualname____doc__classmethodr   r=   rF   strrI   rK    r.   r,   r0   r0   .   sw          	
bi 	
 	
 	
 [	
 *s *r} * * * [* * *r.   r0   c                   |    e Zd Zedej        fd            Ze	 	 ddededededed	ed
edej	        fd            Z
dS )PixverseTextToVideoNoder1   c                 V   t          j        ddddt           j                            dddd	          t           j                            d
t
                    t           j                            dt          t          j                  t           j                            dt                    t           j                            dt                    t           j
                            dddddd          t           j                            ddddd          t          j        t          j                                      ddd          gt           j                                        gt           j        j        t           j        j        t           j        j        gdt(          	  	        S )NrT   zPixVerse Text to Videor3   1Generates videos based on prompt and output_size.promptT Prompt for the video generation	multilinedefaulttooltipaspect_ratior5   qualityr6   r\   duration_secondsmotion_modeseedr   Seed for video generation.r\   minmaxcontrol_after_generater]   negative_prompt?An optional text description of undesired elements on an image.r\   r[   r]   optionalr7   ]An optional template to influence style of generation, created by the PixVerse Template node.r]   rm   	r9   r8   r:   descriptionr;   r<   hiddenis_api_nodeprice_badge)r   r=   Stringr?   r>   r   r   res_540pr   r   IntrB   r   rC   VideorD   Hiddenauth_token_comfy_orgapi_key_comfy_org	unique_idPRICE_BADGE_VIDEOrE   s    r,   rF   z%PixverseTextToVideoNode.define_schemaH   s   y-1-K	"=	     "/    ++4   
 &,    !.    "+/8    	%"]!     	*-..44'{! 5  O,Z X__&&'	.	+	#
 )s:
 :
 :
 :	
r.   NrW   r^   r_   ra   rb   rj   r7   c	                   K   t          |dd           |t          j        k    rt          j        }t
          j        }n|t
          j        k    rt          j        }t          | t          dd          t          t          ||||||r|nd ||                     d {V }	|	j        t          d	|	j         d
          t          | t          d|	j        j                   t           t"          j        gt"          j        t"          j        t"          j        gd t,                     d {V }
t/          j        t3          |
j        j                   d {V           S )NF   )strip_whitespace
min_lengthz#/proxy/pixverse/video/text/generater   r    )rW   r^   r_   durationrb   rj   rJ   rc   r#   dataPixVerse request failed: 'r&   /proxy/pixverse/video/result/r!   c                     | j         j        S Nr'   statusxs    r,   <lambda>z1PixverseTextToVideoNode.execute.<locals>.<lambda>   
    qv} r.   r#   completed_statusesfailed_statusesstatus_extractorestimated_duration)r   r   	res_1080pr   normalr   dur_5r   r   r
   r   r'   r(   r)   r   video_idr   r   
successfulcontents_moderationfaileddeletedAVERAGE_DURATION_T2Vr   rI   r   url)r   rW   r^   r_   ra   rb   rc   rj   r7   response_apiresponse_polls              r,   rK   zPixverseTextToVideoNode.execute   s      	1EEEE o///,3K/5!1!777,3K$B6RRR0)))'3B L-	 	 		
 
 
 
 
 
 
 
 
 $O9LOOOPPP%Y\=N=WYYZZZ; . 9:2%&
 543
 
 
 
 
 
 
 
 
 }#?@R@V#W#WWWWWWWXXXr.   NN)rL   rM   rN   rP   r   r=   rF   rQ   intrI   rK   rR   r.   r,   rT   rT   G   s        ;
bi ;
 ;
 ;
 [;
z   $!%3Y 3Y3Y 3Y 	3Y
 3Y 3Y 3Y 3Y 
3Y 3Y 3Y [3Y 3Y 3Yr.   rT   c                       e Zd Zedej        fd            Ze	 	 ddej        de	de	de
de	d	e	d
e
dej        fd            ZdS )PixverseImageToVideoNoder1   c                 H   t          j        ddddt           j                            d          t           j                            dddd	
          t           j                            dt          t          j                  t           j                            dt                    t           j                            dt                    t           j
                            dddddd          t           j                            ddddd          t          j        t          j                                      ddd          gt           j                                        gt           j        j        t           j        j        t           j        j        gdt(          	  	        S )Nr   zPixVerse Image to Videor3   rV   r   rW   TrX   rY   rZ   r_   r`   ra   r5   rb   rc   r   rd   re   rf   rj   rk   rl   r7   rn   ro   rp   )r   r=   Imager?   ru   r>   r   rv   r   r   rw   rB   r   rC   rx   rD   ry   rz   r{   r|   r}   rE   s    r,   rF   z&PixverseImageToVideoNode.define_schema   s   y.2-Kw''	"=	     ++4   
 &,    !.    "+/8    	%"]!     	*-..44'{! 5  I)T X__&&'	.	+	#
 )m7
 7
 7
 7	
r.   Nr   rW   r_   ra   rb   rj   r7   c	                   K   t          |d           t          | |           d {V }	|t          j        k    rt          j        }t          j        }n|t          j        k    rt          j        }t          | t          dd          t          t          |	|||||r|nd ||                     d {V }
|
j        t          d|
j         d	          t          | t          d
|
j        j                   t"          t$          j        gt$          j        t$          j        t$          j        gd t.                     d {V }t1          j        t5          |j        j                   d {V           S )NFr   z"/proxy/pixverse/video/img/generater   r    )r*   rW   r_   r   rb   rj   rJ   rc   r   r   r&   r   r   c                     | j         j        S r   r   r   s    r,   r   z2PixverseImageToVideoNode.execute.<locals>.<lambda>-  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   AVERAGE_DURATION_I2Vr   rI   r   r   )r   r   rW   r_   ra   rb   rc   rj   r7   r*   r   r   s               r,   rK   z PixverseImageToVideoNode.execute   s      	7777/U;;;;;;;; o///,3K/5!1!777,3K$A&QQQ0*)'3B L-	 	 		
 
 
 
 
 
 
 
 
  $O9LOOOPPP%Y\=N=WYYZZZ; . 9:2%&
 543
 
 
 
 
 
 
 
 
 }#?@R@V#W#WWWWWWWXXXr.   r   rL   rM   rN   rP   r   r=   rF   torchTensorrQ   r   rI   rK   rR   r.   r,   r   r      s        8
bi 8
 8
 8
 [8
t   $!%6Y 6Y|6Y 6Y 	6Y
 6Y 6Y 6Y 6Y 
6Y 6Y 6Y [6Y 6Y 6Yr.   r   c                       e Zd Zedej        fd            Ze	 ddej        dej        de	de	de
d	e	d
e	dej        fd            ZdS )PixverseTransitionVideoNoder1   c                    t          j        ddddt           j                            d          t           j                            d          t           j                            ddd	d
          t           j                            dt          t          j                  t           j                            dt                    t           j                            dt                    t           j
                            d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"          	  	        S )Nr   zPixVerse Transition Videor3   rV   first_frame
last_framerW   TrX   rY   rZ   r_   r`   ra   r5   rb   rc   r   rd   re   rf   rj   rk   rl   rp   )r   r=   r   r?   ru   r>   r   rv   r   r   rw   rx   rD   ry   rz   r{   r|   r}   rE   s    r,   rF   z)PixverseTransitionVideoNode.define_schema4  sh   y14-K}--|,,	"=	     ++4   
 &,    !.    "+/8    	%"]!    =%L X__&&'	.	+	#
 )e3
 3
 3
 3	
r.   Nr   r   rW   r_   ra   rb   rj   c	                   K   t          |d           t          | |           d {V }	t          | |           d {V }
|t          j        k    rt          j        }t          j        }n|t          j        k    rt          j        }t          | t          dd          t          t          |	|
|||||r|nd |                     d {V }|j        t          d|j         d	          t          | t          d
|j        j                   t"          t$          j        gt$          j        t$          j        t$          j        gd t.                     d {V }t1          j        t5          |j        j                   d {V           S )NFr   z)/proxy/pixverse/video/transition/generater   r    )first_frame_imglast_frame_imgrW   r_   r   rb   rj   rc   r   r   r&   r   r   c                     | j         j        S r   r   r   s    r,   r   z5PixverseTransitionVideoNode.execute.<locals>.<lambda>  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   rI   r   r   )r   r   r   rW   r_   ra   rb   rc   rj   first_frame_idlast_frame_idr   r   s                r,   rK   z#PixverseTransitionVideoNode.executek  s      	77777[IIIIIIII6sJGGGGGGGG o///,3K/5!1!777,3K$HQWXXX0/ .,)'3B L	 	 		
 
 
 
 
 
 
 
 
  $O9LOOOPPP%Y\=N=WYYZZZ; . 9:2%&
 543
 
 
 
 
 
 
 
 
 }#?@R@V#W#WWWWWWWXXXr.   r   r   rR   r.   r,   r   r   3  s        4
bi 4
 4
 4
 [4
l   $7Y 7Y\7Y L7Y 	7Y
 7Y 7Y 7Y 7Y 
7Y 7Y 7Y [7Y 7Y 7Yr.   r   )ra   r_   rb   )widgetsa  
    (
      $prices := {
        "5": {
          "1080p": {"normal": 1.2, "fast": 1.2},
          "720p": {"normal": 0.6, "fast": 1.2},
          "540p": {"normal": 0.45, "fast": 0.9},
          "360p": {"normal": 0.45, "fast": 0.9}
        },
        "8": {
          "1080p": {"normal": 1.2, "fast": 1.2},
          "720p": {"normal": 1.2, "fast": 1.2},
          "540p": {"normal": 0.9, "fast": 1.2},
          "360p": {"normal": 0.9, "fast": 1.2}
        }
      };
      $durPrices := $lookup($prices, $string(widgets.duration_seconds));
      $qualityPrices := $lookup($durPrices, widgets.quality);
      $price := $lookup($qualityPrices, widgets.motion_mode);
      {"type":"usd","usd": $price ? $price : 0.9}
    )
    )
depends_onexprc                   L    e Zd Zedeeej                          fd            ZdS )PixVerseExtensionr1   c                 :   K   t           t          t          t          gS r   )rT   r   r   r0   )selfs    r,   get_node_listzPixVerseExtension.get_node_list  s       $$' 	
 	
r.   N)	rL   rM   rN   r   r@   typer   	ComfyNoder   rR   r.   r,   r   r     sE        
T$r|*<%= 
 
 
 X
 
 
r.   r   r1   c                  "   K   t                      S r   )r   rR   r.   r,   comfy_entrypointr     s      r.   )+r   typing_extensionsr   comfy_api.latestr   r   comfy_api_nodes.apis.pixverser   r   r   r	   r
   r   r   r   r   r   r   r   r   comfy_api_nodes.utilr   r   r   r   r   r   r   r   AVERAGE_DURATION_T2Tr   r   r   r-   r0   rT   r   r   
PriceBadgePriceBadgeDependsr}   r   r   rR   r.   r,   <module>r      s    & & & & & & / / / / / / / /                                                
'R\(: 
'5< 
' 
' 
' 
'* * * * *2< * * *2sY sY sY sY sYbl sY sY sYlsY sY sY sY sYr| sY sY sYlpY pY pY pY pY", pY pY pYf "BM#r#,Z,Z,Z[[[
   6
 
 
 
 
 
 
 
 1      r.   