
    +j)                        d dl Z d dlmZ d dlmZmZmZ d dlmZm	Z	m
Z
mZmZmZmZmZmZ 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 ddiZdedz  fd	Z dedz  fd
Z! G d dej"                  Z#g dZ$de%de&fdZ' G d dej"                  Z( G d dej"                  Z) G d dej"                  Z* G d dej"                  Z+ G d dej"                  Z, G d dej"                  Z- G d de          Z.de.fdZ/dS )     N)override)IOComfyExtensionInput)	ImageEditRequestImageGenerationRequestImageGenerationResponseInputUrlObjectVideoEditRequestVideoExtensionRequestVideoGenerationRequestVideoGenerationResponseVideoStatusResponse)ApiEndpointdownload_url_to_image_tensordownload_url_to_video_outputget_fs_object_sizeget_number_of_imagespoll_opsync_optensor_to_base64_stringupload_images_to_comfyapiupload_video_to_comfyapivalidate_stringvalidate_video_durationgrok-imagine-video-1.5zgrok-imagine-video-1.5-previewreturnc                 J    | j         r| j         j        | j         j        dz  S d S )Nl    d(	 )usagecost_in_usd_ticks)responses    :/home/wildlama/comfy/ComfyUI/comfy_api_nodes/nodes_grok.py_extract_grok_pricer#   %   s,    ~ A(.:F~/.@@4    c                 2    t          |           }||dz  S d S )NgzG?)r#   )r!   prices     r"   _extract_grok_video_pricer'   +   s$    ))Et|4r$   c                   f    e Zd Zed             Ze	 ddedededededed	ej        fd
            Z	dS )GrokImageNodec                 
   t          j        ddddt           j                            dg d          t           j                            dd	d
          t           j                            dg d          t           j                            ddddddt           j        j                  t           j                            dddddt           j        j        d	d          t           j                            dddg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
Grok Imagepartner/image/Grokz1Generate images using Grok based on a text promptmodelgrok-imagine-image-qualitygrok-imagine-image-progrok-imagine-imageoptionspromptT*The text prompt used to generate the image	multilinetooltipaspect_ratio)1:12:33:23:44:39:1616:99:19.519.5:99:2020:91:22:1number_of_images   
   zNumber of images to generatedefaultminmaxstepr7   display_modeseedr   `Seed to determine if node should re-run; actual results are nondeterministic regardless of seed.rJ   rK   rL   rM   rN   control_after_generater7   
resolution1K2K)r2   optionalr,   rF   rT   widgetsaM  
                (
                  $rate := widgets.model = "grok-imagine-image-quality"
                    ? (widgets.resolution = "1k" ? 0.05 : 0.07)
                    : ($contains(widgets.model, "pro") ? 0.07 : 0.02);
                  {"type":"usd","usd": $rate * widgets.number_of_images}
                )
                
depends_onexpr	node_iddisplay_namecategorydescriptioninputsoutputshiddenis_api_nodeprice_badge)r   SchemaCombor   StringIntNumberDisplaynumberImageOutputHiddenauth_token_comfy_orgapi_key_comfy_org	unique_id
PriceBadgePriceBadgeDependsclss    r"   define_schemazGrokImageNode.define_schema4   s   y#%)K      	"H    
 "     $ &:!#!1!8    "!#!1!8+/N  
 
 |dD\DQQi5n !! 	.	+	#
 /8c8c8cddd
 
 
IO
 O
 O
 O	
r$   rU   r,   r3   r8   rF   rO   rT   r   c                   K   t          |dd           t          | t          dd          t          ||||||                                          t
          t                     d {V }t          |j                  dk    r7t          j
        t          |j        d	         j                   d {V           S t          j
        t          j        d
 d |j        D             D              d {V                     S )NTrG   strip_whitespace
min_lengthz /proxy/xai/v1/images/generationsPOSTpathmethod)r,   r3   r8   nrO   rT   dataresponse_modelprice_extractorr   c                 <   K   g | ]}t          |           d {V S Nr   .0is     r"   
<listcomp>z)GrokImageNode.execute.<locals>.<listcomp>   7      mmm13A66666666mmmr$   c                 D    g | ]}|j         	t          |j                   S  urlstrr   ds     r"   r   z)GrokImageNode.execute.<locals>.<listcomp>   *    @l@l@lPQfgfk@lQU@l@l@lr$   )r   r   r   r   lowerr	   r#   lenr   r   
NodeOutputr   r   torchcat)rw   r,   r3   r8   rF   rO   rT   r!   s           r"   executezGrokImageNode.execute   sA      	!DDDD ?OOO')"%++--   3/
 
 
 
 
 
 
 
 
 x}""='CHMRSDTDX'Y'Y!Y!Y!Y!Y!Y!YZZZ}Imm@l@lU]Ub@l@l@lmmmmmmmmm 
 
 	
r$   N)rU   )
__name__
__module____qualname__classmethodrx   r   intr   r   r   r   r$   r"   r)   r)   2   s        P
 P
 [P
d  
 

 
 	

 
 
 
 

 
 
 [
 
 
r$   r)   autor9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   max_ref_imageswith_aspect_ratioc                 8   t           j                            dt           j                            t           j                            d          d t          d| dz             D             d          | dk    rdnd|  d	          t           j                            d
ddg          t           j                            ddddddt           j        j	                  g}|r:|
                    t           j                            dt          d                     |S )Nimagesimagec                     g | ]}d | S )image_r   r   s     r"   r   z1_grok_image_edit_model_inputs.<locals>.<listcomp>   s    JJJ|||JJJr$   rG   )namesrK   zReference image to edit.z"Reference image(s) to edit. Up to z images.templater7   rT   rU   rV   r1   rF   rH   #Number of edited images to generaterI   r8   z0Only allowed when multiple images are connected.r2   r7   )r   Autogrowr   TemplateNamesrn   rangeri   rk   rl   rm   append%_GROK_IMAGE_EDIT_ASPECT_RATIO_OPTIONS)r   r   rc   s      r"   _grok_image_edit_model_inputsr      s-   
[..w''JJU1nq6H-I-IJJJ /   "Q&& +*R.RRR 	 	
 	
 	|dD\::
9)0 	 	
 	
F2  
HNN=J   	
 	
 	
 Mr$   c                   t    e Zd Zed             Ze	 ddedej        dedededed	ed
e	j
        fd            ZdS )GrokImageEditNodec                 N   t          j        ddddt           j                            dg d          t           j                            dd	
          t           j                            ddd          t           j                            dddg          t           j                            ddddddt           j        j                  t           j                            dddddt           j        j        dd          t           j                            dg 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"#          d$
  
        S )%Nr   Grok Image Editr+   /Modify an existing image based on a text promptr,   r-   r1   r   r   )r`   r3   Tr4   r5   rT   rU   rV   rF   rG   rH   r   rI   rO   r   rP   rQ   rR   r8   r   zCOnly allowed when multiple images are connected to the image input.)r2   rW   r7   rX   rY   a  
                (
                  $isQualityModel := widgets.model = "grok-imagine-image-quality";
                  $isPro := $contains(widgets.model, "pro");
                  $rate := $isQualityModel
                    ? (widgets.resolution = "1k" ? 0.05 : 0.07)
                    : ($isPro ? 0.07 : 0.02);
                  $base := $isQualityModel ? 0.01 : 0.002;
                  $output := $rate * widgets.number_of_images;
                  $isPro
                    ? {"type":"usd","usd": $base + $output}
                    : {"type":"range_usd","min_usd": $base + $output, "max_usd": 3 * $base + $output}
                )
                r[   )
r_   r`   ra   rb   rc   rd   re   rf   rg   is_deprecated)r   rh   ri   r   rn   rj   rk   rl   rm   ro   rp   rq   rr   rs   rt   ru   rv   s    r"   rx   zGrokImageEditNode.define_schema   s   y'*)I      wX>>	"H    
 |dD\BB&A!#!1!8    "!#!1!8+/N  
 
 "    "a'   I9v !! 	.	+	#
 /8c8c8cddd  " sZ
 Z
 Z
 Z	
r$   r   r,   r   r3   rT   rF   rO   r8   r   c                   K   t          |dd           |dk    r#t          |          dk    rt          d          n"t          |          dk    rt          d          |dk    r"t          |          dk    rt          d	          t          | t	          d
d          t          |d |D             ||                                |||dk    rd n|          t          t                     d {V }t          |j
                  dk    r7t          j        t          |j
        d         j                   d {V           S t          j        t          j        d d |j
        D             D              d {V                     S )NTrG   rz   r/   *The pro model supports only 1 input image.   )A maximum of 3 input images is supported.r   ZCustom aspect ratio is only allowed when multiple images are connected to the image input./proxy/xai/v1/images/editsr}   r~   c                 N    g | ]"}t          d t          |                     #S data:image/png;base64,r   r
   r   r   s     r"   r   z-GrokImageEditNode.execute.<locals>.<listcomp>Z  s7    qqqfg+`D[\]D^D^+`+`aaaqqqr$   r,   r   r3   rT   r   rO   r8   r   r   c                 <   K   g | ]}t          |           d {V S r   r   r   s     r"   r   z-GrokImageEditNode.execute.<locals>.<listcomp>h  r   r$   c                 D    g | ]}|j         	t          |j                   S r   r   r   s     r"   r   z-GrokImageEditNode.execute.<locals>.<listcomp>h  r   r$   )r   r   
ValueErrorr   r   r   r   r	   r#   r   r   r   r   r   r   r   r   )	rw   r,   r   r3   rT   rF   rO   r8   r!   s	            r"   r   zGrokImageEditNode.execute@  s      	!DDDD,,,#E**Q.. !MNNN /!%((1,,HIII6!!&:5&A&AQ&F&Fl   !9&III!qqkpqqq%++--"%1V%;%;TT   3/
 
 
 
 
 
 
 
 
 x}""='CHMRSDTDX'Y'Y!Y!Y!Y!Y!Y!YZZZ}Imm@l@lU]Ub@l@l@lmmmmmmmmm 
 
 	
r$   N)r   )r   r   r   r   rx   r   r   rn   r   r   r   r   r   r$   r"   r   r      s        [
 [
 [[
z  #)
 )
)
 {)
 	)

 )
 )
 )
 )
 
)
 )
 )
 [)
 )
 )
r$   r   c            	       V    e Zd Zed             Zededededej	        fd            Z
dS )GrokImageEditNodeV2c                 *   t          j        ddddt           j                            dddd	          t           j                            d
t           j                            dt          dd                    t           j                            dt          dd                    t           j                            dt          dd                    g          t           j                            dddddt           j        j	        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   r   r+   r   r3   T r4   )r6   rJ   r7   r,   r.   r   )r   r   r/   rG   Fr0   r1   rO   r   rP   rQ   rR   )r,   model.resolutionzmodel.number_of_imagesrY   a  
                (
                  $isQualityModel := widgets.model = "grok-imagine-image-quality";
                  $isPro := $contains(widgets.model, "pro");
                  $res := $lookup(widgets, "model.resolution");
                  $n := $lookup(widgets, "model.number_of_images");
                  $rate := $isQualityModel
                    ? ($res = "1k" ? 0.05 : 0.07)
                    : ($isPro ? 0.07 : 0.02);
                  $base := $isQualityModel ? 0.01 : 0.002;
                  $output := $rate * $n;
                  $isPro
                    ? {"type":"usd","usd": $base + $output}
                    : {"type":"range_usd","min_usd": $base + $output, "max_usd": 3 * $base + $output}
                )
                r[   r^   )r   rh   rj   r   DynamicComboOptionr   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   s    r"   rx   z!GrokImageEditNodeV2.define_schemao  s   y)*)I	"H	     %%..89^bccc  ..49^cddd  ..09^bccc  &  " "!#!1!8+/N  
 
1#J !! 	.	+	#
 /SSS  	  eG
 G
 G
 G	
r$   r3   r,   rO   r   c                   K   t          |dd           |d         }|d         }|d         }|                    d          pi }|                    dd	          }d
 |                                D             }	t          d |	D                       }
|
dk     rt	          d          |dk    r|
dk    rt	          d          |dk    r|
dk    rt	          d          |d	k    r|
dk    rt	          d          g }|	D ]it          j                  dk    r:|                    fdt          j        d                   D                        T|	                               jt          | t          dd          t          |d |D             ||                                |||d	k    rd n|          t          t                     d {V }t          |j                  dk    r7t#          j        t'          |j        d         j                   d {V           S t#          j        t+          j        d d |j        D             D              d {V                     S )NTrG   rz   r,   rT   rF   r   r8   r   c                     g | ]}||S r   r   r   ts     r"   r   z/GrokImageEditNodeV2.execute.<locals>.<listcomp>  s    +]+]+]!q}A}}}r$   c              3   4   K   | ]}t          |          V  d S r   )r   r   s     r"   	<genexpr>z.GrokImageEditNodeV2.execute.<locals>.<genexpr>  s+      FF1+A..FFFFFFr$   z+At least one image is required for editing.r/   r   r   r   r      c              3   (   K   | ]}|         V  d S r   r   )r   r   tensors     r"   r   z.GrokImageEditNodeV2.execute.<locals>.<genexpr>  s'      #N#N!F1I#N#N#N#N#N#Nr$   r   r   r}   r~   c                 N    g | ]"}t          d t          |                     #S r   r   r   s     r"   r   z/GrokImageEditNodeV2.execute.<locals>.<listcomp>  sC       bcN'\@WXY@Z@Z'\'\]]]  r$   r   r   c                 <   K   g | ]}t          |           d {V S r   r   r   s     r"   r   z/GrokImageEditNodeV2.execute.<locals>.<listcomp>  r   r$   c                 D    g | ]}|j         	t          |j                   S r   r   r   s     r"   r   z/GrokImageEditNodeV2.execute.<locals>.<listcomp>  r   r$   )r   getvaluessumr   r   shapeextendr   r   r   r   r   r   r	   r#   r   r   r   r   r   r   r   )rw   r3   r,   rO   model_idrT   rF   images_dictr8   image_tensorsn_imagesflat_tensorsr!   r   s                @r"   r   zGrokImageEditNodeV2.execute  s      	!DDDD><(
 !34ii))/Ryy88+]+]{7I7I7K7K+]+]+]FFFFFFFa<<JKKK///HqLLIJJJ///HqLLHIII6!!h!mml   ,.# 	, 	,F6<  A%%###N#N#N#NuV\!_7M7M#N#N#NNNNN##F++++ 9&III! gs   %++--"%1V%;%;TT
 
 
 3/
 
 
 
 
 
 
 
 
" x}""='CHMRSDTDX'Y'Y!Y!Y!Y!Y!Y!YZZZ}Imm@l@lU]Ub@l@l@lmmmmmmmmm 
 
 	
r$   Nr   r   r   r   rx   r   dictr   r   r   r   r   r$   r"   r   r   m  sy        H
 H
 [H
T 8
8
 8
 	8

 
8
 8
 8
 [8
 8
 8
r$   r   c                   z    e Zd Zed             Ze	 ddedededededed	ej        dz  d
e	j
        fd            ZdS )GrokVideoNodec                 T   t          j        ddddt           j                            dddgd	          t           j                            d
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          t           j	                            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
Grok Videopartner/video/Grokz(Generate video from a prompt or an imager,   grok-imagine-videor   z@grok-imagine-video-1.5 currently always requires an input image.r   r3   T&Text description of the desired video.r5   rT   480p720p#The resolution of the output video.r8   )r   r?   r=   r;   r9   r:   r<   r>   %The aspect ratio of the output video.duration   rG      ,The duration of the output video in seconds.rI   rO   r   rP   rQ   rR   r   zTOptional starting image for grok-imagine-video. Required for grok-imagine-video-1.5.)rW   r7   )r,   r   rT   )rZ   rc   a  
                (
                  $is15 := $contains(widgets.model, "1.5");
                  $rate := $is15
                    ? (widgets.resolution = "720p" ? 0.2002 : 0.1144)
                    : (widgets.resolution = "720p" ? 0.07 : 0.05);
                  $imgCost := $is15 ? 0.0143 : 0.002;
                  $base := $rate * widgets.duration;
                  {"type":"usd","usd": inputs.image.connected ? $base + $imgCost : $base}
                )
                r[   r^   )r   rh   ri   r   rj   rk   rl   sliderrm   rn   Videoro   rp   rq   rr   rs   rt   ru   rv   s    r"   rx   zGrokVideoNode.define_schema  s   y#%)B13KL^   
 	"D    
  #V,A   
 "WWWC   
 J!#!1!8    "!#!1!8+/N  
 
 !r   S.` !! 	.	+	#
 /8[8[8[eldmnnn
  {K
 K
 K
 K	
r$   Nr,   r3   rT   r8   r   rO   r   r   c                   K   ||dk    rt          d| d          d }|Bt          |          dk    rt          d          t          dt          |                     }t	          |dd	           t          | t          d
d          t          t          	                    ||          |||||dk    rd n||          t                     d {V }	t          | t          d|	j                   d t          |dk    rt          nt                     d {V }
t!          j        t%          |
j        j                   d {V           S )Nr   zThe 'zB' model requires an input image; connect one to the 'image' input.rG   z"Only one input image is supported.r   r   Trz    /proxy/xai/v1/videos/generationsr}   r~   r   )r,   r   r3   rT   r   r8   rO   r   r   /proxy/xai/v1/videos/r   c                 "    | j         | j         ndS Ncompletestatusrs    r"   <lambda>z'GrokVideoNode.execute.<locals>.<lambda>k      183GqxxZ r$   status_extractorr   r   )r   r   r
   r   r   r   r   r   _GROK_VIDEO_MODEL_API_IDSr   r   r   
request_idr   r'   r#   r   r   r   videor   )rw   r,   r3   rT   r8   r   rO   r   	image_urlinitial_responser!   s              r"   r   zGrokVideoNode.executeG  s      =U&>>>nUnnnooo	#E**a// !EFFF&+dD[\aDbDb+d+deeeI!DDDD!(?OOO'/33E5AA%!%1V%;%;TT   3"
 "
 "
 
 
 
 
 
 
 !R5E5PRRSSSWW.9>BZ9Z9Z55`s
 
 
 
 
 
 
 
 
 }#?@R#S#SSSSSSSTTTr$   r   )r   r   r   r   rx   r   r   r   rn   r   r   r   r   r$   r"   r   r     s        L
 L
 [L
\  %)'U 'U'U 'U 	'U
 'U 'U 'U {T!'U 
'U 'U 'U ['U 'U 'Ur$   r   c                   d    e Zd Zed             Zedededej        dede	j
        f
d            ZdS )	GrokVideoEditNodec                 *   t          j        ddddt           j                            ddg          t           j                            dd	d
          t           j                            dd          t           j                            dddddt           j        j        d	d          gt           j        	                                gt           j
        j        t           j
        j        t           j
        j        gd	t          j        d          	  	        S )Nr  zGrok Video Editr   z.Edit an existing video based on a text prompt.r,   r   r1   r3   Tr   r5   r  z=Maximum supported duration is 8.7 seconds and 50MB file size.r7   rO   r   rP   rG   rQ   rR   zM{"type":"usd","usd": 0.06, "format": {"suffix": "/sec", "approximate": true}})r]   r^   )r   rh   ri   r   rj   r   rk   rl   rm   ro   rp   rq   rr   rs   rt   rv   s    r"   rx   zGrokVideoEditNode.define_schemat  s	   y'*)Hw1E0FGG	"D    
 w0opp"!#!1!8+/N  
 
* !! 	.	+	#
 h  E%
 %
 %
 %	
r$   r,   r3   r  rO   r   c                 l  K   t          |dd           t          |dd           |                                }t          |          }|dk    rt	          d|dz  dz  d	d
          t          | t          dd          t          |t          t          | |           d {V           ||          t                     d {V }t          | t          d|j                   d t          t                     d {V }t          j        t#          |j        j                   d {V           S )NTrG   rz   gffffff!@min_durationmax_duration   Video size (   .1fMB) exceeds 50MB limit.z/proxy/xai/v1/videos/editsr}   r~   r   )r,   r  r3   rO   r   r   r   c                 "    | j         | j         ndS r   r  r  s    r"   r  z+GrokVideoEditNode.execute.<locals>.<lambda>  r  r$   r  )r   r   get_stream_sourcer   r   r   r   r   r
   r   r   r   r
  r   r#   r   r   r   r  r   )	rw   r,   r3   r  rO   video_stream
video_sizer  r!   s	            r"   r   zGrokVideoEditNode.execute  s      	!DDDDACHHHH..00'55
(((aJ,=,Daaaabbb!(9&III!$/GU/S/S)S)S)S)S)S)STTT	   3
"
 
"
 
"
 

 

 

 

 

 

 !R5E5PRRSSSWW./
 
 
 
 
 
 
 
 
 }#?@R#S#SSSSSSSTTTr$   N)r   r   r   r   rx   r   r   r   r   r   r   r   r   r$   r"   r  r  r  s        &
 &
 [&
P UU U {	U
 U 
U U U [U U Ur$   r  c            	       V    e Zd Zed             Zededededej	        fd            Z
dS )GrokVideoReferenceNodec                 
   t          j        ddddt           j                            ddd          t           j                            d	t           j                            d
t           j                            dt           j                            t           j                            d          dd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                   g          gd!          t           j
                            d"d#d#d$dt           j        j        dd%&          gt           j                                        gt           j        j        t           j        j        t           j        j        gdt          j        t          j        d'd(gd)g*          d+,          -	  	        S ).Nr   zGrok Reference-to-Videor   zJGenerate video guided by reference images as style and content references.r3   Tr   r5   r,   r   reference_imagesr   
reference_rG      )prefixrK   rL   z7Up to 7 reference images to guide the video generation.r   rT   r   r   r   r   r8   )r?   r=   r;   r9   r:   r<   r>   r   r   r      rH   r   rI   z&The model to use for video generation.rO   r   rP   rQ   rR   model.durationr   zmodel.reference_images)rZ   input_groupsa  
                (
                  $res := $lookup(widgets, "model.resolution");
                  $dur := $lookup(widgets, "model.duration");
                  $refs := $lookup(inputGroups, "model.reference_images");
                  $rate := $res = "720p" ? 0.07 : 0.05;
                  $price := ($rate * $dur + 0.002 * $refs) * 1.43;
                  {"type":"usd","usd": $price}
                )
                r[   r^   )r   rh   rj   r   r   r   r   TemplatePrefixrn   ri   rk   rl   r   rm   r   ro   rp   rq   rr   rs   rt   ru   rv   s    r"   rx   z$GrokVideoReferenceNode.define_schema  s.   y,2)d	"D    
 %%..0 " 1 1$6-/[-G-G(*w(?(?/;,-,-	 .H .& .& -f !2 	!" 	!" !#$0-3V,<,Q !/ !" !"
 !#$2,_,_,_,S !/ !" !"
 !#$.,-()(*)*,Z131A1H !- !" !"+! !#H EM & ' 'P "!#!1!8+/N  
 
]9v !! 	.	+	#
 /-/AB":!;  	  QX
 X
 X
 X	
r$   r3   r,   rO   r   c                 F  K   t          |dd           t          | t          |d                                                   ddd           d {V }t	          | t          d	d
          t          |d         d |D             ||d         |d         |d         |          t                     d {V }t          | t          d|j	                   d t          t                     d {V }t          j        t          |j        j                   d {V           S )NTrG   rz   r"  z	image/pngzUploading base imagesr$  )	mime_type
wait_label
max_imagesr   r}   r~   r,   c                 .    g | ]}t          |           S )r   )r
   r   s     r"   r   z2GrokVideoReferenceNode.execute.<locals>.<listcomp>2  s#    !P!P!PA.Q"7"7"7!P!P!Pr$   rT   r   r8   )r,   r"  r3   rT   r   r8   rO   r   r   r   c                 "    | j         | j         ndS r   r  r  s    r"   r  z0GrokVideoReferenceNode.execute.<locals>.<lambda>>  r  r$   r  )r   r   listr   r   r   r   r   r   r
  r   r'   r   r   r   r  r   )rw   r3   r,   rO   ref_image_urlsr  r!   s          r"   r   zGrokVideoReferenceNode.execute  s      	!DDDD8)*113344!. 
  
  
 
 
 
 
 
 
 ")?OOO'Gn!P!P!P!P!P .z*">2   3"
 "
 "
 
 
 
 
 
 
 !R5E5PRRSSSWW.5
 
 
 
 
 
 
 
 
 }#?@R#S#SSSSSSSTTTr$   Nr   r   r$   r"   r   r     s        Y
 Y
 [Y
v #U#U #U 	#U
 
#U #U #U [#U #U #Ur$   r   c                   d    e Zd Zed             Zededej        dede	de
j        f
d            ZdS )	GrokVideoExtendNodec                    t          j        ddddt           j                            ddd          t           j                            d	d
          t           j                            dt           j                            dt           j                            ddddddt           j        j	                  g          gd          t           j                            dddddt           j        j
        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 )!Nr3  zGrok Video Extendr   zMExtend an existing video with a seamless continuation based on a text prompt.r3   Tz9Text description of what should happen next in the video.r5   r  z1Source video to extend. MP4 format, 2-15 seconds.r  r,   r   r      r&  rH   rG   z#Length of the extension in seconds.rI   z%The model to use for video extension.r   rO   r   rP   rQ   rR   r'  rY   a;  
                (
                  $dur := $lookup(widgets, "model.duration");
                  {
                    "type": "range_usd",
                    "min_usd": (0.02 + 0.05 * $dur) * 1.43,
                    "max_usd": (0.15 + 0.05 * $dur) * 1.43
                  }
                )
                r[   r^   )r   rh   rj   r   r   r   r   rk   rl   r   rm   ro   rp   rq   rr   rs   rt   ru   rv   s    r"   rx   z!GrokVideoExtendNode.define_schemaG  s   y),)g	"W    
 w0cdd%%..0 "$.,-()(*)*,Q131A1H !- !" !"
   D% &  ( "!#!1!8+/N  
 
7&P !! 	.	+	#
 /9I8JKKK	  kB
 B
 B
 B	
r$   r3   r  r,   rO   r   c                 r  K   t          |dd           t          |dd           t          |                                          }|dk    rt	          d|d	z  d	z  d
d          t          | t          dd          t          |t          t          | |           d {V           |d                   t                     d {V }t          | t          d|j                   d t          t                     d {V }t          j        t#          |j        j                   d {V           S )NTrG   rz   r&  r   r  r  r  r  r  r  z/proxy/xai/v1/videos/extensionsr}   r~   r   r   )r3   r  r   r   r   r   c                 "    | j         | j         ndS r   r  r  s    r"   r  z-GrokVideoExtendNode.execute.<locals>.<lambda>  r  r$   r  )r   r   r   r  r   r   r   r   r
   r   r   r   r
  r   r'   r   r   r   r  r   )rw   r3   r  r,   rO   r  r  r!   s           r"   r   zGrokVideoExtendNode.execute  s      	!DDDDABGGGG'(?(?(A(ABB
(((aJ,=,Daaaabbb!(>vNNN&$/GU/S/S)S)S)S)S)S)STTTz*  
 3	"
 	"
 	"
 	
 	
 	
 	
 	
 	
 !R5E5PRRSSSWW.5
 
 
 
 
 
 
 
 
 }#?@R#S#SSSSSSSTTTr$   N)r   r   r   r   rx   r   r   r   r   r   r   r   r   r   r$   r"   r3  r3  E  s        C
 C
 [C
J UU {U 	U
 U 
U U U [U U Ur$   r3  c                   L    e Zd Zedeeej                          fd            ZdS )GrokExtensionr   c                 ^   K   t           t          t          t          t          t
          t          gS r   )r)   r   r   r   r   r  r3  )selfs    r"   get_node_listzGrokExtension.get_node_list  s'       "
 	
r$   N)	r   r   r   r   r0  typer   	ComfyNoder<  r   r$   r"   r9  r9    sE        	
T$r|*<%= 	
 	
 	
 X	
 	
 	
r$   r9  c                  "   K   t                      S r   )r9  r   r$   r"   comfy_entrypointr@    s      ??r$   )0r   typing_extensionsr   comfy_api.latestr   r   r   comfy_api_nodes.apis.grokr   r   r	   r
   r   r   r   r   r   comfy_api_nodes.utilr   r   r   r   r   r   r   r   r   r   r   r   r	  floatr#   r'   r>  r)   r   r   boolr   r   r   r   r  r   r3  r9  r@  r   r$   r"   <module>rG     s    & & & & & & 6 6 6 6 6 6 6 6 6 6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
                           " > 
UT\    54<    t
 t
 t
 t
 t
BL t
 t
 t
n) ) ) %$"S "T " " " "JJ
 J
 J
 J
 J
 J
 J
 J
ZF
 F
 F
 F
 F
", F
 F
 F
RyU yU yU yU yUBL yU yU yUxKU KU KU KU KU KU KU KU\BU BU BU BU BUR\ BU BU BUJfU fU fU fU fU", fU fU fUR
 
 
 
 
N 
 
 
      r$   