
    +j                         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
 d dlmZmZmZmZmZmZmZmZmZm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 )    )override)IOComfyExtensionInput)FlashVSRRequestTaskCreatedResponseTaskResultResponseSeedVR2ImageRequest)
ApiEndpointdownload_url_to_video_outputpoll_opsync_opupload_video_to_comfyapi validate_container_format_is_mp4validate_video_durationupload_images_to_comfyapiget_number_of_imagesdownload_url_to_image_tensorc                   \    e Zd Zed             Zedej        dedej	        fd            Z
dS )WavespeedFlashVSRNodec                    t          j        ddddt           j                            d          t           j                            dg d          gt           j                                        gt           j        j        t           j        j        t           j        j	        gd	t          j
        t          j        dg
          d          	  	        S )Nr   zFlashVSR Video Upscalezpartner/video/WaveSpeedzsFast, high-quality video upscaler that boosts resolution and restores clarity for low-resolution or blurry footage.videotarget_resolution)720p1080p2K4KoptionsTwidgetsaw  
                (
                  $price_for_1sec := {"720p": 0.012, "1080p": 0.018, "2k": 0.024, "4k": 0.032};
                  {
                    "type":"usd",
                    "usd": $lookup($price_for_1sec, widgets.target_resolution),
                    "format":{"suffix": "/second", "approximate": true}
                  }
                )
                
depends_onexpr	node_iddisplay_namecategorydescriptioninputsoutputshiddenis_api_nodeprice_badge)r   SchemaVideor   ComboOutputHiddenauth_token_comfy_orgapi_key_comfy_org	unique_id
PriceBadgePriceBadgeDependsclss    ?/home/wildlama/comfy/ComfyUI/comfy_api_nodes/nodes_wavespeed.pydefine_schemaz#WavespeedFlashVSRNode.define_schema   s    y+1.[ w''2<Y<Y<YZZ
 !! 	.	+	#
 /9L8MNNN	  ' 
  
  
  	
    r   r   returnc                   K   t          |           t          |dd           t          | t          dd          t          t          |                                t          | |           d {V |                                                     d {V }|j	        d	k    rt          d
|j	         d|j                   t          | t          d|j        j         d          t          d d           d {V }|j	        d	k    rt          d|j	         d|j                   t!          j        t%          |j        j        d                    d {V           S )N   iX  )min_durationmax_durationz-/proxy/wavespeed/api/v3/wavespeed-ai/flashvsrPOSTpathmethod)r   r   durationresponse_modeldata   Task creation fails with code= and message=$/proxy/wavespeed/api/v3/predictions//resultrE   c                 ,    | j         dn| j         j        S NfailedrJ   statusxs    r;   <lambda>z/WavespeedFlashVSRNode.execute.<locals>.<lambda>U       16>xxqv} r=         $@rI   status_extractorpoll_interval!Task processing failed with code=r   )r   r   r   r   r   r   lowerr   get_durationcode
ValueErrormessager   rJ   idr	   r   
NodeOutputr   r+   )r:   r   r   initial_resfinal_responses        r;   executezWavespeedFlashVSRNode.execute=   s      	)///AGLLLL#LU[\\\. "3"9"9";";4S%@@@@@@@@++--  		
 	
 	
 	
 	
 	
 	
 	
 	
 s""rk>Nrr]h]prrsss&`KDTDW```aaa-TT 
  
  
 
 
 
 
 
 
 #%%nN4GnnVdVlnn   }#?@S@[\]@^#_#_______```r=   N)__name__
__module____qualname__classmethodr<   r   r0   strr   re   rh    r=   r;   r   r      sw        !
 !
 [!
F a{a a 
	a a a [a a ar=   r   c            	       `    e Zd Zed             Zededej        dedej	        fd            Z
dS )WavespeedImageUpscaleNodec                    t          j        ddddt           j                            dddg          t           j                            d	          t           j                            d
g d          gt           j                                        gt           j        j        t           j        j        t           j        j	        gdt          j
        t          j        dg          d          	  	        S )Nrp   zWaveSpeed Image Upscalezpartner/image/WaveSpeedz]Boost image resolution and quality, upscaling photos to 4K or 8K for sharp, detailed results.modelSeedVR2Ultimater   imager   )r   r   8KTr    z
                (
                  $prices := {"seedvr2": 0.01, "ultimate": 0.06};
                  {"type":"usd", "usd": $lookup($prices, widgets.model)}
                )
                r"   r%   )r   r/   r1   r   Imager2   r3   r4   r5   r6   r7   r8   r9   s    r;   r<   z'WavespeedImageUpscaleNode.define_schema`   s    y/2.wwJ0GHHw''2<N<N<NOO !! 	.	+	#
 /	BBB  '
 
 
 	
r=   rr   ru   r   r>   c                   K   t          |          dk    rt          d          |dk    rd}nd}t          | t          d| d          t          t          |                                t          | |d	           d {V d
                              d {V }|j        dk    rt          d|j         d|j	                   t          | t          d|j        j         d          t          d d           d {V }|j        dk    rt          d|j         d|j	                   t          j        t!          |j        j        d
                    d {V           S )N   z$Exactly one input image is required.rs   zseedvr2/imagezultimate-image-upscalerz%/proxy/wavespeed/api/v3/wavespeed-ai/rC   rD   )
max_imagesr   )r   ru   rH   rK   rL   rM   rN   rO   rP   c                 ,    | j         dn| j         j        S rR   rT   rV   s    r;   rX   z3WavespeedImageUpscaleNode.execute.<locals>.<lambda>   rY   r=   rZ   r[   r^   )r   rb   r   r   r   r
   r_   r   ra   rc   r   rJ   rd   r	   r   re   r   r+   )r:   rr   ru   r   
model_pathrf   rg   s          r;   rh   z!WavespeedImageUpscaleNode.execute   s       &&!++CDDDI(JJ2J#QZQQZ`aaa.$"3"9"9";";6sEaPPPPPPPPPRST  	
 
 
 
 
 
 
 
 
 s""rk>Nrr]h]prrsss&`KDTDW```aaa-TT 
  
  
 
 
 
 
 
 
 #%%nN4GnnVdVlnn   }#?@S@[\]@^#_#_______```r=   N)ri   rj   rk   rl   r<   rm   r   rw   r   re   rh   rn   r=   r;   rp   rp   _   s        
 
 [
> "a"a {"a 	"a
 
"a "a "a ["a "a "ar=   rp   c                   L    e Zd Zedeeej                          fd            ZdS )WavespeedExtensionr>   c                 "   K   t           t          gS N)r   rp   )selfs    r;   get_node_listz WavespeedExtension.get_node_list   s       "%
 	
r=   N)	ri   rj   rk   r   listtyper   	ComfyNoder   rn   r=   r;   r~   r~      sE        
T$r|*<%= 
 
 
 X
 
 
r=   r~   r>   c                  "   K   t                      S r   )r~   rn   r=   r;   comfy_entrypointr      s      r=   N)typing_extensionsr   comfy_api.latestr   r   r   comfy_api_nodes.apis.wavespeedr   r   r	   r
   comfy_api_nodes.utilr   r   r   r   r   r   r   r   r   r   r   r   rp   r~   r   rn   r=   r;   <module>r      s   & & & & & & 6 6 6 6 6 6 6 6 6 6                                  Da Da Da Da DaBL Da Da DaNDa Da Da Da Da Da Da DaN
 
 
 
 
 
 
 
  2            r=   