
    +j{                       d dl Z d dlZd dlZd dlZd dlmZ d dlZd dlmZ d dl	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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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZB d dlCmDZD d	ZEd
ZFdZGddddZHeeedZIdZJdZKdZLdddZMddhZN ejO        eP          ZQdejR        deSdeSdeTddf
dZUdejV        dejV        fdZWd d!d"d#d$d%d&ZXd'd(d)d*ZYdeSd+eSdejZ        de[eTeTf         fd,Z\dejZ        d-eTd.eTdejZ        fd/Z]d0e^ej_                 d1e`eS         de[eaeSeSf         eaeSeSf         eaeSeSf         f         fd2Zb ejc        d3ejd                  Zed4eaeSeSf         d5eaeSeSf         d6eaeSeSf         d7eaeSeSf         d8eTd9eTd:eTdeaeTeSf         fd;Zfd<eSd=eaeTeSf         deSfd>Zgd0e^ej_                 deSfd?Zhd0e^ej_                 d@eSdeSfdAZid0e^ej_                 d@eSdBeSdCeSdDeSdeSfdEZjd0e^ej_                 dFeSd@eSdefdGZkdHdId0e^ej_                 dejZ        dJeSdeSfdKZldLdId0e^ej_                 dejR        dJeSdeSfdMZmdeSdNenfdOZodPedeSfdQZp G dR dSej_                  Zq G dT dUej_                  ZrdVeTdWe`fdXZs G dY dZej_                  Zt G d[ d\ej_                  Zu G d] d^ej_                  Zv G d_ d`ej_                  Zw G da dbej_                  Zxd<eSdce`eS         ddfddZy ejz         ej{        g def          dgh          Z|d~dje`eS         dkeSfdlZ} G dm dnej_                  Z~ G do dpej_                  Zd~dje`eS         dkeSfdqZ G dr dsej_                  Zd0e^ej_                 dte.ez  dueTdz  dej        fdvZ G dw dxej_                  Z G dy dzej_                  Z G d{ d|e          Zdefd}ZdS )    N)BytesIO)override)common_upscale)IOComfyExtensionInputTypes)RECOMMENDED_PRESETSRECOMMENDED_PRESETS_SEEDREAM_4 RECOMMENDED_PRESETS_SEEDREAM_4_0 RECOMMENDED_PRESETS_SEEDREAM_4_5#RECOMMENDED_PRESETS_SEEDREAM_5_LITESEEDANCE2_PRICE_PER_1K_TOKENS SEEDANCE2_REF_VIDEO_PIXEL_LIMITSVIDEO_TASKS_EXECUTION_TIMEGetAssetResponseImage2VideoTaskCreationRequestImageTaskCreationResponseSeedance2TaskCreationRequestSeedanceCreateAssetRequestSeedanceCreateAssetResponse+SeedanceCreateVisualValidateSessionResponse(SeedanceGetVisualValidateSessionResponse(SeedanceVirtualLibraryCreateAssetRequestSeedream4OptionsSeedream4TaskCreationRequestTaskAudioContentTaskAudioContentUrlTaskCreationResponseTaskImageContentTaskImageContentUrlTaskStatusResponseTaskTextContentTaskVideoContentTaskVideoContentUrlText2ImageTaskCreationRequestText2VideoTaskCreationRequest)ApiEndpointdownload_url_to_image_tensordownload_url_to_video_output"downscale_image_tensor_by_max_sidedownscale_video_to_max_pixelsget_number_of_imagesimage_tensor_pair_to_batchpoll_opsync_opupload_audio_to_comfyapiupload_image_to_comfyapiupload_images_to_comfyapiupload_video_to_comfyapiupscale_video_to_min_pixelsvalidate_image_aspect_ratiovalidate_image_dimensionsvalidate_stringvalidate_video_dimensionsvalidate_video_duration)PromptServerz)/proxy/byteplus/api/v3/images/generationsx      seedream-5-0-260128seedream-4-5-251128seedream-4-0-250828)seedream 5.0 liter?   r@   )r>   r?   r@   z1/proxy/byteplus/api/v3/contents/generations/tasksz;/proxy/byteplus-seedance2/api/v3/contents/generations/taskszdreamina-seedance-2-0-260128z!dreamina-seedance-2-0-fast-260128)Seedance 2.0Seedance 2.0 Fastseedance-1-0-lite-t2v-250428seedance-1-0-lite-i2v-250428videomodel_id
resolutionindexreturnc                    t          j        |          }|sdS |                    |          }|sdS 	 |                                 \  }}n# t          $ r Y dS w xY w||z  }|                    d          }	|                    d          }
|	r'||	k     r!t	          d| d| d| d|dd	|	dd
          |
r'||
k    r#t	          d| d| d| d|dd|
dd          dS dS )zcValidate reference video pixel count against Seedance 2.0 model limits for the selected resolution.NminmaxReference video z is too small: xz = ,z) total pixels. Minimum for this model is z total pixels.z is too large: z) total pixels. Maximum for this model is z) total pixels. Try downscaling the video.)r   getget_dimensions	Exception
ValueError)rF   rG   rH   rI   model_limitslimitswhpixelsmin_pxmax_pxs              ?/home/wildlama/comfy/ComfyUI/comfy_api_nodes/nodes_bytedance.py_validate_ref_video_pixelsr]   d   s   37AAL j))F ##%%11   UFZZFZZF 
&6//Bu B BQ B B B BvX B B)/AB B B
 
 	
  
&6//]u ] ]Q ] ] ] ]vX ] ])/\] ] ]
 
 	

 
//s   A 
AAimagec                 v    t          | ddd           t          | d          } t          | dddd           | S )	zOAuto-downscale a Seedance image input to the per-side limits, then validate it.      rb   ra   Fstrictp  )max_side,  	min_width
min_height	max_width
max_height)r6   r+   r7   )r^   s    r\   _prepare_seedance_imagern      sJ    vveDDDD.utDDDEessd_cddddL    )   	   )   r=   )   rs   )r=   rr   )rq   rp   )   rq   16:94:31:13:49:1621:9i  i  i8  480p720p1080pratioc                 B   t           |          }|t          vr4|j        d         |j        d         z  t          t          fd          }t          |         \  }}||k    rt	          ||z  |z            |}}n|t	          ||z  |z            }}||dz  z
  ||dz  z
  fS )aU  Exact supported output (width, height) for (resolution, ratio).

    The shorter side equals the resolution number (e.g. 1080p 16:9 -> 1920x1080). For ratio
    "adaptive" (or any unexpected value) the ratio is derived from the image's own aspect, snapped
    to the nearest supported ratio, so the output keeps the frame's orientation.
    c                 r    t          t          |          d         t          |          d         z  z
            S )Nr   rs   )absSEEDANCE2_RATIO_WH)kaspects    r\   <lambda>z(_seedance2_target_dims.<locals>.<lambda>   s3    c:LQ:OPQ:RUghiUjklUm:mpv:v6w6w ro   )keyra   )SEEDANCE2_RES_SHORT_SIDEr   shaperL   round)	rH   r   r^   shortrwrhout_wout_hr   s	           @r\   _seedance2_target_dimsr      s     %Z0E&&&R5;r?2&,w,w,w,wxxx&FB	RxxURZ"_--uueEBJO44u519eeai///ro   widthheightc                     |                      dd          }t          |||dd          }|                     dd          S )zPCenter-crop to the target aspect and resize to exactly width x height (lanczos).rs   lanczoscenter)movedimr   )r^   r   r   samplesresizeds        r\   _resize_to_exactr      s>    mmB""GWeVYIIG??1b!!!ro   cls	asset_idsc                   K   i }i }i }t          |d          D ]\  }}|pd                                }|st          | t          d|           t                     d{V }|j        dk    rE|j        rd|j        j         d	|j        j         nd}	t          d
| d| d|j         d|	           d| }
|j
        dk    r|
||<   |j
        dk    r|
||<   |j
        dk    r|
||<   |||fS )zLook up each asset, validate Active status, group by asset_type.

    Returns (image_assets, video_assets, audio_assets), each mapping asset_id -> "asset://<asset_id>".
    rs    /proxy/seedance/assets/pathresponse_modelNActive z: zReference asset z (Id=z) is not Active (Status=).asset://ImageVideoAudio)	enumeratestripr0   r(   r   statuserrorcodemessagerT   
asset_type)r   r   image_assetsvideo_assetsaudio_assetsiraw_idasset_idresultextra	asset_uris              r\   _resolve_reference_assetsr      s|      $&L#%L#%Ly!,, / /	6Lb'')) 	AxAABBB+
 
 
 
 
 
 
 
 

 =H$$GM|[C)CCV\-ACCCY[ErrrrrZ`Zgrrkprrsss)x))	''%.L""'))%.L""'))%.L"|33ro   z\basset ?(\d{1,2})\breference_assetsimage_asset_urisvideo_asset_urisaudio_asset_urisn_reference_imagesn_reference_videosn_reference_audiosc                 \   |}|}|}	i }
|                                  D ]\  }}|pd                                }|s	 t          |                    dd          d                   }n# t          $ r Y Uw xY w||v r|dz  }d| |
|<   k||v r|dz  }d| |
|<   }||v r|	dz  }	d|	 |
|<   |
S )aE  Map asset slot number (from 'asset_N' keys) to its positional label.

    Asset entries are appended to `content` after the reference_images/videos/audios,
    so their 1-indexed labels continue from the count of existing same-type refs:
    one reference_images entry + one Image-type asset -> asset labelled "Image 2".
    r   _rs   r   zImage zVideo zAudio )itemsr   intrsplitrT   )r   r   r   r   r   r   r   image_nvideo_naudio_nlabelsslot_keyr   r   slot_nums                  r\   _build_asset_labelsr      s     !G G GF,2244 2 2&Lb'')) 		8??3222677HH 	 	 	H	'''qLG111F8)))qLG111F8)))qLG111F8Ms   )A&&
A32A3promptr   c                 `    s| S dddt           ffd}t                              ||           S )zJCase-insensitively replace 'assetNN' (1-2 digit) tokens with their labels.mzre.Match[str]rJ   c                                          t          |                     d                    |                     d                    S )Nrs   r   )rQ   r   group)r   r   s    r\   _subz!_rewrite_asset_refs.<locals>._sub   s1    zz#aggajj//1771::666ro   )str_ASSET_REF_REsub)r   r   r   s    ` r\   _rewrite_asset_refsr      sT     7 7C 7 7 7 7 7 7 T6***ro   c                 V  K   t          | t          dd          t                     d {V }t                              d|j                   d|j         }t          | t          d|j                   t          d	 d
gdgt          t          t          z  dz
  t          dz
  |
  
         d {V }|j        st          d|j         d          t                              d|j                   t          j                            d|j         | j        j                   |j        S )Nz(/proxy/seedance/visual-validate/sessionsPOSTr   methodr   z/Seedance authentication required. Open link: %sz@Open this link in your browser and complete face verification:

z)/proxy/seedance/visual-validate/sessions/r   c                     | j         S Nr   rs    r\   r   z._obtain_group_id_via_h5_auth.<locals>.<lambda>      18 ro   	completedfailedrs   )r   status_extractorcompleted_statusesfailed_statusespoll_intervalmax_poll_attemptsestimated_duration
extra_textzSeedance session z completed without a group_idz1Seedance authentication complete. New GroupId: %sz&Authentication complete. New GroupId: )r0   r(   r   loggerwarningh5_linkr/   
session_idr   _VERIFICATION_POLL_INTERVAL_SEC_VERIFICATION_POLL_TIMEOUT_SECgroup_idRuntimeErrorr;   instancesend_progress_texthidden	unique_id)r   sessionh5_textr   s       r\   _obtain_group_id_via_h5_authr     sr     CFSSSB        G
 NNDgoVVVdSZSbddGYWEWYYZZZ?++'=!
59=\\`aa9A=        F ? b`w/A```aaa
NNFXXX,,BBBCJDX   ?ro   r   c                    K   |r(|                                 r|                                 S t          |            d {V S r   )r   r   )r   r   s     r\   _resolve_group_idr   $  sO        HNN$$  ~~-c222222222ro   urlnamer   c                   K   t          ||||pd           }t          | t          dd          t          |           d {V }|j        S )N)r   r   r   r  z/proxy/seedance/assetsr   r   r   data)r   r0   r(   r   r   )r   r   r   r  r   reqr   s          r\   _create_seedance_assetr  *  s       %\T	  C 1&AAA2	        F ?ro   r   c                    K   t          | t          d|           t          d dgdgddd| d	| 
	  	         d{V S )z=Poll the newly created asset until its status becomes Active.r   r   c                     | j         S r   r   r   s    r\   r   z(_wait_for_asset_active.<locals>.<lambda>G  r   ro   r   Failedrb   i  z/Waiting for asset pre-processing...

asset_id: 

group_id: )r   r   r   r   r   r   r   N)r/   r(   r   )r   r   r   s      r\   _wait_for_asset_activer  A  s      =8==>>>'++$:!
ixii_gii
 
 
 
 
 
 
 
 
 
ro   zUploading image
wait_labelr  c          	        K   t          | ||           d{V }|                                                                                                                    t
          j                  }t          j                    }|	                    t          t          |j                                                d                     |	                    d           |	                    |                                                                           |                                }t#          | t%          dd          t&          t)          ||          	           d{V }t+          | |j        d
           d{V  d|j         S )zHUpload an image into the caller's per-customer Seedance virtual library.r  Nzutf-8    &/proxy/seedance/virtual-library/assetsr   r   )r   hashr  virtual-libraryr   r   )r2   detachcpu
contiguoustotorchfloat32hashlibsha256updater   tupler   encodenumpytobytes	hexdigestr0   r(   r   r   r  r   )r   r^   r  
public_url
normalizeddigest
image_hashcreate_resps           r\   ,_seedance_virtual_library_upload_image_assetr'  P  s      0UzRRRRRRRRRJ##%%002255emDDJ^F
MM#eJ,--..55g>>???
MM%
MM*""$$,,..///!!##JA&QQQ25*:VVV	        K !k&:EV
W
W
WWWWWWWW,k*,,,ro   zUploading videoc          
        K   t                      }|                    |t          j        j        t          j        j                   t          j        |	                                          
                                }t          | ||           d {V }t          | t          dd          t          t          ||d                     d {V }t!          | |j        d	
           d {V  d|j         S )N)formatcodecr  r  r   r   r   )r   r  r   r  r  r  r   )r   save_tor	   VideoContainerMP4
VideoCodecH264r  r  	getbufferr!  r4   r0   r(   r   r   r  r   )r   rF   r  buf
video_hashr"  r&  s          r\   ,_seedance_virtual_library_upload_video_assetr3  h  s      ))C	MM#e26e>N>SMTTT00::<<J/UzRRRRRRRRRJA&QQQ25*:bijjj	        K !k&:EV
W
W
WWWWWWWW,k*,,,ro   has_video_inputc                 j    t          j        | |f          dS dt          dt          dz  ffd}|S )z;Returns a price_extractor closure for Seedance 2.0 poll_op.NresponserJ   c                 @    | j         d S | j         j        dz  z  dz  S )NgzG?g     @@)usagetotal_tokens)r6  rates    r\   	extractorz-_seedance2_price_extractor.<locals>.extractor  s*    >!4~*T1D87BBro   )r   rQ   r"   float)rG   r4  r;  r:  s      @r\   _seedance2_price_extractorr=  |  sc    (,h-HIID|tC. C54< C C C C C C
 ro   r6  c                    | j         rAd| j         d          d| j         d          }t          j        |           t          |          t          j        d| j        d         d                    | j        d         d         S )Nz ByteDance request failed. Code: r   z, message: r   z'ByteDance task succeeded, image URL: %sr   r   )r   logginginfor   r  )r6  	error_msgs     r\   get_image_url_from_responserB    s    ~ &ux~f7MuuZbZhirZsuu	Y9%%%L:HM!<LU<STTT=E""ro   c                   j    e Zd Zed             Zedededededededed	ed
e	j
        fd            ZdS )ByteDanceImageNodec                    t          j        ddddt           j                            ddg          t           j                            dd	d
          t           j                            dd t
          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        j        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*+          d	,
  
        S )-NrD  zByteDance Imagepartner/image/ByteDancez>Generate images using ByteDance models via api based on promptmodelzseedream-3-0-t2i-250415optionsr   Tz*The text prompt used to generate the image	multilinetooltipsize_presetc                     g | ]\  }}}|	S  rO  .0labelr   s      r\   
<listcomp>z4ByteDanceImageNode.define_schema.<locals>.<listcomp>  s    JJJ{uaUJJJro   zHPick a recommended size. Select Custom to use the width and height belowrI  rL  r            @   QCustom width for image. Value is working only if `size_preset` is set to `Custom`defaultrL   rM   steprL  r   RCustom height for image. Value is working only if `size_preset` is set to `Custom`seedr   rs   zSeed to use for generationr[  rL   rM   r\  display_modecontrol_after_generaterL  optionalguidance_scale      @g      ?      $@g{Gz?z;Higher value makes the image follow the prompt more closelyr[  rL   rM   r\  ra  rL  rc  	watermarkFz7Whether to add an "AI generated" watermark to the imager[  rL  rc  advancedz{"type":"usd","usd":0.03})expr
node_iddisplay_namecategorydescriptioninputsoutputsr   is_api_nodeprice_badgeis_deprecated)r   SchemaCombor   Stringr
   IntNumberDisplaynumberFloatBooleanr   OutputHiddenauth_token_comfy_orgapi_key_comfy_orgr   
PriceBadger   s    r\   define_schemaz ByteDanceImageNode.define_schema  s   y(*.Xw1J0KLL	"H    
 !JJ6IJJJf   
  o     p    "!#!1!8+/8!  
 
 $!#!1!8Y!  	 	 
  !U!! !  c8t !! 	.	+	#
 4   UK
 K
 K
 K	
ro   rG  r   rM  r   r   r^  rd  rh  rJ   c	                   K   t          |dd           d x}	}
t          D ]\  }}}||k    r||}
}	 n|	|
9||}
}	d|	cxk    rdk    rn nd|
cxk    rdk    sn t          d|	 d|
 d          t          |||	 d|
 |||	          }t	          | t          t          d
          |t                     d {V }t          j	        t          t          |                     d {V           S )NTrs   strip_whitespace
min_lengthrV  rW  zCustom size out of range: rO   z<. Both width and height must be between 512 and 2048 pixels.)rG  r   sizer^  rd  rh  r   r   r  r   )r8   r
   rT   r&   r0   r(   BYTEPLUS_IMAGE_ENDPOINTr   r   
NodeOutputr)   rB  )r   rG  r   rM  r   r   r^  rd  rh  rW   rX   rR  twthpayloadr6  s                   r\   executezByteDanceImageNode.execute  s      	!DDDDA0 	 	ME2r##21 $ 9	&qA1$$$$$$$$$cQ.>.>.>.>$.>.>.>.> wwwQwww   0)
 
 
 !4VDDD4	
 
 
 
 
 
 
 
 
 }#?@[\d@e@e#f#fffffffgggro   N)__name__
__module____qualname__classmethodr  r   r   r<  boolr   r  r  rO  ro   r\   rD  rD    s        L
 L
 [L
\ 'h'h 'h 	'h
 'h 'h 'h 'h 'h 
'h 'h 'h ['h 'h 'hro   rD  c                       e Zd Zed             Zeded         d         dddddddf	d	ed
edej        dz  dede	de	dede	de	de
de
dej        fd            ZdS )ByteDanceSeedreamNodec                    t          j        ddddt           j                            dt	          t
                                                              t           j                            ddd	d
          t           j                            ddd          t           j                            dd t          D             d          t           j
                            ddddddd          t           j
                            ddddddd          t           j                            dddgd d!          t           j
                            d"d#d#d$d#t           j        j        d%d&          t           j
                            d'd(d(d)d#t           j        j        dd*d+	  	        t           j                            d,d-d.dd/          t           j                            d0dd1dd/          gt           j                                        gt           j        j        t           j        j        t           j        j        gdt          j        t          j        dg2          d34          d5
  
        S )6Nr  ByteDance Seedream 4.5 & 5.0rF  \Unified text-to-image generation and precise single-sentence editing at up to 4K resolution.rG  rH  r   Tr   -Text prompt for creating or editing an image.rK  r[  rL  r^   zjInput image(s) for image-to-image generation. Reference image(s) for single or multi-reference generation.rL  rc  rM  c                     g | ]\  }}}|	S rO  rO  rP  s      r\   rS  z7ByteDanceSeedreamNode.define_schema.<locals>.<listcomp>+  s    UUU{uaUUUUro   IPick a recommended size. Select Custom to use the width and height below.rT  r   rW  rU  `  ra   rY  )r[  rL   rM   r\  rL  rc  r     r]  sequential_image_generationdisabledautozGroup image generation mode. 'disabled' generates a single image. 'auto' lets the model decide whether to generate multiple related images (e.g., story scenes, character variations).)rI  rL  rc  
max_imagesrs      zMaximum number of images to generate when sequential_image_generation='auto'. Total images (input + generated) cannot exceed 15.rg  r^  r   r_  Seed to use for generation.r`  rh  F8Whether to add an "AI generated" watermark to the image.ri  fail_on_partialSIf enabled, abort execution if any requested images are missing or return an error.widgets  
                (
                  $price := $contains(widgets.model, "5.0 lite") ? 0.035 :
                            $contains(widgets.model, "4-5") ? 0.04 : 0.03;
                  {
                    "type":"usd",
                    "usd": $price,
                    "format": { "suffix":" x images/Run", "approximate": true }
                  }
                )
                
depends_onrk  rl  )r   rv  rw  r   listSEEDREAM_MODELSkeysrx  r   r   ry  rz  r{  r}  r~  r  r  r  r   r  PriceBadgeDependsr  s    r\   r  z#ByteDanceSeedreamNode.define_schema  s   y+7.v !5!5!7!788    	"K	     S!	    !UU6TUUUg   
  o!     p!    1'0B "     !#!1!8I!  
 
 "!#!1!8+/9!  
 
 
  !V!! !   
  % q!! !  ]Un !! 	.	+	#
 /	BBB
   es
 s
 s
 s	
ro   Nr   rW  r  rs   FTrG  r   r^   rM  r   r   r  r  r^  rh  r  rJ   c                 .  K   t           |         }t          |dd           d x}}t          D ]\  }}}||k    r||}} n||||}}||z  }|dz  }d|v sd|v r|dk     rt          d|d	d
          d|v r|dk     rt          d|d	d
          d|v rdnd}||k    rt          d|dz  d	d|d	d
          |t	          |          nd}|dk    rdnd}||k    rt          d| d| d          |dk    r||z   dk    rt          d          g }|r/|D ]}t          |dd           t          | ||d            d {V }t          | t          t          d!"          t          t          |||| d#| |	|t          |$          |
|dk    rd%nd &	  	        '           d {V }t          |j                  dk    r4t          j        t#          t%          |                     d {V           S d( |j        D             }|rZt          |          t          |j                  k     r5t'          d)t          |           d*t          |j                   d+          t          j        t)          j        d, |D              d {V                     S )-NTrs   r      .Aseedream-4-5seedream-5-0 @8 ?Minimum image resolution for the selected model is 3.68MP, but .2fMP provided.seedream-4-0  MMinimum image resolution that the selected model can generate is 0.92MP, but i    z3Maximum image resolution for the selected model is i@B zMP, but r   r>      
   Maximum of % reference images are supported, but 
 received.r  r  \The maximum number of generated images plus the number of reference images cannot exceed 15.rs   r=   r=   rs   	image/pngr  	mime_typer   r   rO   r  png)	rG  r   r^   r  r^  r  #sequential_image_generation_optionsrh  output_formatr  c                 j    g | ]0}t          |t                    d |v t          |d                    1S r   
isinstancedictr   rQ  ds     r\   rS  z1ByteDanceSeedreamNode.execute.<locals>.<listcomp>  =    [[[!
1d8K8K[PUYZPZPZAeHPZPZPZro   Only  of $ images were generated before error.c                 <   K   g | ]}t          |           d {V S r   r)   rQ  r   s     r\   rS  z1ByteDanceSeedreamNode.execute.<locals>.<listcomp>  8      '\'\'\RS.J1.M.M(M(M(M(M(M(M'\'\'\ro   )r  r8   r   rT   r-   r6   r3   r0   r(   r  r   r   r   lenr  r   r  r)   rB  r   r  cat)r   rG  r   r^   rM  r   r   r  r  r^  rh  r  rW   rX   rR  r  r  out_num_pixelsmp_provided
max_pixelsn_input_imagesmax_num_of_imagesreference_images_urlsr   r6  urlss                             r\   r  zByteDanceSeedreamNode.execute  s       &!DDDDA; 	 	ME2r##21 $ 9	&qAQ${2e##~'>'>NU\D\D\sVaOssss   U""~'>'>5"45 5 5   $2U#:#:ZZ

J&&5jS\F\f 5 5"45 5 5   9>8I-e444q"'+@"@"@BBb---p/ppVdppp   '&00^j5PSU5U5Un   !# 	 ? ?+Avv>>>>*C)%	+ + + % % % % % %! !4VDDD4-+ZZAZZ,G4DPZ4[4[4[#',0E'E'Eee4
 
 
	
 
 
 
 
 
 
 
 
  x}""='CD_`hDiDi'j'j!j!j!j!j!j!jkkk[[x}[[[ 	ps4yy3x}+=+===ns4yynnc(-6H6Hnnnooo}UY'\'\W['\'\'\'\'\'\'\'\'\]]^^^ro   )r  r  r  r  r  r   r   r   r   r   r  r   r  r  rO  ro   r\   r  r    s"       t
 t
 [t
l 
 %)9!<Q?+5 $S_ S_S_ S_ {T!	S_
 S_ S_ S_ &)S_ S_ S_ S_ S_ 
S_ S_ S_ [S_ S_ S_ro   r  max_ref_imagespresetsc                    t           j                            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t           j        j        d          t           j                            dt           j                            t           j                            d          d t          d| dz             D             d          d|  d          t           j
                            dddd          gS ) NrM  c                     g | ]\  }}}|	S rO  rO  rP  s      r\   rS  z*_seedream_model_inputs.<locals>.<listcomp>  s    666{uaU666ro   r  rT  r   rW  rU  r  ra   rY  rZ  r   r  r]  r  rs   zMaximum number of images to generate. With 1, exactly one image is produced. With >1, the model generates between 1 and max_images related images (e.g., story scenes, character variations). Total images (input + generated) cannot exceed 15.)r[  rL   rM   r\  ra  rL  imagesr^   c                     g | ]}d | S )image_rO  r  s     r\   rS  z*_seedream_model_inputs.<locals>.<listcomp>  s    JJJ|||JJJro   r   namesrL   zTOptional reference image(s) for image-to-image or multi-reference generation. Up to z images.)templaterL  r  Fr  Tr[  rL  rj  )r   rw  r   ry  rz  r{  AutogrowTemplateNamesr   ranger}  r  r  s     r\   _seedream_model_inputsr    sx   
66g666_ 	 	
 	

 	g 	 	
 	
 	h 	 	
 	
 	)0A 	 	
 	
 	[..w''JJU1nq6H-I-IJJJ /  
.#. . . 	 		
 		
 	
i	 	 	
 	
Y2 2ro   c                   `    e Zd Zed             Ze	 	 ddedededede	j
        f
d	            Zd
S )ByteDanceSeedreamNodeV2c                    t          j        ddddt           j                            dddd	          t           j                            d
t           j                            dt          dt                              t           j                            dt          dt                              t           j                            dt          dt                              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        d
g          d          	  	        S ) Nr  r  rF  r  r   Tr   r  r  rG  rA   r  r  r?   r  r@   rH  r^  r   r_  rs   r  r[  rL   rM   r\  ra  rb  rL  rh  Fr  r  r  r  r  	rm  rn  ro  rp  rq  rr  r   rs  rt  )r   rv  rx  r   DynamicComboOptionr  r   r   r   ry  rz  r{  r}  r   r~  r  r  r  r   r  r  r  s    r\   r  z%ByteDanceSeedreamNodeV2.define_schema  s   y-7.v	"K	     %%../2"Nqrrr  ..12"Nnooo  ..12"Nnooo  &  " "!#!1!8+/9  	 	 
  !V!	 !  E(T !! 	.	+	#
 /	BBB
  oE
 E
 E
 E	
ro   r   Fr   rG  r^  rh  rJ   c                   K   t          |dd           t          |d                  }t          |         }|                    d|d         d                   }|                    dd          }|                    d	d          }	|                    d
d          }
|
dk    rdnd}|                    d          pi }|                    dd          }d x}}|D ]\  }}}||k    r||}} n||||	}}||z  }|dz  }d|v sd|v r|dk     rt	          d|dd          d|v r|dk     rt	          d|dd          |dk    rt	          d|dd          d |                                D             }t          d |D                       }|dk    rdnd }||k    rt	          d!| d"| d#          |dk    r||
z   d$k    rt	          d%          g }|r0|D ]}t          |d&d'           t          | ||d(d)*           d {V }t          | t          t          d+,          t          t          |||| d-| ||t          |
.          |/          0           d {V }t          |j                  dk    r4t#          j        t'          t)          |                     d {V           S d1 |j        D             }|rZt          |          t          |j                  k     r5t+          d2t          |           d3t          |j                   d4          t#          j        t-          j        d5 |D              d {V                     S )6NTrs   r  rG  rM  r   r   rW  r   r  r  r  r  r  Fr  r  r  r  r  r  r  r  r  r  r  z@Maximum image resolution for the selected model is 16.78MP, but c                     g | ]}||S r   rO  rQ  ts     r\   rS  z3ByteDanceSeedreamNodeV2.execute.<locals>.<listcomp>  s    +]+]+]!q}A}}}ro   c              3   4   K   | ]}t          |          V  d S r   )r-   r   s     r\   	<genexpr>z2ByteDanceSeedreamNodeV2.execute.<locals>.<genexpr>  s+      LL1!44LLLLLLro   r>   r  r  r  r  r  r  r  r  r  r  zUploading reference images)r  r  r  r   r   rO   r  )rG  r   r^   r  r^  r  r  rh  r  c                 j    g | ]0}t          |t                    d |v t          |d                    1S r  r  r  s     r\   rS  z3ByteDanceSeedreamNodeV2.execute.<locals>.<listcomp>  r  ro   r  r  r  c                 <   K   g | ]}t          |           d {V S r   r  r  s     r\   rS  z3ByteDanceSeedreamNodeV2.execute.<locals>.<listcomp>  r  ro   )r8   r  SEEDREAM_PRESETSrQ   rT   valuessumr6   r3   r0   r(   r  r   r   r   r  r  r   r  r)   rB  r   r  r  )r   r   rG  r^  rh  rG   r  rM  r   r   r  r  images_dictr  rW   rX   rR  r  r  r  r  image_tensorsr  r  r  tensorr6  r  s                               r\   r  zByteDanceSeedreamNodeV2.execute`  s      	!DDDD"5>2"8,iiwqz!}==		'4((8T**YY|Q//
4>!OOjj#ii))/R))$5u==A$ 	 	ME2r##21 $ 9	&qAQ${2h&&.H*D*D.[bJbJboR]oooo   X%%.6*A*A5"45 5 5   J&&pS^pppp   ,^+]{7I7I7K7K+]+]+]LLmLLLLL"*.C"C"CBB---p/ppVdppp   '&00^j5PSU5U5Un   ,. 		' D D+FFFCCCC*C)%7+ + + % % % % % %! !4VDDD4-+ZZAZZ,G4DPZ4[4[4[#	 	 		
 
 
 
 
 
 
 
 
 x}""='CD_`hDiDi'j'j!j!j!j!j!j!jkkk[[x}[[[ 	ps4yy3x}+=+===ns4yynnc(-6H6Hnnnooo}UY'\'\W['\'\'\'\'\'\'\'\'\]]^^^ro   N)r   F)r  r  r  r  r  r   r  r   r  r   r  r  rO  ro   r\   r  r    s        F
 F
 [F
P 
 W_ W_W_ W_ 	W_
 W_ 
W_ W_ W_ [W_ W_ W_ro   r  c                   r    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dedej	        fd            Z
dS )ByteDanceTextToVideoNodec                    t          j        ddddt           j                            dg dd          t           j                            d	d
d          t           j                            dg dd          t           j                            dg dd          t           j                            ddddddt           j        j                  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
#          g	t           j
                                        gt           j        j        t           j        j        t           j        j        gd
t           (	  	        S ))Nr  zByteDance Text to Videopartner/video/ByteDancez=Generate video using ByteDance models via api based on promptrG  )seedance-1-5-pro-251215seedance-1-0-pro-250528rD   seedance-1-0-pro-fast-251015r  rI  r[  r   T+The text prompt used to generate the video.rJ  rH   r|   #The resolution of the output video.rT  aspect_ratioru   %The aspect ratio of the output video.durationrb   r=      rs   ,The duration of the output video in seconds.r[  rL   rM   r\  rL  ra  r^  r   r_  r  r`  camera_fixedFSpecifies whether to fix the camera. The platform appends an instruction to fix the camera to your prompt, but does not guarantee the actual effect.ri  rh  8Whether to add an "AI generated" watermark to the video.generate_audio@This parameter is ignored for any model except seedance-1-5-pro.r  )r   rv  rw  r   rx  ry  rz  sliderr{  r}  r   r~  r  r  r  r   PRICE_BADGE_VIDEOr  s    r\   r  z&ByteDanceTextToVideoNode.define_schema  s	   y.2.W   ;  	 	 	"I    
  555A   
 "IIIC   
 J!#!1!8    "!#!1!8+/9!  
 
 
  "!b!! !   
  !V!! !   
  $!^!! !  {DL !! 	.	+	#
 )gT
 T
 T
 T	
ro   FrG  r   rH   r  r  r^  r  rh  r  rJ   c
                   K   |dk    r|dk     rt          d          t          |dd           t          |g d           | d| d	| d
| d| dt          |                                           dt          |                                           }t          | t          |t          |          g|dk    r|	nd           t          dt          j
        t          |         |         |dz  z                                 d {V S )Nr  rr   =Minimum supported duration for Seedance 1.5 Pro is 4 seconds.Trs   r  rH   r   r  r^  camerafixedrh   --resolution 	 --ratio  --duration  --seed  --camerafixed  --watermark textrG  contentr  rf  r  r   )rT   r8   raise_if_text_paramsr   lowerprocess_video_taskr'   r#   rM   mathceilr   )
r   rG  r   rH   r  r  r^  r  rh  r  s
             r\   r  z ByteDanceTextToVideoNode.execute  s      ---(Q,,\]]]!DDDDV%l%l%lmmm  4 4&4 4#4 4 #4 4 	4 4
 !..44664 4 y>>//114 4 	 (1(f555616:S1S1S~~Y]  
  #1di0J50QR\0]ailpap0q&r&rss
 
 
 
 
 
 
 
 
 	
ro   NF)r  r  r  r  r  r   r   r  r   r  r  rO  ro   r\   r  r    s        U
 U
 [U
n   %"
 "
"
 "
 	"

 "
 "
 "
 "
 "
 "
 
"
 "
 "
 ["
 "
 "
ro   r  c                       e Zd Zed             Ze	 ddededej        dededed	ed
e	de	de	de
j        fd            ZdS )ByteDanceImageToVideoNodec                    t          j        ddddt           j                            dg dd          t           j                            d	d
d          t           j                            dd          t           j                            dg dd          t           j                            dg dd          t           j                            ddddddt           j        j                  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
&          g
t           j                                        gt           j        j        t           j        j        t           j        j        gd
t"          +	  	        S ),Nr9  zByteDance Image to Videor  zGGenerate video using ByteDance models via api based on image and promptrG  )r  r  rE   r  r  r  r   Tr  rJ  r^   %First frame to be used for the video.rL  rH   r|   r  rT  r  adaptiverv   rw   rx   ry   rz   r{   r  r  rb   r=   r  rs   r  r  r^  r   r_  r  r`  r  Fr  ri  rh  r  r  r   r  r   rv  rw  r   rx  r   ry  rz  r!  r{  r}  r   r~  r  r  r  r   r"  r  s    r\   r  z'ByteDanceImageToVideoNode.define_schema=  s)   y/3.a   ;  	 	 	"I    
 C     555A   
 "UUUC   
 J!#!1!8    "!#!1!8+/9!  
 
 
  "!b!! !   
  !V!! !   
  $!^!! !  CHT !! 	.	+	#
 )oX
 X
 X
 X	
ro   FrG  r   r^   rH   r  r  r^  r  rh  r  rJ   c                   K   |dk    r|dk     rt          d          t          |dd           t          |g d           t          |ddd	d	
           t	          |ddd           t          | |d           d {V d         }| d| d| d| d| dt          |                                           dt          |	                                           }t          | t          |t          |          t          t          |                    g|dk    r|
nd           t          dt          j        t           |         |         |dz  z                                 d {V S )Nr  rr   r$  Trs   r  r%  rh   rf   ri   r`   rc   Frd   r  r   r'  r(  r)  r*  r+  r,  r-  r  )	image_urlr/  rf  r1  )rT   r8   r2  r7   r6   r3   r   r3  r4  r   r#   r    r!   rM   r5  r6  r   )r   rG  r   r^   rH   r  r  r^  r  rh  r  rA  s               r\   r  z!ByteDanceImageToVideoNode.execute  s      ---(Q,,\]]]!DDDDV%l%l%lmmm!%33RVcghhhh#E66%HHHH4S%ANNNNNNNNNPQR	 4 4&4 4#4 4 #4 4 	4 4
 !..44664 4 y>>//114 4 	 (2(f5557GRejsRtRtRt7u7u7uv16:S1S1S~~Y]  
  #1di0J50QR\0]ailpap0q&r&rss
 
 
 
 
 
 
 
 
 	
ro   Nr7  r  r  r  r  r  r   r   r   r   r  r   r  r  rO  ro   r\   r9  r9  ;  s        Y
 Y
 [Y
v   %'
 '
'
 '
 {	'

 '
 '
 '
 '
 '
 '
 '
 
'
 '
 '
 ['
 '
 '
ro   r9  c                       e Zd Zed             Ze	 ddededej        dej        deded	ed
ede	de	de	de
j        fd            ZdS )ByteDanceFirstLastFrameNodec                    t          j        ddddt           j                            dg dd          t           j                            d	d
d          t           j                            dd          t           j                            dd          t           j                            dg dd          t           j                            dg dd          t           j                            ddddddt           j        j                  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
(          gt           j                                        gt           j        j        t           j        j        t           j        j        gd
t"          -	  	        S ).NrD  z#ByteDance First-Last-Frame to Videor  z6Generate video using prompt and first and last frames.rG  )r  r  rE   rE   r  r   Tr  rJ  first_framer;  r<  
last_framez$Last frame to be used for the video.rH   r|   r  rT  r  r=  r  r  rb   r=   r  rs   r  r  r^  r   r_  r  r`  r  Fr  ri  rh  r  r  r   r  r?  r  s    r\   r  z)ByteDanceFirstLastFrameNode.define_schema  sA   y1>.Prrr:   
 	"I    
 !C     B     555A   
 "UUUC   
 J!#!1!8    "!#!1!8+/9!  
 
 
  "!b!! !   
  !V!! !   
  $!^!! !  AGR !! 	.	+	#
 )mW
 W
 W
 W	
ro   FrG  r   rF  rG  rH   r  r  r^  r  rh  r  rJ   c                   K   |dk    r|dk     rt          d          t          |dd           t          |g d           ||fD ])}t          |ddd	d	
           t	          |ddd           *t          | t          ||          dd           d {V }| d| d| d| d| dt          |	                                           dt          |
                                           }t          | t          |t          |          t          t          t          |d                             d          t          t          t          |d                             d          g|dk    r|nd           t          dt          j        t"          |         |         |dz  z                                  d {V S )!Nr  rr   r$  Trs   r  r%  rh   rf   ri   r`   rc   Frd   ra   r  r  r'  r(  r)  r*  r+  r,  r-  r   r  rF  rA  rolerG  r/  rf  r1  )rT   r8   r2  r7   r6   r3   r.   r   r3  r4  r   r#   r    r!   rM   r5  r6  r   )r   rG  r   rF  rG  rH   r  r  r^  r  rh  r  r   download_urlss                 r\   r  z#ByteDanceFirstLastFrameNode.execute!  sx      ---(Q,,\]]]!DDDDV%l%l%lmmmz* 	I 	IA%a33RVcghhhh'66%HHHHH7&{J??!	
 
 
 
 
 
 
 
 
  4 4&4 4#4 4 #4 4 	4 4
 !..44664 4 y>>//114 4 	 (2#000$/Bs=YZK[G\G\/]/]/]dqrrr$/Bs=YZK[G\G\/]/]/]dpqqq
 27:S1S1S~~Y]    #1di0J50QR\0]ailpap0q&r&rss
 
 
 
 
 
 
 
 
 	
ro   Nr7  rB  rO  ro   r\   rD  rD    s        X
 X
 [X
t   %3
 3
3
 3
 [	3

 K3
 3
 3
 3
 3
 3
 3
 3
 
3
 3
 3
 [3
 3
 3
ro   rD  c                   t    e Zd Zed             Zedededej        dedededed	e	d
e
j        fd            ZdS )ByteDanceImageReferenceNodec                    t          j        ddddt           j                            dddgd          t           j                            d	d
d          t           j                            dd          t           j                            dddgd          t           j                            dg dd          t           j                            ddddddt           j        j                  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        t          j        g d()          d*+          ,	  	        S )-NrM  z#ByteDance Reference Images to Videor  z1Generate video using prompt and reference images.rG  r  rE   r  r   Tr  rJ  r  zOne to four images.r<  rH   r}   r~   r  rT  r  r=  r  r  rb   r=   r  rs   r  r  r^  r   r_  r  r`  rh  Fr  ri  )rG  r  rH   r  a(  
                (
                  $priceByModel := {
                    "seedance-1-0-pro": {
                      "480p":[0.23,0.24],
                      "720p":[0.51,0.56]
                    },
                    "seedance-1-0-lite": {
                      "480p":[0.17,0.18],
                      "720p":[0.37,0.41]
                    }
                  };
                  $model := widgets.model;
                  $modelKey :=
                    $contains($model, "seedance-1-0-pro")  ? "seedance-1-0-pro" :
                    "seedance-1-0-lite";
                  $resolution := widgets.resolution;
                  $resKey :=
                    $contains($resolution, "720") ? "720p" :
                    "480p";
                  $modelPrices := $lookup($priceByModel, $modelKey);
                  $baseRange := $lookup($modelPrices, $resKey);
                  $min10s := $baseRange[0];
                  $max10s := $baseRange[1];
                  $scale := widgets.duration / 10;
                  $minCost := $min10s * $scale;
                  $maxCost := $max10s * $scale;
                  ($minCost = $maxCost)
                    ? {"type":"usd","usd": $minCost}
                    : {"type":"range_usd","min_usd": $minCost, "max_usd": $maxCost}
                )
                r  r  )r   rv  rw  r   rx  r   ry  rz  r!  r{  r}  r   r~  r  r  r  r   r  r  r  s    r\   r  z)ByteDanceImageReferenceNode.define_schemaZ  s   y1>.K68VW:   
 	"I    
 1     #V,A   
 "UUUC   
 J!#!1!8    "!#!1!8+/9!  
 
 
  !V!! !  [4l !! 	.	+	#
 /8[8[8[\\\" " "Gf
 f
 f
 f	
ro   rG  r   r  rH   r  r  r^  rh  rJ   c	                 4  K   t          |dd           t          |g d           |D ])}	t          |	dddd           t          |	dd	d
           *t	          | |dd           d {V }
| d| d| d| d| dt          |                                           }t          |          gd |
D             }t          | t          ||d           t          dt          j        t          |         |         |dz  z                                 d {V S )NTrs   r  )rH   r   r  r^  rh  rh   rf   ri   r`   rc   Frd   rr   r  r  r'  r(  r)  r*  r,  r-  c           	      f    g | ].}t          t          t          |                     d          /S )r  reference_imagerI  )r    r!   r   r  s     r\   rS  z7ByteDanceImageReferenceNode.execute.<locals>.<listcomp>  s:    vvvfg)<Q)H)H)HO`aaavvvro   r/  rf  r1  )r8   r2  r7   r6   r3   r   r3  r#   r4  r   rM   r5  r6  r   )r   rG  r   r  rH   r  r  r^  rh  r^   
image_urlsrO   s               r\   r  z#ByteDanceImageReferenceNode.execute  s      	!DDDDV%]%]%]^^^ 	M 	ME%essVZgkllll'vveLLLLL4S&QZefffffffff
 4 4&4 4#4 4 #4 4 	4 4
 y>>//114 4 	 (((
vvkuvvv
 (2Z^___"1di0J50QR\0]ailpap0q&r&rss
 
 
 
 
 
 
 
 
 	
ro   NrB  rO  ro   r\   rM  rM  X  s        g
 g
 [g
R "
"
 "
 	"

 "
 "
 "
 "
 "
 
"
 "
 "
 ["
 "
 "
ro   rM  text_paramsc                 F    |D ]}d| d| v rt          d| d          d S )Nz--r   zV is not allowed in the prompt, use the appropriated widget input to change this value.)rT   )r   rS  r   s      r\   r2  r2    sS      999nQnnn    ro   )rG  r  rH   r  r  a  
    (
      $priceByModel := {
        "seedance-1-5-pro": {
          "480p":[0.12,0.12],
          "720p":[0.26,0.26],
          "1080p":[0.58,0.59]
        },
        "seedance-1-0-pro": {
          "480p":[0.23,0.24],
          "720p":[0.51,0.56],
          "1080p":[1.18,1.22]
        },
        "seedance-1-0-pro-fast": {
          "480p":[0.09,0.1],
          "720p":[0.21,0.23],
          "1080p":[0.47,0.49]
        },
        "seedance-1-0-lite": {
          "480p":[0.17,0.18],
          "720p":[0.37,0.41],
          "1080p":[0.85,0.88]
        }
      };
      $model := widgets.model;
      $modelKey :=
        $contains($model, "seedance-1-5-pro")      ? "seedance-1-5-pro" :
        $contains($model, "seedance-1-0-pro-fast") ? "seedance-1-0-pro-fast" :
        $contains($model, "seedance-1-0-pro")      ? "seedance-1-0-pro" :
        "seedance-1-0-lite";
      $resolution := widgets.resolution;
      $resKey :=
        $contains($resolution, "1080") ? "1080p" :
        $contains($resolution, "720")  ? "720p" :
        "480p";
      $modelPrices := $lookup($priceByModel, $modelKey);
      $baseRange := $lookup($modelPrices, $resKey);
      $min10s := $baseRange[0];
      $max10s := $baseRange[1];
      $scale := widgets.duration / 10;
      $audioMultiplier := ($modelKey = "seedance-1-5-pro" and widgets.generate_audio) ? 2 : 1;
      $minCost := $min10s * $scale * $audioMultiplier;
      $maxCost := $max10s * $scale * $audioMultiplier;
      ($minCost = $maxCost)
        ? {"type":"usd","usd": $minCost, "format": { "approximate": true }}
        : {"type":"range_usd","min_usd": $minCost, "max_usd": $maxCost, "format": { "approximate": true }}
    )
    r  rv   resolutionsdefault_ratioc                 ~   t           j                            dddd          t           j                            d| d          t           j                            d	g d
|d          t           j                            ddddddt           j        j                  t           j                            ddd          gS )Nr   Tr   z!Text prompt for video generation.r  rH   zResolution of the output video.rT  r   )rv   rw   rx   ry   rz   r{   r>  z!Aspect ratio of the output video.)rI  r[  rL  r     rr   r  rs   z/Duration of the output video in seconds (4-15).r  r  z-Enable audio generation for the output video.r[  rL  )r   rx  r   rw  ry  rz  r!  r}  rU  rV  s     r\   _seedance2_text_inputsr[  '  s    
	7	 	 	
 	
 	5 	 	
 	

 	MMM!7	 	 	
 	
 	E)0 	 	
 	
 	
C 	 	
 	
7   ro   c            	       V    e Zd Zed             Zededededej	        fd            Z
dS )ByteDance2TextToVideoNodec                    t          j        ddddt           j                            dt           j                            dt          g d                    t           j                            dt          d	d
g                    g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$ByteDance Seedance 2.0 Text to Videor  z@Generate video using Seedance 2.0 models based on a text prompt.rG  rB   r|   rC   r}   r~   KSeedance 2.0 for maximum quality; Seedance 2.0 Fast for speed optimization.rT  r^  r   r_  rs   T_Seed controls whether the node should re-run; results are non-deterministic regardless of seed.r  rh  F(Whether to add a watermark to the video.r  rG  zmodel.resolutionzmodel.durationr    
                (
                  $rate480 := 10044;
                  $rate720 := 21600;
                  $rate1080 := 48800;
                  $m := widgets.model;
                  $pricePer1K := $contains($m, "fast") ? 0.008008 : 0.01001;
                  $res := $lookup(widgets, "model.resolution");
                  $dur := $lookup(widgets, "model.duration");
                  $rate := $res = "1080p" ? $rate1080 :
                           $res = "720p"  ? $rate720 :
                                            $rate480;
                  $cost := $dur * $rate * $pricePer1K / 1000;
                  {"type": "usd", "usd": $cost, "format": {"approximate": true}}
                )
                r  r  )r   rv  r  r   r  r[  ry  rz  r{  r}  r   r~  r  r  r  r   r  r  r  s    r\   r  z'ByteDance2TextToVideoNode.define_schemaM  sn   y/?.Z%%..~?UVoVoVo?p?pqq../BDZ\bdj[kDlDlmm j &   "!#!1!8+/H  
 
 
  !F!	 !  )8 !! 	.	+	#
 /8g8g8ghhh  S<
 <
 <
 <	
ro   rG  r^  rh  rJ   c                 @  K   t          |d         dd           t          |d                  }t          | t          t          d          t          |t          |d                   g|d	         |d
         |d         |d         ||          t                     d {V }t          | t          t           d|j
                   t          d t          |d          d           d {V }t          j        t          |j        j                   d {V           S )Nr   Trs   r  rG  r   r   r-  r  rH   r   r  rG  r0  r  rH   r   r  r^  rh  r  /r   c                     | j         S r   r   r   s    r\   r   z3ByteDance2TextToVideoNode.execute.<locals>.<lambda>      qx ro   Fr4  rq   r   r   price_extractorr   )r8   SEEDANCE_MODELSr0   r(   BYTEPLUS_TASK_ENDPOINTr   r#   r   r/   'BYTEPLUS_SEEDANCE2_TASK_STATUS_ENDPOINTidr"   r=  r   r  r*   r0  	video_url)r   rG  r^  rh  rG   initial_responser6  s          r\   r  z!ByteDance2TextToVideoNode.execute  ss      	h$1MMMM"5>2!(3FCCC-(eHo>>>?$%56 .Gnz*#	 	 	 0"
 "
 "
 
 
 
 
 
 
 ! G__JZJ]__```-//6xQVWWW
 
 
 
 
 
 
 
 
 }#?@P@Z#[#[[[[[[[\\\ro   Nr  r  r  r  r  r  r   r  r   r  r  rO  ro   r\   r]  r]  K  s        =
 =
 [=
~ ]] ] 	]
 
] ] ] [] ] ]ro   r]  c                       e Zd Zed             Ze	 	 	 	 ddedededej	        dz  dej	        dz  d	e
d
e
dej        fd            ZdS )ByteDance2FirstLastFrameNodec                    t          j        ddddt           j                            dt           j                            dt          g dd	                    t           j                            d
t          ddgd	                    gd          t           j                            ddd          t           j                            ddd          t           j                            dddd          t           j                            dd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 )*Nrt  z0ByteDance Seedance 2.0 First-Last-Frame to Videor  zYGenerate video using Seedance 2.0 from a first frame image and optional last frame image.rG  rB   r|   r>  rV  rC   r}   r~   r_  rT  rF  z First frame image for the video.Tr  rG  zLast frame image for the video.first_frame_asset_idr   zaSeedance asset_id to use as the first frame. Mutually exclusive with the first_frame image input.)r[  rL  rc  last_frame_asset_idz_Seedance asset_id to use as the last frame. Mutually exclusive with the last_frame image input.r^  r   r_  rs   r`  r  rh  Fra  r  rb  r  rc  r  r  )r   rv  r  r   r  r[  r   rx  ry  rz  r{  r}  r   r~  r  r  r  r   r  r  r  s    r\   r  z*ByteDance2FirstLastFrameNode.define_schema  s!   y2K.s%%..*23L3L3L\fggg  ../2FF3CS]^^^ 	 j &   !>!   
  =!   
 	*K!     	)J!     "!#!1!8+/H  
 
 
  !F!	 !  e8t !! 	.	+	#
 /8g8g8ghhh  OZ
 Z
 Z
 Z	
ro   Nr   rG  r^  rh  rF  rG  rw  rx  rJ   c                   K   t          |d         dd           t          |d                  }|                                }|                                }||rt          d          ||st          d          ||rt          d          |d	         }	|s|r#|t	          |          }|t	          |          }nd
}	d }
|Ot          |ddd           t          |dd           t          |d         |d	         |          }
t          |g|
R  }|Qt          |ddd           t          |dd           |
t          |d         |d	         |          }
t          |g|
R  }d ||fD             }i }|r6t          | |           d {V \  }}}|D ]}||vrt          d| d          |r	||         }nt          | |d           d {V }t          |d                   t          t          |          d          g}|r9|                    t          t          ||                   d                     nJ|H|                    t          t          t          | |d           d {V           d                     t          | t!          t"          d          t%          |||d         |d         |	|d          ||!          t&          "           d {V }t)          | t!          t*           d#|j         $          t.          d% t1          |d&          d'(           d {V }t3          j        t7          |j        j                   d {V           S ))Nr   Trs   r  rG  zBProvide only one of first_frame or first_frame_asset_id, not both.z7Either first_frame or first_frame_asset_id is required.z@Provide only one of last_frame or last_frame_asset_id, not both.r   r>  r`   rc   Frd   rh   )rj   rk   rH   c                     g | ]}||S rO  rO  )rQ  as     r\   rS  z8ByteDance2FirstLastFrameNode.execute.<locals>.<listcomp>?  s    \\\aZ[\\\\ro   zAsset z is not an Image asset.zUploading first frame.r  r-  r  rF  rI  rG  zUploading last frame.r   r   r  r  re  r  rf  r   c                     | j         S r   r   r   s    r\   r   z6ByteDance2FirstLastFrameNode.execute.<locals>.<lambda>{  rh  ro   ri  rq   rj  )r8   rl  r   rT   rn   r6   r7   r   r   r   r'  r#   r    r!   appendr0   r(   rm  r   r   r/   rn  ro  r"   r=  r   r  r*   r0  rp  )r   rG  r^  rh  rF  rG  rw  rx  rG   request_ratiotarget_dimsasset_ids_to_resolver   r   aidfirst_frame_urlr0  rq  r6  s                      r\   r  z$ByteDance2FirstLastFrameNode.execute  s      	h$1MMMM"5>2399;;17799"';"abbb';VWWW!&9!_```g 	H#6 	H&5kBB%4Z@@
 'M26K&+KPUVVVV)+QTUUUU4U<5H%PW.Zeff.{I[III%+JuUUUU)*PSTTTT&"8|9LeT[n^h"i"iK-jG;GGG
\\,@BU+V\\\') 	L'@FZ'['[![![![![![![L!Q+ L Ll**$%Jc%J%J%JKKK +   	*+?@OO$P[-E% % %      O
 x111-/BBB"  =
  	NN 1lCV6WXXX%      #NN 1"N8O# # #        
 &  	 	 	 ")3FCCC-$%56 .#z*#	 	 	 0"
 "
 "
 
 
 
 
 
 
 ! G__JZJ]__```-//6xQVWWW
 
 
 
 
 
 
 
 
 }#?@P@Z#[#[[[[[[[\\\ro   )NNr   r   )r  r  r  r  r  r  r   r  r   r   r   r   r  r  rO  ro   r\   rt  rt    s        [
 [
 [[
z  +/)-$&#%n] n]n] n] 	n]
 [4'n] K$&n] "n] !n] 
n] n] n] [n] n] n]ro   rt  c           	         g t          | |          t          j                            dt          j                            t          j                            d          g dd                    t          j                            dt          j                            t          j                            d	          g d
d                    t          j                            dt          j                            t          j                            d          g dd                    t          j                            dddd          t          j                            ddddd          t          j                            dt          j                            t          j	                            d          g dd                    S )Nrv  reference_imagesrQ  )	image_1image_2image_3image_4image_5image_6image_7image_8image_9r   r  )r  reference_videosreference_video)video_1video_2video_3reference_audiosreference_audio)audio_1audio_2audio_3auto_downscaleTzAutomatically downscale reference videos that exceed the model's pixel budget for the selected resolution. Aspect ratio is preserved; videos already within limits are untouched.)r[  rc  rL  auto_upscaleFa+  Automatically upscale reference videos that are below the model's minimum pixel count for the selected resolution. Aspect ratio is preserved; videos already meeting the minimum are untouched. Note: upscaling a low-resolution source does not add real detail and may produce lower-quality generations.)r[  rj  rc  rL  r   reference_asset)	asset_1asset_2asset_3asset_4asset_5asset_6asset_7asset_8asset_9)
r[  r   r  r   r  r   r   r   r}  rx  rZ  s     r\   _seedance2_reference_inputsr    s   G	=	I	I	IG
[..011
 
 
  /   	 	
 	
G( 	[..011777 /   	 	
 	
)G8 	[..011777 /   	 	
 	
9GH 	
r	 	 	
 	
IGV 	
) 	 		
 		
WGj 	[..	 122
 
 
  /   	 	
 	
kG Gro   c            	       V    e Zd Zed             Zededededej	        fd            Z
dS )ByteDance2ReferenceNodec                    t          j        ddddt           j                            dt           j                            dt          g dd	                    t           j                            d
t          ddgd	                    g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g          d          	  	        S ) Nr  z)ByteDance Seedance 2.0 Reference to Videor  zGenerate, edit, or extend video using Seedance 2.0 with reference images, videos, and audio. Supports multimodal reference, video editing, and video extension.rG  rB   r|   r>  rv  rC   r}   r~   r_  rT  r^  r   r_  rs   Tr`  r  rh  Fra  r  rb  zmodel.reference_videos)r  input_groupsa  
                (
                  $rate480 := 10044;
                  $rate720 := 21600;
                  $rate1080 := 48800;
                  $m := widgets.model;
                  $hasVideo := $lookup(inputGroups, "model.reference_videos") > 0;
                  $noVideoPricePer1K := $contains($m, "fast") ? 0.008008 : 0.01001;
                  $videoPricePer1K := $contains($m, "fast") ? 0.004719 : 0.006149;
                  $res := $lookup(widgets, "model.resolution");
                  $dur := $lookup(widgets, "model.duration");
                  $rate := $res = "1080p" ? $rate1080 :
                           $res = "720p"  ? $rate720 :
                                            $rate480;
                  $noVideoCost := $dur * $rate * $noVideoPricePer1K / 1000;
                  $minVideoFactor := $ceil($dur * 5 / 3);
                  $minVideoCost := $minVideoFactor * $rate * $videoPricePer1K / 1000;
                  $maxVideoCost := (15 + $dur) * $rate * $videoPricePer1K / 1000;
                  $hasVideo
                    ? {
                        "type": "range_usd",
                        "min_usd": $minVideoCost,
                        "max_usd": $maxVideoCost,
                        "format": {"approximate": true}
                      }
                    : {
                        "type": "usd",
                        "usd": $noVideoCost,
                        "format": {"approximate": true}
                      }
                )
                r  r  )r   rv  r  r   r  r  ry  rz  r{  r}  r   r~  r  r  r  r   r  r  r  s    r\   r  z%ByteDance2ReferenceNode.define_schema  s   y-D.d %%..*78Q8Q8Qaklll  ../78HXbccc 	 j &   "!#!1!8+/H  
 
 
  !F!	 !  5 D !! 	.	+	#
 /KKK":!;  % % %aV
 V
 V
 V	
ro   rG  r^  rh  rJ   c                   K   t          |d         dd           |                    di           }|                    di           }|                    di           }|                    di           }t          | t          |                                                     d {V \  }}	}
|s|s|s|	st          d	          t          |          t          |          z   }|d
k    r3t          d| dt          |           dt          |           d          t          |          t          |	          z   }|dk    r3t          d| dt          |           dt          |	           d          t          |          t          |
          z   }|dk    r3t          d| dt          |           dt          |
           d          |D ]}t          ||                   ||<   t          |d                  }|dk    }|                    d          rd|rbt          j        |i                               |d         i                               d          }|r|D ]}t          ||         |          ||<   |                    d          rd|rbt          j        |i                               |d         i                               d          }|r|D ]}t          ||         |          ||<   d}t          |d          D ]v\  }}||         }t          |||d         |           	 |                                }|dk     rt          d | d!|d"d#          ||z  }]# t
          $ r  t          $ r Y sw xY w|d$k    rt          d%|d"d&          d}t          |d          D ]e\  }}||         }t!          |d'         j        d(                   t!          |d)                   z  }|dk     rt          d*| d!|d"d#          ||z  }f|d$k    rt          d+|d"d&          t%          |||	|
t          |          t          |          t          |                    }t'          |d         |          }t)          |,          g}t          |d          D ]V\  }}|                    t-          t/          t1          | ||         d-| .           d {V /          d01                     Wt          |d          D ]U\  }}|                    t3          t5          t7          | ||         d2| .           d {V /          3                     V|D ]Q}|                    t9          t;          t=          | ||         d4d5d67           d {V /          8                     R|                                D ]4}|                    t-          t/          |/          d01                     5|	                                D ]3}|                    t3          t5          |/          3                     4|
                                D ]3}|                    t9          t;          |/          8                     4t?          | tA          tB          d9:          tE          |||d;         |d         |d<         |d=         ||>          tF          ?           d {V }tI          | tA          tJ           d@|j&         A          tN          dB tQ          ||C          d
D           d {V }tS          j*        tW          |j,        j-                   d {V           S )ENr   Trs   r  r  r  r  r   z;At least one reference image or video or asset is required.rq   zToo many reference images: z	 (images=z, image assets=z). Maximum is 9.r=   zToo many reference videos: z	 (videos=z, video assets=z). Maximum is 3.zToo many reference audios: z	 (audios=z, audio assets=rG  r   r  rH   rM   r  rL   g        g?rN   z is too short: z.1fz#s. Minimum duration is 1.8 seconds.g333333.@z"Total reference video duration is zs. Maximum is 15.1 seconds.waveformr   sample_ratezReference audio z"Total reference audio duration is r-  zUploading image r  r  rQ  rI  zUploading video )rp  mp3
libmp3lamez
audio/mpeg)container_format
codec_namer  )	audio_urlr   r   r  r   r  re  r  rf  r   c                     | j         S r   r   r   s    r\   r   z1ByteDance2ReferenceNode.execute.<locals>.<lambda>  rh  ro   ri  rj  ).r8   rQ   r   r  r  rT   r  rn   rl  r   r,   r5   r   r]   get_durationrS   r   r   r   r   r#   r}  r    r!   r'  r$   r%   r3  r   r   r1   r0   r(   rm  r   r   r/   rn  ro  r"   r=  r   r  r*   r0  rp  )r   rG  r^  rh  r  r  r  r   reference_image_assetsreference_video_assetsreference_audio_assetstotal_imagestotal_videostotal_audiosr   rG   r4  r[   rZ   total_video_durationr   rF   durtotal_audio_durationaudioasset_labelsprompt_textr0  r   rq  r6  s                                  r\   r  zByteDance2ReferenceNode.execute)  s0
      	h$1MMMM 99%7<< 99%7<< 99%7<< 99%7<<Wp&--//00X
 X
 R
 R
 R
 R
 R
 R
N 68N   	\(8 	\AW 	\`v 	\Z[[[+,,s3I/J/JJ!ol o o/00o oADE[A\A\o o o   +,,s3I/J/JJ!ol o o/00o oADE[A\A\o o o   +,,s3I/J/JJ!ol o o/00o oADE[A\A\o o o  
 $ 	S 	SC$;<LS<Q$R$RS!!"5>2&*99%&& 	i+; 	i59(BGGKKER^L_acddhhinooF i+ i iC,IJZ[^J_ag,h,h$S))99^$$ 	g)9 	g59(BGGKKER^L_acddhhinooF g+ g gC,GHXY\H]_e,f,f$S))" 0!44 	 	FAs$S)E&uhl8KQOOO((**99$%v%v%v#%v%v%v%vwww$+$$      $&&wBVwwwwxxx" 0!44 	( 	(FAs$S)EeJ'-b122S}9M5N5NNCSyy !rA!r!rc!r!r!r!rsss C'  $&&wBVwwwwxxx*""" !! !! !!
 
 *%/<HH ---c
   0!44 	 	FAsNN 1"N,S1'=!'='=# # #         +	 	 	      0!44 	 	FAsNN 1"N,S1'=!'='=# # #          
 
 
 
 $ 	 	CNN 1":,S1-2'3&2# # #        
 
 
    *0022 	 	CNN 1c:::*      *0022 	 	CNN +>3+G+G+GHHH    *0022 	 	CNN +>3+G+G+GHHH    ")3FCCC-$%56 .Gnz*#	 	 	 0"
 "
 "
 
 
 
 
 
 
 ! G__JZJ]__```-//6xQ`aaa
 
 
 
 
 
 
 
 
 }#?@P@Z#[#[[[[[[[\\\s   +6M""M98M9Nrr  rO  ro   r\   r  r    s        W
 W
 [W
r n]n] n] 	n]
 
n] n] n] [n] n] n]ro   r  r  r   c                   K   |j         t          v r t                              d|j                    t	          | t          t          d          |t                     d {V }t          | t          t           d|j
                   d |t                     d {V }t          j        t          |j        j                   d {V           S )	NzModel '%s' is deprecated and will be deactivated on May 13, 2026. Please switch to a newer model. Recommended: seedance-1-0-pro-fast-251015.r   r   r  rf  r   c                     | j         S r   r   r   s    r\   r   z$process_video_task.<locals>.<lambda>  r   ro   )r   r   r   )rG  DEPRECATED_MODELSr   r   r0   r(   rm  r   r/   BYTEPLUS_TASK_STATUS_ENDPOINTro  r"   r   r  r*   r0  rp  )r   r  r   rq  r6  s        r\   r4  r4    s     
 })))YM	
 	
 	

 %/???+	         9QQ<L<OQQRRR++-)        H =;H<L<VWWWWWWWWXXXro   c                   p    e Zd Zedej        fd            Ze	 ddej        de	dej
        fd            ZdS )	ByteDanceCreateImageAssetrJ   c                    t          j        ddddt           j                            dd          t           j                            dd	d
          gt           j                            d          t           j                            d          gt           j        j        t           j        j        t           j        j	        g          S )Nr  zByteDance Create Image AssetrF  zCreate a Seedance 2.0 personal image asset. Uploads the input image and registers it in the given asset group. If group_id is empty, runs a real-person H5 authentication flow to create a new group before adding the asset.r^   z&Image to register as a personal asset.r<  r   r   Reuse an existing Seedance asset group ID to skip repeated human verification for the same person. Leave empty to run real-person authentication in the browser and create a new group.rY  r   rn  rm  rn  ro  rp  rq  rr  r   )
r   rv  r   r   rx  r~  r  r  r  r   r  s    r\   r  z'ByteDanceCreateImageAsset.define_schema      y/7.X
 w0XYY	x     	  j 99	  j 99
 	.	+	#7!
 !
 !
 !	
ro   r   r^   r   c                   K   t          |dddd           t          |dd           t          | |           d {V }t          | |t	          | |           d {V dd	           d {V }t          | ||           d {V  t          j                            d
| d| | j	        j
                   t          j        ||          S )Nrh   rf   rj   rl   rk   rm   )皙?rs   )re  rs   )	min_ratio	max_ratior   r   r   r   r  r   <Please save the asset_id and group_id for reuse.

asset_id: r
  )r7   r6   r   r  r2   r  r;   r   r   r   r   r   r  )r   r^   r   resolved_groupr   s        r\   r  z!ByteDanceCreateImageAsset.execute	  s1      	"%3$SVcghhhh#EXRRRR0h????????/#.sE::::::::
 
 
 
 
 
 
 
 
 %S(NCCCCCCCCC00*X * *'* *J 	
 	
 	

 }X~666ro   Nr   )r  r  r  r  r   rv  r  r   r   r   r  r  rO  ro   r\   r  r    s        "
bi "
 "
 "
 ["
H  7 7{7 7
 
7 7 7 [7 7 7ro   r  c                   p    e Zd Zedej        fd            Ze	 ddej        de	dej
        fd            ZdS )	ByteDanceCreateVideoAssetrJ   c                    t          j        ddddt           j                            dd          t           j                            dd	d
          gt           j                            d          t           j                            d          gt           j        j        t           j        j        t           j        j	        g          S )Nr  zByteDance Create Video Assetr  zCreate a Seedance 2.0 personal video asset. Uploads the input video and registers it in the given asset group. If group_id is empty, runs a real-person H5 authentication flow to create a new group before adding the asset.rF   z&Video to register as a personal asset.r<  r   r   r  rY  r   r  r  )
r   rv  r   r   rx  r~  r  r  r  r   r  s    r\   r  z'ByteDanceCreateVideoAsset.define_schema;	  r  ro   r   rF   r   c           	        K   t          |dd           t          |dddd           |                                \  }}|dk    r.||z  }d|cxk    rd	k    sn t          d
|dd| d| d          ||z  }d|cxk    rdk    sn t          d|dd| d| d          t	          |                                          }d|cxk    rdk    sn t          d|dd          t          | |           d {V }t          | |t          | |           d {V dd           d {V }	t          | |	|           d {V  t          j                            d|	 d| | j        j                   t          j        |	|          S )Nra   r  )min_durationmax_durationrh   rf   r  r   r  re  z:Asset video aspect ratio (W/H) must be in [0.4, 2.5], got z.3fz (rO   r   i @ i& uA   Asset video total pixels (W×H) must be in [409600, 927408], got rP      <   z)Asset video FPS must be in [24, 60], got r  .r   r   r  r  r
  )r:   r9   rR   rT   r<  get_frame_rater   r  r4   r  r;   r   r   r   r   r   r  )
r   rF   r   rW   rX   r   rY   fpsr  r   s
             r\   r  z!ByteDanceCreateVideoAsset.execute`	  sT      	 ABGGGG!%3$SVcghhhh##%%1q55EE5''''C'''' !t^c!t!t!tkl!t!top!t!t!tuuuQ6,,,,W,,,,mX^Qmmmdemmhimmm   E((**++cRSSSSSTTT0h????????/#.sE::::::::
 
 
 
 
 
 
 
 
 %S(NCCCCCCCCC00*X * *'* *J 	
 	
 	

 }X~666ro   Nr  )r  r  r  r  r   rv  r  r   r   r   r  r  rO  ro   r\   r  r  9	  s        "
bi "
 "
 "
 ["
H  (7 (7{(7 (7
 
(7 (7 (7 [(7 (7 (7ro   r  c                   L    e Zd Zedeeej                          fd            ZdS )ByteDanceExtensionrJ   c                    K   t           t          t          t          t          t
          t          t          t          t          t          t          gS r   )rD  r  r  r  r9  rD  rM  r]  rt  r  r  r  )selfs    r\   get_node_listz ByteDanceExtension.get_node_list	  s6       !#$%''%(#%%
 	
ro   N)	r  r  r  r   r  typer   	ComfyNoder  rO  ro   r\   r  r  	  sE        
T$r|*<%= 
 
 
 X
 
 
ro   r  c                  "   K   t                      S r   )r  rO  ro   r\   comfy_entrypointr  	  s      ro   )rv   )r  r?  r5  reior   r  typing_extensionsr   comfy.utilsr   comfy_api.latestr   r   r   r	   comfy_api_nodes.apis.bytedancer
   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/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   serverr;   r  r   r   r  r  rm  r  rn  rl  r  	getLoggerr  r   r   r   r   r]   r   rn   r   r   Tensorr  r   r   r  r  r  r  r   compile
IGNORECASEr   r   r   r   r   r  r  r'  r3  r  r=  rB  rD  r  r  r  r  r9  rD  rM  r2  r  r  r"  r[  r]  rt  r  r  r  r4  r  r  r  r  rO  ro   r\   <module>r     s|      				        & & & & & & & & & & & & = = = = = = = = = = = =                                                               @                                         *       E !$ "#  /00  ?;;   M  S *g ' 3< 
 45ST  
	8	$	$
ek 
S 
c 
Z] 
bf 
 
 
 
65; 5;        %(tDD 0s 03 0u| 0PUVY[^V^P_ 0 0 0 0&"EL " "c "el " " " "4	bl	4Cy4 4S>4S>4S>9:4 4 4 4B 
2BMBB$38n$38n$ 38n$ 38n	$
 $ $ $ 
#s(^$ $ $ $N+ +T#s(^ + + + + +D,> 3    B3bl!3 3s 3s 3 3 3 3	bl	  
	
   	   .d2<&8 C SV [k    & (	- - -	bl	-<- 	-
 	- - - -8 (	- - -	bl	-;- 	-
 	- - - -( t    #*C # # # # #yh yh yh yh yh yh yh yhxM_ M_ M_ M_ M_BL M_ M_ M_`3c 3D 3 3 3 3lc_ c_ c_ c_ c_bl c_ c_ c_L}
 }
 }
 }
 }
r| }
 }
 }
@F
 F
 F
 F
 F
 F
 F
 F
RQ
 Q
 Q
 Q
 Q
", Q
 Q
 Q
hO
 O
 O
 O
 O
", O
 O
 O
d 49      "BM#r#,a,a,abbb/
2 2 2 j! !S	 !# ! ! ! !Hb] b] b] b] b] b] b] b]JO] O] O] O] O]2< O] O] O]dH HT#Y Hs H H H HVK] K] K] K] K]bl K] K] K]\Y	bl	Y*-KKY d
Y ]	Y Y Y Y6@7 @7 @7 @7 @7 @7 @7 @7FP7 P7 P7 P7 P7 P7 P7 P7f
 
 
 
 
 
 
 
&  2            ro   