
    Fg5R                    D   % S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSK
Jr  SSKJrJr  SSKJr  \" \	" \5      R&                  S-  5       r\R*                  " \5      rSSS5         " S	 S
5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r  " S S\5      r!0 r"\RG                  5        H8  r$\$\"\$RJ                  '   \$RG                  5        H  r&\&\"\&RJ                  '   M     M:     \\"S
'   \\"S'   \\"S '   0 S!\_S"\_S#\_S$\_S%\_S&\_S'\_S(\_S)\_S*\_S+\_S,\ _S-\ _S.\ _S/\_S0\_S1\_\\ \ \ \\!\ \\ \ \ \ \\\ S2.Er'S3\(S4'   g! , (       d  f       GN1= f)5z:Included for backwards compatibility with 3.x spaces/apps.    )annotationsN)Path)Any)
media_datautils)FileDataz
types.jsonc                  r    \ rS rSrS rSS jrSS jrSS jrSS jrSSS jjr	   S       SS	 jjr
S
rg)Serializable   c                "    U R                  5       $ z
The typing information for this component as a dictionary whose values are a list of 2 strings: [Python type, language-agnostic description].
Keys of the dictionary are: raw_input, raw_output, serialized_input, serialized_output
)api_infoselfs    j/Users/admin/workspace/ai/PDFMathTranslate/myenv/lib/python3.13/site-packages/gradio_client/serializing.pyserialized_infoSerializable.serialized_info   s    
 }}    c                    [        5       er   NotImplementedErrorr   s    r   r   Serializable.api_info       
 "##r   c                    [        5       e)z
The example inputs for this component as a dictionary whose values are example inputs compatible with this component.
Keys of the dictionary are: raw, serialized
r   r   s    r   example_inputsSerializable.example_inputs#   r   r   c                n    U R                  5       nUR                  SUS   S   /S-  5      nUS   US   4$ )Nserialized_inputinfotype   r      r   getr   r   typess      r   input_api_infoSerializable.input_api_info+   sC    ==?/(62B62J1Ka1OPa%(##r   c                n    U R                  5       nUR                  SUS   S   /S-  5      nUS   US   4$ )Nserialized_outputr   r    r!   r   r"   r#   r%   s      r   output_api_infoSerializable.output_api_info1   sC    ==?08F3CF3K2Lq2PQa%(##r   c                    U$ )zM
Convert data from human-readable format to serialized format for a browser.
 r   xload_dirallow_linkss       r   	serializeSerializable.serialize6   s	     r   Nc                    U$ )zM
Convert data from serialized format for a browser to human-readable format.
r.   r   r0   save_dirroot_urlhf_tokens        r   deserializeSerializable.deserialize<   s	     r   r.   )returnzdict[str, list[str]]r<   zdict[str, Any])r<   ztuple[str, str] F)r0   r   r1   
str | Pathr2   boolNNN)r0   r   r7   str | Path | Noner8   
str | Noner9   rD   )__name__
__module____qualname____firstlineno__r   r   r   r'   r+   r3   r:   __static_attributes__r.   r   r   r
   r
      s[    $$$$
 '+##

 $
 	

 
 
r   r
   c                  ,    \ rS rSrSrSS jrSS jrSrg)	SimpleSerializableI   zIGeneral class that does not perform any serialization or deserialization.c                    [         S   SS.$ )NrK   Fr   r   serializer_typesr   s    r   r   SimpleSerializable.api_infoL       $%9:$
 	
r   c                    S S S.$ )Nraw
serializedr.   r   s    r   r   !SimpleSerializable.example_inputsR       
 	
r   r.   Nr<   zdict[str, bool | dict]r=   rE   rF   rG   rH   __doc__r   r   rI   r.   r   r   rK   rK   I   s    S

r   rK   c                  ,    \ rS rSrSrSS jrSS jrSrg)	StringSerializableY   z?Expects a string as input/output but performs no serialization.c                    [         S   SS.$ )Nr]   FrN   rO   r   s    r   r   StringSerializable.api_info\   rR   r   c                    SSS.$ )NHowdy!rT   r.   r   s    r   r   !StringSerializable.example_inputsb   s    "
 	
r   r.   NrY   r=   rZ   r.   r   r   r]   r]   Y   s    I

r   r]   c                  ,    \ rS rSrSrSS jrSS jrSrg)	ListStringSerializablei   zHExpects a list of strings as input/output but performs no serialization.c                    [         S   SS.$ )Nre   FrN   rO   r   s    r   r   ListStringSerializable.api_infol   s    $%=>$
 	
r   c                    SS/SS/S.$ )Nrb   MerhabarT   r.   r   s    r   r   %ListStringSerializable.example_inputsr   s    i(#Y/
 	
r   r.   NrY   r=   rZ   r.   r   r   re   re   i   s    R

r   re   c                  ,    \ rS rSrSrSS jrSS jrSrg)	BooleanSerializabley   z@Expects a boolean as input/output but performs no serialization.c                    [         S   SS.$ )Nrm   FrN   rO   r   s    r   r   BooleanSerializable.api_info|   s    $%:;$
 	
r   c                    SSS.$ )NTrT   r.   r   s    r   r   "BooleanSerializable.example_inputs   rX   r   r.   NrY   r=   rZ   r.   r   r   rm   rm   y   s    J

r   rm   c                  ,    \ rS rSrSrSS jrSS jrSrg)	NumberSerializable   zKExpects a number (int/float) as input/output but performs no serialization.c                    [         S   SS.$ )Nrt   FrN   rO   r   s    r   r   NumberSerializable.api_info   rR   r   c                    SSS.$ )N   rT   r.   r   s    r   r   !NumberSerializable.example_inputs   s    
 	
r   r.   NrY   r=   rZ   r.   r   r   rt   rt      s    U

r   rt   c                  x    \ rS rSrSrS rS
S jrSS jr  S       SS jjr   S         SS jjr	S	r
g)ImgSerializable   zJExpects a base64 string as input/output which is serialized to a filepath.c                    SSS.$ )Nstringz+filepath on your computer (or URL) of imager    descriptionr.   r   s    r   r   ImgSerializable.serialized_info   s    H
 	
r   c                    [         S   SS.$ )Nr|   TrN   rO   r   s    r   r   ImgSerializable.api_info   s    ():;PTUUr   c                (    [         R                  SS.$ )NPhttps://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.pngrT   r   BASE64_IMAGEr   s    r   r   ImgSerializable.example_inputs   s    **l
 	
r   c                    U(       d  g[         R                  " U5      (       a  [         R                  " U5      $ [         R                  " [	        U5      U-  5      $ )z
Convert from human-friendly version of a file (string filepath) to a serialized
representation (base64).
Parameters:
    x: String path to file to serialize
    load_dir: Path to directory containing x
N)r   is_http_url_likeencode_url_to_base64encode_file_to_base64r   r/   s       r   r3   ImgSerializable.serialize   sF     !!!$$--a00**4>A+=>>r   Nc                V    Ub  US:X  a  g[         R                  " XS9nUR                  $ )aq  
Convert from serialized representation of a file (base64) to a human-friendly
version (string filepath). Optionally, save the file to the directory specified by save_dir
Parameters:
    x: Base64 representation of image to deserialize into a string filepath
    save_dir: Path to directory to save the deserialized image to
    root_url: Ignored
    hf_token: Ignored
Nr?   dir)r   decode_base64_to_filename)r   r0   r7   r8   r9   files         r   r:   ImgSerializable.deserialize   s,      9R**1;yyr   r.   rY   r=   r>   )r0   rD   r1   r@   r2   rA   r<   rD   rB   )
r0   rD   r7   rC   r8   rD   r9   rD   r<   rD   )rE   rF   rG   rH   r[   r   r   r   r3   r:   rI   r.   r   r   r|   r|      s    T
V
  "!	?? ? 	?
 
?, '+## $ 	
  
 r   r|   c                    ^  \ rS rSrSrSU 4S jjrS rS rS rS r	S r
SS	 jrSS
 jrSS jrSS jr  S       SS jjrS r   S         SS jjr  S       SS jjr   S         SS jjrSrU =r$ )FileSerializable   zfExpects a dict with base64 representation of object as input/output which is serialized to a filepath.c                >   > S U l         S U l        [        TU ]  5         g N)streamstream_namesuper__init__)r   	__class__s    r   r   FileSerializable.__init__   s    r   c                "    U R                  5       $ r   )_single_file_serialized_infor   s    r   r    FileSerializable.serialized_info   s    0022r   c                    [         S   SS.$ )NSingleFileSerializableTrN   rO   r   s    r   _single_file_api_info&FileSerializable._single_file_api_info   s    $%=>#
 	
r   c                    SSS.$ )Nr   *filepath on your computer (or URL) of filer   r.   r   s    r   r   -FileSerializable._single_file_serialized_info   s    G
 	
r   c                    SSSSS.S.$ )Narrayz&List of filepath(s) or URL(s) to filesr   r   r   )r    r   itemsr.   r   s    r   _multiple_file_serialized_info/FileSerializable._multiple_file_serialized_info   s    C K
 	
r   c                    [         S   SS.$ )NMultipleFileSerializableTrN   rO   r   s    r   _multiple_file_api_info(FileSerializable._multiple_file_api_info   s    $%?@#
 	
r   c                "    U R                  5       $ r   )r   r   s    r   r   FileSerializable.api_info   s    ))++r   c                "    U R                  5       $ r   )_single_file_example_inputsr   s    r   r   FileSerializable.example_inputs   s    //11r   c                .    S[         R                  S.SS.$ NFis_filedatazMhttps://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdfrT   r   BASE64_FILEr   s    r   r   ,FileSerializable._single_file_example_inputs  s    $j.D.DEi
 	
r   c                2    S[         R                  S./S/S.$ r   r   r   s    r   _multiple_file_example_inputs.FileSerializable._multiple_file_example_inputs  s%     %z/E/EFG_
 	
r   c                j   Ub  [        U[        5      (       a  U$ [        R                  " U5      (       a  UnS nO:[	        [        U5      U-  5      n[        U5      R                  5       R                  nU=(       d    S U(       a  S O[        R                  " U5      [        U5      R                  US.$ )N)r   r   	orig_namesize)

isinstancedictr   r   strr   statst_sizeencode_url_or_file_to_base64r   )r   r0   r1   r2   filenamer   s         r   _serialize_single"FileSerializable._serialize_single  s     9
1d++H!!!$$HD4>A-.H>&&(00D$ 33H=h,,
 	
r   c                .    [         R                  " X5      $ r   )r   download_byte_stream)r   urlr9   s      r   _setup_streamFileSerializable._setup_stream&  s    ))#88r   c                p   Uc  g [        U[        5      (       a   [        R                  " XS9R                  nU$ [        U[
        5      (       Ga  UR                  S5      (       aZ  UR                  S5      nUc  [        SU 35      eUb  [        R                  " US-   U-   UUS9nU$ [        R                  " XbS9n U$ UR                  S5      (       Ga  US   (       a  U(       a  U(       d  [        S5      eU R                  (       a  U R                  US   :w  a(  U R                  US	-   US   -   US
9U l
        US   U l        [        U R                  5      n[        U=(       d    [        R                   " 5       5      ["        R$                  " S5      -  nUR'                  SSS9  XR                  SS5      -  nUR)                  U5        [        U5      nU$ UR                  S5      n	U	c  [        SU 35      e[        R                  " XS9R                  n U$ [        S[+        U5       SU 35      e)Nr   r   r   zThe 'name' field is missing in zfile=)r9   r   	is_streamz2name and root_url and save_dir must all be presentzstream/)r9   r   T)parentsexist_okr   outputr   zThe 'data' field is missing in zLA FileSerializable component can only deserialize a string or a dict, not a z: )r   r   r   r   r   r   r$   
ValueErrordownload_tmp_copy_of_filecreate_tmp_copy_of_filer   r   r   nextr   tempfile
gettempdirsecrets	token_hexmkdirwrite_bytesr    )
r   r0   r7   r8   r9   	file_namefilepathchunkpathr   s
             r   _deserialize_single$FileSerializable._deserialize_single)  s/    9a33ADIIIN M 4  uuY55=#$'Fqc%JKK' % ? ? 7*X5!)$!I@ 5 !& = =h UI4 3 {##&	h8$L  {{d&6&6!F)&C"&"4"4 9,qy88 #5 #DK ()yD$T[[)H=(;(;(=>ARARSUAVV

4$
7eeK::  'I	  uuV}<$'Fqc%JKK!77KPP	
  ^_cde_f^ggijkilm r   c                    Ub  US:X  a  g[        U[        5      (       a"  U Vs/ s H  o@R                  XBU5      PM     sn$ U R                  XU5      $ s  snf )a  
Convert from human-friendly version of a file (string filepath) to a
serialized representation (base64)
Parameters:
    x: String path to file to serialize
    load_dir: Path to directory containing x
    allow_links: Will allow path returns instead of raw file content
Nr?   )r   listr   )r   r0   r1   r2   fs        r   r3   FileSerializable.serialize\  sX     9RaNOPa**1DaPP))!{CC Qs   Ac           
         Uc  g[        U[        5      (       a  [        U5      n[        U[        5      (       a!  U Vs/ s H  nU R	                  XRX4S9PM     sn$ U R	                  XX4S9$ s  snf )a  
Convert from serialized representation of a file (base64) to a human-friendly
version (string filepath). Optionally, save the file to the directory specified by `save_dir`
Parameters:
    x: Base64 representation of file to deserialize into a string filepath
    save_dir: Path to directory to save the deserialized file to
    root_url: If this component is loaded from an external Space, this is the URL of the Space.
    hf_token: If this component is loaded from an external private Space, this is the access token for the Space
N)r7   r8   r9   )r   r   r   r   r   )r   r0   r7   r8   r9   r   s         r   r:   FileSerializable.deserializeq  s      9h%%8}Ha
 	 A ((8 )  	  ++x ,  s   A+)r   r   )r<   Noner<   zdict[str, dict | bool]r=   r>   )r0   str | FileData | Noner1   r@   r2   rA   r<   zFileData | NonerB   )
r0   r   r7   rD   r8   rD   r9   rD   r<   rD   )r0   3str | FileData | None | list[str | FileData | None]r1   r@   r2   rA   r<   z'FileData | None | list[FileData | None])
r0   r   r7   Path | str | Noner8   rD   r9   rD   r<   zstr | None | list[str | None])rE   rF   rG   rH   r[   r   r   r   r   r   r   r   r   r   r   r   r   r   r3   r:   rI   __classcell__r   s   @r   r   r      s.   p
3



,2

  "!	
 
 
 	

 

.9  $##1 1 1 	1
 1 
1l  "!	D>D D 	D
 
1D0 '+##> $ 	
  
' r   r   c                     ^  \ rS rSrS rSS jrS	S jr S
       SU 4S jjjr   S         SU 4S jjjrSr	U =r
$ )VideoSerializablei  c                    SSS.$ )Nr   z0filepath on your computer (or URL) of video filer   r.   r   s    r   r   !VideoSerializable.serialized_info  s    M
 	
r   c                    [         S   SS.$ )Nr   TrN   rO   r   s    r   r   VideoSerializable.api_info      ();<QUVVr   c                .    S[         R                  S.SS.$ )NFr   zNhttps://github.com/gradio-app/gradio/raw/main/test/test_files/video_sample.mp4rT   )r   BASE64_VIDEOr   s    r   r    VideoSerializable.example_inputs  s    $j.E.EFj
 	
r   c                (   > [         TU ]  XU5      S 4$ r   )r   r3   )r   r0   r1   r2   r   s       r   r3   VideoSerializable.serialize  s     !!{;TBBr   c                   > [        U[        [        45      (       a(  [        U5      S:w  a  [	        SU 35      eUS   US   /nO[	        SU 35      e[
        TU ]  XRX45      n[        U[        5      (       a  US   $ g)z
Convert from serialized representation of a file (base64) to a human-friendly
version (string filepath). Optionally, save the file to the directory specified by `save_dir`
r!   z&Expected tuple of length 2. Received: r   r"   N)r   tupler   lenr   r   r:   )r   r0   r7   r8   r9   	x_as_listdeserialized_filer   s          r   r:   VideoSerializable.deserialize  s     a%''1v{ #I!!MNN1qtIEaSIJJ!G/	XX'..$Q'' /r   r.   r   r=   r>   )r0   rD   r1   r@   r2   rA   r<   ztuple[FileData | None, None]rB   )
r0   z.tuple[FileData | None, FileData | None] | Noner7   r   r8   rD   r9   rD   r<   z*str | tuple[str | None, str | None] | None)rE   rF   rG   rH   r   r   r   r3   r:   rI   r   r   s   @r   r   r     s    
W
 MRCC'1CEIC	%C C '+##(9( $( 	(
 ( 
4( (r   r   c                  t    \ rS rSrS rS	S jrS
S jr  S       SS jjr   S         SS jjrSr	g)JSONSerializablei  c                    SSS.$ )Nr   zfilepath to JSON filer   r.   r   s    r   r    JSONSerializable.serialized_info  s     1HIIr   c                    [         S   SS.$ )Nr
  TrN   rO   r   s    r   r   JSONSerializable.api_info  r   r   c                    SSS.S S.$ )Nr"   r!   )abrT   r.   r   s    r   r   JSONSerializable.example_inputs  s    #
 	
r   c                Z    Ub  US:X  a  g[         R                  " [        U5      U-  5      $ )z
Convert from a a human-friendly version (string path to json file) to a
serialized representation (json string)
Parameters:
    x: String path to json file to read to get json string
    load_dir: Path to directory containing x
Nr?   )r   file_to_jsonr   r/   s       r   r3   JSONSerializable.serialize  s,     9R!!$x.1"455r   Nc                F    Uc  g[         R                  " XS9R                  $ )a6  
Convert from serialized representation (json string) to a human-friendly
version (string path to json file).  Optionally, save the file to the directory specified by `save_dir`
Parameters:
    x: Json string
    save_dir: Path to save the deserialized json file to
    root_url: Ignored
    hf_token: Ignored
Nr   )r   dict_or_str_to_json_filer   r6   s        r   r:   JSONSerializable.deserialize  s#      9--a>CCCr   r.   r   r=   r>   )r0   rD   r1   r@   r2   rA   r<   zdict | list | NonerB   )
r0   zstr | dict | listr7   rC   r8   rD   r9   rD   r<   rD   
rE   rF   rG   rH   r   r   r   r3   r:   rI   r.   r   r   r
  r
    s    JW
  "!	66 6 	6
 
6( '+##DD $D 	D
 D 
D Dr   r
  c                  r    \ rS rSrS rS	S jrS
S jr S       SS jjr   S         SS jjrSr	g)GallerySerializablei  c                    SSS.$ )Nr   z^path to directory with images and a file associating images with captions called captions.jsonr   r.   r   s    r   r   #GallerySerializable.serialized_info  s    {
 	
r   c                    [         S   SS.$ )Nr  TrN   rO   r   s    r   r   GallerySerializable.api_info  s    $%:;#
 	
r   c                8    [         R                  /S-  S/S-  S.$ )Nr!   r   rT   r   r   s    r   r   "GallerySerializable.example_inputs  s/    ++,q0b 
 	
r   c                @   Ub  US:X  a  g / n[        U5      S-  nUR                  S5       n[        R                  " U5      nS S S 5        WR	                  5        H.  u  p[        5       R                  XS9n
UR                  X/5        M0     U$ ! , (       d  f       NR= f)Nr?   captions.jsonr)r2   )r   openjsonloadr   r   r3   append)r   r0   r1   r2   filescaptions_filecaptions_jsoncaptionsr   captionimgs              r   r3   GallerySerializable.serialize  s     9RQ/1$yy/H %"*.."2I"$..y.RCLL#( #3  %$s   B
BNc                   Uc  g [        U5      [        [        R                  " 5       5      -  nUR	                  SSS9  0 nU Hv  n[        U[        [        45      (       a  Uu  pxOS n[        5       R                  XuX4S9n	XU	'   US-  n
U
R                  S5       n[        R                  " Xk5        S S S 5        Mx     [        R                  R                  U5      $ ! , (       d  f       M  = f)NT)r   r   )r8   r9   r#  w)r   r   uuiduuid4r   r   r   r  r   r:   r%  r&  dumposr   abspath)r   r0   r7   r8   r9   gallery_pathr,  img_datar-  r   r*  r+  s               r   r:   GallerySerializable.deserialize  s     9H~DJJL(99D$7H(T5M22$,!'#%11 2 D %TN(?:M##C(M		(2 )(  ww|,, )(s   C
C+	r.   r   r=   r>   )r0   rD   r1   r@   r2   rA   r<   list[list[str | None]] | None)r?   NN)
r0   r:  r7   r   r8   rD   r9   rD   r<   z
None | strr  r.   r   r   r  r    s    


 MR'1EI	&" ##-(- - 	-
 - 
- -r   r  FileUploadButtontextboxnumberslidercheckboxcheckboxgroupradiodropdownimagevideoaudior   	dataframe
timeseriesfileexplorerstatebuttonuploadbutton)colorpickerlabelhighlightedtextr&  htmlgallerychatbotmodel3dplotbarplotlineplotscatterplotmarkdowncodeannotatedimagezdict[str, type]COMPONENT_MAPPING))r[   
__future__r   r&  r5  r   r   r2  pathlibr   typingr   gradio_clientr   r   gradio_client.data_classesr   r%  __file__parentr   r'  rP   r
   rK   r]   re   rm   rt   r|   r   r   r
  r  SERIALIZER_MAPPING__subclasses__clsrE   subclsr[  __annotations__r.   r   r   <module>rh     st   @ "  	      + /	$x.

,
./1yy| 02 2j
 
 
 
 
\ 
 
, 
 
 
 8l 8v{| {|((( ((V0D| 0Df<-, <-~  &&(C'*s||$$$&.46??+ ' )
 &8 > "- 6 %5 > "!&!!& !&  !& #	!&
 +!& !& "!& _!& !& !& !& !!& "!& $!& !&   !!&" $#!&$ &'" #"&A!& ? !S 0/s   F
F