
    +j)                     $   S SK r S SKJr  S SKJrJrJr  S SKJrJ	r	J
r
JrJrJrJrJrJr  S SKJrJrJrJrJrJrJrJrJrJrJrJr  SS0rS\S-  4S	 jr S\S-  4S
 jr! " S S\RD                  5      r#/ SQr$S\%S\&4S jr' " S S\RD                  5      r( " S S\RD                  5      r) " S S\RD                  5      r* " S S\RD                  5      r+ " S S\RD                  5      r, " S S\RD                  5      r- " S S\5      r.S\.4S jr/g)     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                     U R                   (       a0  U R                   R                  b  U R                   R                  S-  $ g )Nl    d(	 )usagecost_in_usd_ticks)responses    :/home/wildlama/comfy/ComfyUI/comfy_api_nodes/nodes_grok.py_extract_grok_pricer#   %   s0    ~~(..::F~~//.@@    c                 *    [        U 5      nUb  US-  $ g )NgzG?)r#   )r!   prices     r"   _extract_grok_video_pricer'   +   s    )Et|r$   c                   n    \ rS rSr\S 5       r\ SS\S\S\S\S\S\S	\R                  4S
 jj5       r
Srg)GrokImageNode2   c                 :   [         R                  " SSSS[         R                  R                  S/ SQS9[         R                  R                  SS	S
S9[         R                  R                  S/ SQS9[         R
                  R                  SSSSSS[         R                  R                  S9[         R
                  R                  SSSSS[         R                  R                  S	SS9[         R                  R                  SSS/S	S9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S	[         R                  " [         R                  " / SQS9SS9S 9	$ )!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stepr8   display_modeseedr   `Seed to determine if node should re-run; actual results are nondeterministic regardless of seed.rK   rL   rM   rN   rO   control_after_generater8   
resolution1K2K)r3   optionalr-   rG   rU   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_schemaGrokImageNode.define_schema4   s   yy#%)K   		"H   
 "  $ &:!#!1!1!8!8   "!#!1!1!8!8+/N  
 |dD\DQi5n ! 		..		++		##
 //8cd
IO
 O	
r$   r-   r4   r9   rG   rP   rU   r   c                   #    [        USSS9  [        U [        SSS9[        UUUUUUR	                  5       S9[
        [        S9I S h  vN n[        UR                  5      S:X  a>  [        R                  " [        UR                  S	   R                  5      I S h  vN 5      $ [        R                  " [        R                  " UR                   Vs/ s H*  oR                  (       d  M  [        UR                  5      PM,     sn V	s/ s H  n	[        U	5      I S h  vN PM     sn	5      5      $  N Ns  snf  Ns  sn	f 7f)
NTrH   strip_whitespace
min_lengthz /proxy/xai/v1/images/generationsPOSTpathmethod)r-   r4   r9   nrP   rU   dataresponse_modelprice_extractorr   )r   r   r   r   lowerr	   r#   lenr   r   
NodeOutputr   urltorchcatstr)
rx   r-   r4   r9   rG   rP   rU   r!   dis
             r"   executeGrokImageNode.execute   s     	!D ?O')"%++- 3/
 
 x}}"=='CHMMRSDTDXDX'Y!YZZ}}IIU]UbUb@lUbPQfkfkQUUUb@lm@l13A666@lm
 	
!
 "Z Am6msa   AE D0	AE D26E D4*D4E D;D9D;%E 2E 4E 9D;;E  N)rV   )__name__
__module____qualname____firstlineno__classmethodry   r   intr   r   r   __static_attributes__r   r$   r"   r)   r)   2   sx    P
 P
d  

 
 	

 
 
 
 

 
r$   r)   autor:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   max_ref_imageswith_aspect_ratioc                 B   [         R                  R                  S[         R                  R                  [         R                  R                  S5      [        SU S-   5       Vs/ s H  nSU 3PM
     snSS9U S:X  a  SOSU  S3S	9[         R                  R                  S
SS/S9[         R                  R                  SSSSSS[         R                  R                  S9/nU(       a2  UR                  [         R                  R                  S[        SS95        U$ s  snf )NimagesimagerH   image_)namesrL   zReference image to edit.z"Reference image(s) to edit. Up to z images.templater8   rU   rV   rW   r2   rG   rI   #Number of edited images to generaterJ   r9   z0Only allowed when multiple images are connected.r3   r8   )r   Autogrowr   TemplateNamesro   rangerj   rl   rm   rn   append%_GROK_IMAGE_EDIT_ASPECT_RATIO_OPTIONS)r   r   r   rd   s       r"   _grok_image_edit_model_inputsr      s   
[[..w'-21nq6H-IJ-Is|-IJ /  "Q& +9.9IR 	 	
 	|dD\:
9))00 	 	
F2 HHNN=J  	
 M9 Ks   #Dc                       \ rS rSr\S 5       r\ SS\S\R                  S\S\S\	S\	S	\S
\
R                  4S jj5       rSrg)GrokImageEditNode   c                 x   [         R                  " SSSS[         R                  R                  S/ SQS9[         R                  R                  SS	S
9[         R
                  R                  SSSS9[         R                  R                  SSS/S9[         R                  R                  SSSSSS[         R                  R                  S9[         R                  R                  SSSSS[         R                  R                  SSS9[         R                  R                  S/ SQSSS9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                  " [         R                  " / S QS!9S"S#9SS$9
$ )%Nr   Grok Image Editr,   /Modify an existing image based on a text promptr-   r.   r2   r   r   )ra   r4   Tr5   r6   rU   rV   rW   rG   rH   rI   r   rJ   rP   r   rQ   rR   rS   r9   r   zCOnly allowed when multiple images are connected to the image input.)r3   rX   r8   rY   rZ   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`   ra   rb   rc   rd   re   rf   rg   rh   is_deprecated)r   ri   rj   r   ro   rk   rl   rm   rn   rp   rq   rr   rs   rt   ru   rv   rw   s    r"   ry   GrokImageEditNode.define_schema   s   yy'*)I   wX>		"H   
 |dD\B&A!#!1!1!8!8   "!#!1!1!8!8+/N  
 "  "a'  I9v ! 		..		++		##
 //8cd" sZ
 Z	
r$   r-   r   r4   rU   rG   rP   r9   r   c                   #    [        USSS9  US:X  a  [        U5      S:  a  [        S5      eO[        U5      S:  a  [        S5      eUS:w  a  [        U5      S:X  a  [        S	5      e[        U [	        S
SS9[        UU Vs/ s H  n[        S[        U5       3S9PM     snUUR                  5       UUUS:X  a  S OUS9[        [        S9I S h  vN n	[        U	R                  5      S:X  a>  [        R                  " [        U	R                  S   R                   5      I S h  vN 5      $ [        R                  " ["        R$                  " U	R                   V
s/ s H*  oR                   (       d  M  ['        U
R                   5      PM,     sn
 Vs/ s H  n[        U5      I S h  vN PM     sn5      5      $ s  snf  N Ns  sn
f  N!s  snf 7f)NTrH   r|   r0   *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   data:image/png;base64,r   r-   r   r4   rU   r   rP   r9   r   r   )r   r   
ValueErrorr   r   r   r
   r   r   r	   r#   r   r   r   r   r   r   r   r   r   )rx   r-   r   r4   rU   rG   rP   r9   r   r!   r   s              r"   r   GrokImageEditNode.execute@  s     	!D,,#E*Q. !MNN /!%(1,HII6!&:5&AQ&Fl  !9&I!kpqkpfg-CD[\]D^C_+`akpq%++-"%1V%;T 3/
 
 x}}"=='CHMMRSDTDXDX'Y!YZZ}}IIU]UbUb@lUbPQfkfkQUUUb@lm@l13A666@lm
 	
 r
  "Z Am6msm   B GF8!/GF=AG#F?$6GG2GGG$G%G-G?GGGGr   N)r   )r   r   r   r   r   ry   r   r   ro   r   r   r   r   r   r   r$   r"   r   r      s    [
 [
z  #)
)
 {{)
 	)

 )
 )
 )
 )
 
)
 )
r$   r   c            	       \    \ rS rSr\S 5       r\S\S\S\S\	R                  4S j5       rSrg	)
GrokImageEditNodeV2im  c                 0   [         R                  " SSSS[         R                  R                  SSSSS	9[         R                  R                  S
[         R                  R                  S[        SSS95      [         R                  R                  S[        SSS95      [         R                  R                  S[        SSS95      /S9[         R                  R                  SSSSS[         R                  R                  SSS9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                   " [         R"                  " / SQS9SS9S9	$ )Nr   r   r,   r   r4   T r5   )r7   rK   r8   r-   r/   r   )r   r   r0   rH   Fr1   r2   rP   r   rQ   rR   rS   )r-   model.resolutionzmodel.number_of_imagesrZ   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   ri   rk   r   DynamicComboOptionr   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   s    r"   ry   !GrokImageEditNodeV2.define_schemao  sv   yy)*)I		"H	    %%..89^bc ..49^cd ..09^bc & " "!#!1!1!8!8+/N  
1#J ! 		..		++		##
 //S	eG
 G	
r$   r4   r-   rP   r   c                 R  ^#    [        USSS9  US   nUS   nUS   nUR                  S5      =(       d    0 nUR                  SS	5      nUR                  5        V	s/ s H	  oc  M  U	PM     n
n	[        S
 U
 5       5      nUS:  a  [	        S5      eUS:X  a  US:  a  [	        S5      eUS:w  a  US:  a  [	        S5      eUS	:w  a  US:X  a  [	        S5      e/ nU
 H`  m[        TR                  5      S:X  a3  UR                  U4S j[        TR                  S   5       5       5        MO  UR                  T5        Mb     [        U [        SSS9[        UU Vs/ s H  n[        S[        U5       3S9PM     snUUR                  5       UUUS	:X  a  S OUS9[         ["        S9I S h  vN n[        UR$                  5      S:X  a>  [&        R(                  " [+        UR$                  S   R,                  5      I S h  vN 5      $ [&        R(                  " [.        R0                  " UR$                   Vs/ s H*  oR,                  (       d  M  [3        UR,                  5      PM,     sn Vs/ s H  n[+        U5      I S h  vN PM     sn5      5      $ s  sn	f s  snf  N Ns  snf  N&s  snf 7f)NTrH   r|   r-   rU   rG   r   r9   r   c              3   8   #    U  H  n[        U5      v   M     g 7fN)r   ).0ts     r"   	<genexpr>.GrokImageEditNodeV2.execute.<locals>.<genexpr>  s     F1+A..s   z+At least one image is required for editing.r0   r   r   r   r      c              3   .   >#    U  H
  nTU   v   M     g 7fr   r   )r   r   tensors     r"   r   r     s     #N7M!F1I7Ms   r   r   r   r   r   r   r   r   )r   getvaluessumr   r   shapeextendr   r   r   r   r   r
   r   r   r	   r#   r   r   r   r   r   r   r   r   )rx   r4   r-   rP   model_idrU   rG   images_dictr9   r   image_tensorsn_imagesflat_tensorsr   r!   r   r   s                   @r"   r   GrokImageEditNodeV2.execute  s     	!D><(
 !34ii)/Ryy87B7I7I7K+]7K!A7K+]FFFa<JKK//HqLIJJ//HqLHII6!h!ml  ,.#F6<< A%###NuV\\!_7M#NN##F+	 $ !9&I!gsgsbcN)?@WXY@Z?['\]gs %++-"%1V%;T
 3/
 
" x}}"=='CHMMRSDTDXDX'Y!YZZ}}IIU]UbUb@lUbPQfkfkQUUUb@lm@l13A666@lm
 	
O ,^2
$ "Z Am6ms   AJ'J&J,C+J'J6/J'%J&AJ'8J96J'/JJ J'%J"9J :J"J'J'J' J""J'r   Nr   r   r   r   r   ry   r   dictr   r   r   r   r   r   r$   r"   r   r   m  sU    H
 H
T 8
8
 8
 	8

 
8
 8
r$   r   c                       \ rS rSr\S 5       r\ SS\S\S\S\S\S	\S
\R                  S-  S\
R                  4S jj5       rSrg)GrokVideoNodei  c                 ~   [         R                  " SSSS[         R                  R                  SSS/SS	9[         R                  R                  S
SSS9[         R                  R                  SSS/SS	9[         R                  R                  S/ SQSS	9[         R
                  R                  SSSSSS[         R                  R                  S9[         R
                  R                  SSSSS[         R                  R                  SSS9[         R                  R                  S SS!S"9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                   " [         R"                  " / S#QS /S$9S%S&9S'9	$ )(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   r4   T&Text description of the desired video.r6   rU   480p720p#The resolution of the output video.r9   )r   r@   r>   r<   r:   r;   r=   r?   %The aspect ratio of the output video.duration   rH      ,The duration of the output video in seconds.rJ   rP   r   rQ   rR   rS   r   zTOptional starting image for grok-imagine-video. Required for grok-imagine-video-1.5.)rX   r8   )r-   r   rU   )r[   rd   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   ri   rj   r   rk   rl   rm   sliderrn   ro   Videorp   rq   rr   rs   rt   ru   rv   rw   s    r"   ry   GrokVideoNode.define_schema  s   yy#%)B13KL^  
 		"D   
  #V,A  
 "WC  
 J!#!1!1!8!8   "!#!1!1!8!8+/N  
 !r  S.` ! 		..		++		##
 //8[eldmn
{K
 K	
r$   Nr-   r4   rU   r9   r   rP   r   r   c                 F  #    Uc  US:X  a  [        SU S35      eS nUb/  [        U5      S:w  a  [        S5      e[        S[        U5       3S9n[	        USSS	9  [        U [        S
SS9[        [        R                  X5      UUUUUS:X  a  S OUUS9[        S9I S h  vN n	[        U [        SU	R                   3S9S [        US:X  a  [        O[        S9I S h  vN n
[         R"                  " [%        U
R&                  R(                  5      I S h  vN 5      $  N} NA N7f)Nr   zThe 'zB' model requires an input image; connect one to the 'image' input.rH   z"Only one input image is supported.r   r   Tr|    /proxy/xai/v1/videos/generationsr   r   r   )r-   r   r4   rU   r   r9   rP   r   r   /proxy/xai/v1/videos/r   c                 8    U R                   b  U R                   $ S$ Ncompletestatusrs    r"   <lambda>'GrokVideoNode.execute.<locals>.<lambda>k      1883Gqxx'WZ'Wr$   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   )rx   r-   r4   rU   r9   r   rP   r   	image_urlinitial_responser!   s              r"   r   GrokVideoNode.executeG  s<     =U&>>uUG+mnoo	#E*a/ !EFF&-CD[\aDbCc+deI!D!(?O'/33EA%!%1V%;T 3"
 
 !45E5P5P4QRSW.9>BZ9Z5`s
 
 }}#?@R@R#SSTT+

 Ts6   BD!D=D!D6D!D	D!D!D!r   r   )r   r   r   r   r   ry   r   r   r   ro   r   r   r   r   r   r$   r"   r   r     s    L
 L
\  %)'U'U 'U 	'U
 'U 'U 'U {{T!'U 
'U 'Ur$   r   c                   t    \ rS rSr\S 5       r\S\S\S\R                  S\	S\
R                  4
S j5       rS	rg
)GrokVideoEditNodeir  c                 V   [         R                  " SSSS[         R                  R                  SS/S9[         R                  R                  SS	S
S9[         R
                  R                  SSS9[         R                  R                  SSSSS[         R                  R                  S	SS9/[         R
                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S	[         R                  " SS9S9	$ )Nr	  zGrok Video Editr   z.Edit an existing video based on a text prompt.r-   r   r2   r4   Tr   r6   r  z=Maximum supported duration is 8.7 seconds and 50MB file size.r8   rP   r   rQ   rH   rR   rS   zM{"type":"usd","usd": 0.06, "format": {"suffix": "/sec", "approximate": true}})r^   r_   )r   ri   rj   r   rk   r   rl   rm   rn   rp   rq   rr   rs   rt   ru   rw   s    r"   ry   GrokVideoEditNode.define_schemat  s   yy'*)Hw1E0FG		"D   
 w0op"!#!1!1!8!8+/N  
* ! 		..		++		##
 hE%
 %	
r$   r-   r4   r  rP   r   c                   #    [        USSS9  [        USSS9  UR                  5       n[        U5      nUS:  a  [	        SUS-  S-  S	 S
35      e[        U [        SSS9[        U[        [        X5      I S h  vN S9UUS9[        S9I S h  vN n[        U [        SUR                   3S9S [        [        S9I S h  vN n[        R                   " [#        UR$                  R&                  5      I S h  vN 5      $  N Ns NC N7f)NTrH   r|   gffffff!@min_durationmax_duration   Video size (   .1fMB) exceeds 50MB limit.z/proxy/xai/v1/videos/editsr   r   r   )r-   r  r4   rP   r   r   r   c                 8    U R                   b  U R                   $ S$ r   r   r   s    r"   r   +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   )	rx   r-   r4   r  rP   video_stream
video_sizer  r!   s	            r"   r   GrokVideoEditNode.execute  s     	!DACH..0'5
((|J,=,DS+II`abb!(9&I!$/G/S)ST	 3
"
 

 !45E5P5P4QRSW./
 
 }}#?@R@R#SSTT *T


 TsH   A6D8C?9DD1D?D 6D6D7	DDDDr   N)r   r   r   r   r   ry   r   r   r   r   r   r   r   r   r   r$   r"   r	  r	  r  sh    &
 &
P UU U {{	U
 U 
U Ur$   r	  c            	       \    \ rS rSr\S 5       r\S\S\S\S\	R                  4S j5       rSrg	)
GrokVideoReferenceNodei  c                 .   [         R                  " SSSS[         R                  R                  SSSS9[         R                  R                  S	[         R                  R                  S
[         R                  R                  S[         R                  R                  [         R                  R                  S5      SSSS9SS9[         R                  R                  SSS/SS9[         R                  R                  S/ SQSS9[         R                  R                  SSSSSS[         R                  R                  S 9/5      /S!S9[         R                  R                  S"S#S#S$S[         R                  R                  SS%S&9/[         R                  R                  5       /[         R                   R"                  [         R                   R$                  [         R                   R&                  /S[         R(                  " [         R*                  " S'S(/S)/S*9S+S,9S-9	$ ).Nr  zGrok Reference-to-Videor   zJGenerate video guided by reference images as style and content references.r4   Tr   r6   r-   r   reference_imagesr   
reference_rH      )prefixrL   rM   z7Up to 7 reference images to guide the video generation.r   rU   r   r   r   r   r9   )r@   r>   r<   r:   r;   r=   r?   r   r   r      rI   r   rJ   z&The model to use for video generation.rP   r   rQ   rR   rS   model.durationr   zmodel.reference_images)r[   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   ri   rk   r   r   r   r   TemplatePrefixro   rj   rl   rm   r   rn   r   rp   rq   rr   rs   rt   ru   rv   rw   s    r"   ry   $GrokVideoReferenceNode.define_schema  s   yy,2)d		"D   
 %%..0 " 1 1$6-/[[-G-G(*w(?/;,-,-	 .H .& -f !2 	!" !#$0-3V,<,Q !/ !"
 !#$2,_,S !/ !"
 !#$.,-()(*)*,Z131A1A1H1H !- !"+!#H EM & 'P "!#!1!1!8!8+/N  
]9v ! 		..		++		##
 //-/AB":!;	QX
 X	
r$   r4   r-   rP   r   c                   #    [        USSS9  [        U [        US   R                  5       5      SSSS9I S h  vN n[	        U [        S	S
S9[        US   U Vs/ s H  n[        US9PM     snUUS   US   US   US9[        S9I S h  vN n[        U [        SUR                   3S9S [        [        S9I S h  vN n[        R                  " [        UR                   R"                  5      I S h  vN 5      $  Ns  snf  Nx NH N7f)NTrH   r|   r  z	image/pngzUploading base imagesr!  )	mime_type
wait_label
max_imagesr   r   r   r-   r   rU   r   r9   )r-   r  r4   rU   r   r9   rP   r   r   r   c                 8    U R                   b  U R                   $ S$ r   r   r   s    r"   r   0GrokVideoReferenceNode.execute.<locals>.<lambda>>  r   r$   r   )r   r   listr   r   r   r   r
   r   r   r  r   r'   r   r   r   r  r   )rx   r4   r-   rP   ref_image_urlsr   r  r!   s           r"   r   GrokVideoReferenceNode.execute  s"     	!D8)*1134!. 
 
 ")?O'GnAO!PA.Q"7!P .z*">2 3"
 
 !45E5P5P4QRSW.5
 
 }}#?@R@R#SSTT9
 "Q

 TsQ   6DC; DC=,D	D
1D;D<6D2D3	D=DDDr   Nr   r   r$   r"   r  r    s[    Y
 Y
v #U#U #U 	#U
 
#U #Ur$   r  c                   t    \ rS rSr\S 5       r\S\S\R                  S\	S\
S\R                  4
S j5       rS	rg
)GrokVideoExtendNodeiE  c                 0   [         R                  " SSSS[         R                  R                  SSSS9[         R                  R                  S	S
S9[         R
                  R                  S[         R
                  R                  S[         R                  R                  SSSSSS[         R                  R                  S9/5      /SS9[         R                  R                  SSSSS[         R                  R                  SSS9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                   " [         R"                  " S/S9SS9S 9	$ )!Nr2  zGrok Video Extendr   zMExtend an existing video with a seamless continuation based on a text prompt.r4   Tz9Text description of what should happen next in the video.r6   r  z1Source video to extend. MP4 format, 2-15 seconds.r  r-   r   r      r#  rI   rH   z#Length of the extension in seconds.rJ   z%The model to use for video extension.r   rP   r   rQ   rR   rS   r$  rZ   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   ri   rk   r   r   r   r   rl   rm   r   rn   rp   rq   rr   rs   rt   ru   rv   rw   s    r"   ry   !GrokVideoExtendNode.define_schemaG  s{   yy),)g		"W   
 w0cd%%..0 "$.,-()(*)*,Q131A1A1H1H !- !"
  D% & ( "!#!1!1!8!8+/N  
7&P ! 		..		++		##
 //9I8JK	kB
 B	
r$   r4   r  r-   rP   r   c                   #    [        USSS9  [        USSS9  [        UR                  5       5      nUS:  a  [	        SUS	-  S	-  S
 S35      e[        U [        SSS9[        U[        [        X5      I S h  vN S9US   S9[        S9I S h  vN n[        U [        SUR                   3S9S [        [        S9I S h  vN n[        R                   " [#        UR$                  R&                  5      I S h  vN 5      $  N Ns NC N7f)NTrH   r|   r#  r   r  r  r  r  r  r  z/proxy/xai/v1/videos/extensionsr   r   r   r   )r4   r  r   r   r   r   c                 8    U R                   b  U R                   $ S$ r   r   r   s    r"   r   -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   )rx   r4   r  r-   rP   r  r  r!   s           r"   r   GrokVideoExtendNode.execute  s     	!DABG'(?(?(AB
((|J,=,DS+II`abb!(>vN&$/G/S)STz*
 3	"
 	
 !45E5P5P4QRSW.5
 
 }}#?@R@R#SSTT *T	

 TsH   A4D6C?7DD1D?D 6D6D7	DDDDr   N)r   r   r   r   r   ry   r   r   r   r   r   r   r   r   r   r   r$   r"   r2  r2  E  sj    C
 C
J UU {{U 	U
 U 
U Ur$   r2  c                   L    \ rS rSr\S\\\R                        4S j5       r	Sr
g)GrokExtensioni  r   c                 T   #    [         [        [        [        [        [
        [        /$ 7fr   )r)   r   r   r   r  r	  r2  )selfs    r"   get_node_listGrokExtension.get_node_list  s&      "
 	
s   &(r   N)r   r   r   r   r   r.  typer   	ComfyNoder>  r   r   r$   r"   r;  r;    s)    	
T$r||*<%= 	
 	
r$   r;  c                     #    [        5       $ 7fr   )r;  r   r$   r"   comfy_entrypointrC    s     ?s   )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'   rA  r)   r   r   boolr   r   r   r   r	  r  r2  r;  rC  r   r$   r"   <module>rJ     s%    & 6 6
 
 
   " > 
UT\ 54< t
BLL t
n) %$"S "T "JJ
 J
ZF
",, F
RyUBLL yUxKU KU\BUR\\ BUJfU",, fUR
N 
 r$   