o
    ٷi1                     @  sR  d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	m
Z
 ddlmZmZ ddlmZmZmZmZmZ ddlmZ dd	lmZ dd
lmZ ddl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( ddl)m*Z* ddl+m,Z,m-Z- ddl.m/Z/ zddlm0Z0 W n e1y   eZ0Y nw ede2Z3ede2Z4G dd deZ5G dd deZ6G dd dZ7eee7f Z8G dd deZ9G dd de9Z:G dd deZ;G d d! d!eZ<G d"d# d#eZ=G d$d% d%eZ>G d&d' d'eZ?G d(d) d)eZ@G d*d+ d+eZAG d,d- d-eZBG d.d/ d/e#ZCG d0d1 d1eBeZDG d2d3 d3eBe#ZEeeDeEf ZFG d4d5 d5e-ZGG d6d7 d7e-ZHe G d8d9 d9eDZIG d:d; d;eEZJG d<d= d=ZKG d>d? d?e-ZLG d@dA dAe-ZMG dBdC dCe-ZNG dDdE dEe-ZOG dFdG dGe-ZPG dHdI dIeDZQG dJdK dKeDZRG dLdM dMe-ZSG dNdO dOe-ZTG dPdQ dQe-ZUdS )RzPydantic data models and other dataclasses. This is the only file that uses Optional[]
typing syntax instead of | None syntax to work with pydantic    )annotationsN)ABCabstractmethod)Iterator)Enumauto)	AnnotatedAnyLiteralNewTypeUnion)Request)ParameterInfo)document)is_file_obj_with_metatraverse)		BaseModel
ConfigDictFieldGetCoreSchemaHandlerGetJsonSchemaHandler	RootModelValidationErrorValidationInfomodel_validator)JsonSchemaValue)core_schema)NotRequired	TypedDict)I18nData)	JsonValueDeveloperPathUserProvidedPathc                   @  s&   e Zd ZU ded< ded< ded< dS )
CancelBodystrsession_hashintfn_indexevent_idN__name__
__module____qualname____annotations__ r.   r.   G/home/ubuntu/.local/lib/python3.10/site-packages/gradio/data_classes.pyr#   2      
 r#   c                   @  s"   e Zd ZU ded< dZded< dS )SimplePredictBody	list[Any]dataN
str | Noner%   )r*   r+   r,   r-   r%   r.   r.   r.   r/   r1   8   s   
 r1   c                   @  s(   e Zd ZedddZedddZdS )#_StarletteRequestPydanticAnnotation_source_typer	   _handlerr   returncore_schema.CoreSchemac                 C  s   ddd}t |S )Nvaluer	   r8   r   c                 S  s   t | tr| S td)Nz(Input must be a Starlette Request object)
isinstancer   
ValueError)r:   r.   r.   r/   validate_requestD   s   
zZ_StarletteRequestPydanticAnnotation.__get_pydantic_core_schema__.<locals>.validate_request)r:   r	   r8   r   )r    no_info_plain_validator_function)clsr6   r7   r=   r.   r.   r/   __get_pydantic_core_schema__>   s   

z@_StarletteRequestPydanticAnnotation.__get_pydantic_core_schema___core_schemahandlerr   r   c                 C  s
   dddS )NobjectStarletteRequest)typetitler.   )r?   rA   rB   r.   r.   r/   __get_pydantic_json_schema__K   s   
z@_StarletteRequestPydanticAnnotation.__get_pydantic_json_schema__N)r6   r	   r7   r   r8   r9   )rA   r9   rB   r   r8   r   )r*   r+   r,   classmethodr@   rG   r.   r.   r.   r/   r5   =   s
    r5   c                   @  sv   e Zd ZU dZded< dZded< ded< dZded< dZd	ed
< dZd	ed< dZ	ded< dZ
ded< edd ZdS )PredictBodyNr4   r%   r(   r2   r3   z
Any | None
event_data
int | Noner'   
trigger_idFboolsimple_formatzbool | Nonebatchedc                 C  sH   ddddiddidddidddiddiddiddiddid	d
gdS )NrI   rC   rE   stringarray)rE   itemsintegerboolean)r%   r(   r3   rJ   r'   rL   rN   rO   r3   )rF   rE   
propertiesrequiredr.   )r?   r   rB   r.   r.   r/   rG   a   s   
z(PredictBody.__get_pydantic_json_schema__)r*   r+   r,   r%   r-   r(   rJ   r'   rL   rN   rO   rH   rG   r.   r.   r.   r/   rI   U   s   
 
rI   c                   @  s   e Zd ZU dZdZded< dS )PredictBodyInternalzOSeparate class to avoid exposing PydanticStarletteRequest in the API validationNzPydanticStarletteRequest | Nonerequest)r*   r+   r,   __doc__rX   r-   r.   r.   r.   r/   rW   t   s   
 rW   c                   @     e Zd ZU ded< dS )	ResetBodyr$   r(   Nr)   r.   r.   r.   r/   r[   |      
 r[   c                   @  rZ   )VibeEditBodyr$   promptNr)   r.   r.   r.   r/   r]      r\   r]   c                   @  rZ   )VibeCodeBodyr$   codeNr)   r.   r.   r.   r/   r_      r\   r_   c                   @  .   e Zd ZU ded< ded< ded< ded< dS )	ComponentServerJSONBodyr$   r%   r&   component_idfn_namer	   r3   Nr)   r.   r.   r.   r/   rb      
   
 rb   c                   @     e Zd ZU ded< ded< dS )DataWithFilesr	   r3   zlist[tuple[str, bytes]]filesNr)   r.   r.   r.   r/   rg         
 rg   c                   @  ra   )	ComponentServerBlobBodyr$   r%   r&   rc   rd   rg   r3   Nr)   r.   r.   r.   r/   rj      re   rj   c                   @  s$   e Zd Ze Ze Ze Ze ZdS )InterfaceTypesN)r*   r+   r,   r   STANDARD
INPUT_ONLYOUTPUT_ONLYUNIFIEDr.   r.   r.   r/   rk      s
    
rk   c                   @  s(   e Zd Zd
ddZeedddZd	S )GradioBaseModeldirstr | pathlib.Pathr8   GradioDataModelc                   sJ   t | ttfstdt  d fdd}| jjt| 	 |t
jdS )Nz must be used in a Pydantic modelobjdictc                   s0   t di | }|tt td  S )N
   r.   )FileData_copy_to_dirr$   pathlibPathsecrets	token_hex
model_dump)rt   r3   rq   r.   r/   unique_copy   s   z0GradioBaseModel.copy_to_dir.<locals>.unique_copy)x)rt   ru   )r;   r   r   	TypeErrorry   rz   	__class__	from_jsonr   r}   rw   is_file_data)selfrq   r   r.   r~   r/   copy_to_dir   s   
zGradioBaseModel.copy_to_dirc                 C  s   d S Nr.   r?   r   r.   r.   r/   r      s   zGradioBaseModel.from_jsonN)rq   rr   r8   rs   )r8   rs   )r*   r+   r,   r   rH   r   r   r.   r.   r.   r/   rp      s
    
rp   c                   @  s   e Zd ZU dZded< dS )JsonDatazHJSON data returned from a component that should not be modified further.r    rootN)r*   r+   r,   rY   r-   r.   r.   r.   r/   r      s   
 r   c                   @     e Zd ZedddZdS )GradioModelr8   c                 C  s   | di |S )Nr.   r.   r   r.   r.   r/   r      s   zGradioModel.from_jsonN)r8   r   r*   r+   r,   rH   r   r.   r.   r.   r/   r          r   c                   @  r   )GradioRootModelr8   c                 C  
   | |dS )Nr   r.   r   r.   r.   r/   r         
zGradioRootModel.from_jsonN)r8   r   r   r.   r.   r.   r/   r      r   r   c                   @  sF   e Zd ZU ded< ded< ded< ded< ded< d	ed
< ded< dS )FileDataDictr$   pathNotRequired[str | None]urlzNotRequired[int | None]size	orig_name	mime_typerM   	is_streamzNotRequired[dict]metaNr)   r.   r.   r.   r/   r      s   
 r   c                   @  rZ   )FileDataMetazLiteral['gradio.FileData']_typeNr)   r.   r.   r.   r/   r      r\   r   c                   @  s   e Zd ZU dZded< dZded< dZded< dZded	< dZded
< dZ	ded< e
dd dZded< edded%ddZed&ddZed'ddZd(dd Zed)d#d$ZdS )*rw   ad  
    The FileData class is a subclass of the GradioModel class that represents a file object within a Gradio interface. It is used to store file data and metadata when a file is uploaded.

    Attributes:
        path: The server file path where the file is stored.
        url: The normalized server URL pointing to the file.
        size: The size of the file in bytes.
        orig_name: The original filename before upload.
        mime_type: The MIME type of the file.
        is_stream: Indicates whether the file is a stream.
        meta: Additional metadata used internally (should not be changed).
    r$   r   Nr4   r   rK   r   r   r   FrM   r   c                   C  s   ddiS )Nr   gradio.FileDatar.   r.   r.   r.   r/   <lambda>   s    zFileData.<lambda>)default_factoryr   r   before)modeinfor   c                 C  s&   |j r|j drt|std|S )Nvalidate_metazlThe 'meta' field must be explicitly provided in the input data and be equal to {'_type': 'gradio.FileData'}.)contextgetr   r<   )r?   vr   r.   r.   r/   validate_model   s   
zFileData.validate_modelr8   c                 C  s&   t dd | j| j| j| j| jfD S )z
        Checks if the FileData object is empty, i.e., all attributes are None.

        Returns:
            bool: True if all attributes (except 'is_stream' and 'meta') are None, False otherwise.
        c                 s  s    | ]}|d u V  qd S r   r.   ).0fr.   r.   r/   	<genexpr>  s
    
z#FileData.is_none.<locals>.<genexpr>)allr   r   r   r   r   r   r.   r.   r/   is_none  s   zFileData.is_nonec                 C  r   )z
        Creates a FileData object from a given file path.

        Args:
            path: The file path.

        Returns:
            FileData: An instance of FileData representing the file at the specified path.
        )r   r.   )r?   r   r.   r.   r/   	from_path  s   
zFileData.from_pathrq   c                 C  sN   t |jdd t| }| jstdt| j|}||d< | jdi |S )a^  
        Copies the file to a specified directory and returns a new FileData object representing the copied file.

        Args:
            dir: The destination directory.

        Returns:
            FileData: A new FileData object representing the copied file.

        Raises:
            ValueError: If the source file path is not set.
        T)exist_okzSource file path is not setr   Nr.   )	ry   rz   mkdirru   r   r<   shutilcopyr   )r   rq   new_objnew_namer.   r.   r/   rx   $  s   zFileData._copy_to_dirrt   r	   c              	   C  s<   t |trz
tdi |j W S  ttfy   Y dS w dS )z
        Checks if an object is a valid FileData instance.

        Args:
            obj: The object to check.

        Returns:
            bool: True if the object is a valid FileData instance, False otherwise.
        FNr.   )r;   ru   rw   r   r   r   )r?   rt   r.   r.   r/   r   :  s   
zFileData.is_file_data)r   r   )r8   rM   )r   r$   r8   rw   )rq   r$   r8   rw   )rt   r	   r8   rM   )r*   r+   r,   rY   r-   r   r   r   r   r   r   r   r   rH   r   propertyr   r   rx   r   r.   r.   r.   r/   rw      s&   
 
rw   c                   @  s(   e Zd ZU ded< dd Zd
ddZd	S )	ListFileszlist[FileData]r   c                 C  s
   | j | S r   r   )r   indexr.   r.   r/   __getitem__P     
zListFiles.__getitem__r8   Iterator[FileData]c                 C  s
   t | jS r   )iterr   r   r.   r.   r/   __iter__S  r   zListFiles.__iter__N)r8   r   )r*   r+   r,   r-   r   r   r.   r.   r.   r/   r   M  s   
 r   c                   @  s*   e Zd ZdZg ZdddZedd	 Zd
S )_StaticFilesz3
    Class to hold all static files for an app
    pathslist[str | pathlib.Path]r8   Nonec                 C  s   || _ dd |D | _d S )Nc                 S  s   g | ]	}t | qS r.   )ry   rz   resolve)r   pr.   r.   r/   
<listcomp>`  s    z)_StaticFiles.__init__.<locals>.<listcomp>)r   	all_paths)r   r   r.   r.   r/   __init__^  s   z_StaticFiles.__init__c                 C  s
   g | _ d S r   )r   )r?   r.   r.   r/   clearb  r   z_StaticFiles.clearN)r   r   r8   r   )r*   r+   r,   rY   r   r   rH   r   r.   r.   r.   r/   r   W  s    
r   c                   @  s.   e Zd ZU ded< ded< ded< ded< dS )BodyCSSr$   body_background_fillbody_text_colorbody_background_fill_darkbody_text_color_darkNr)   r.   r.   r.   r/   r   g  re   r   c                   @  rf   )Layoutr&   idzNotRequired[list[int | Layout]]childrenNr)   r.   r.   r.   r/   r   n  ri   r   c                   @  s&   e Zd ZU ded< ded< ded< dS )Pagez	list[int]
componentsdependenciesr   layoutNr)   r.   r.   r.   r/   r   s  r0   r   c                   @  s6  e Zd ZU ded< ded< ded< ded< ded	< ded
< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< d ed!< d"ed#< ded$< ded%< ded&< d'ed(< d)ed*< d+ed,< d+ed-< ded.< d/ed0< d1ed2< d3ed4< d5ed6< d7ed8< d/ed9< d:S );BlocksConfigDictr$   versionz0NotRequired[Literal['valid', 'invalid', 'none']]deep_link_stater   r&   app_idrM   dev_mode	vibe_modeanalytics_enabledzlist[dict[str, Any]]r   r4   cssconnect_heartbeatzstr | Literal[True] | Nonejsheadzstr | I18nDatarF   space_idenable_queue
show_errorshow_apiis_colabrK   max_file_sizez	list[str]stylesheetsthemez>Literal['ws', 'sse', 'sse_v1', 'sse_v2', 'sse_v2.1', 'sse_v3']protocolr   body_cssfill_height
fill_width
theme_hashzNotRequired[Layout]r   z!NotRequired[list[dict[str, Any]]]r   r   r   username
api_prefixzNotRequired[bool]pwazdict[str, Page]pagezlist[tuple[str, str]]pagesNotRequired[str]current_pagez-NotRequired[dict[str, dict[str, str]] | None]i18n_translations
mcp_serverNr)   r.   r.   r.   r/   r   y  sL   
 r   c                   @  .   e Zd ZU ded< ded< ded< ded< d	S )
MediaStreamChunkbytesr3   floatdurationr$   	extensionr   r   Nr)   r.   r.   r.   r/   r     re   r   c                   @  s   e Zd ZU edddZded< edddZded< edddZd	ed
< edddZded< edddZ	ded< edddZ
ded< ddiZded< eddidZdS )	ImageDataNzPath to a local file)defaultdescriptionr4   r   z.Publicly available url or base64 encoded imager   zSize of image in bytesrK   r   zOriginal filenamer   zmime type of imager   FzCan always be set to FalserM   r   r   r   ru   r   r   zTFor input, either path or url must be provided. For output, path is always provided.)json_schema_extra)r*   r+   r,   r   r   r-   r   r   r   r   r   r   r   model_configr.   r.   r.   r/   r     s   
 
r   c                   @  s    e Zd ZU eddZded< dS )Base64ImageDatazbase64 encoded image)r   r$   r   N)r*   r+   r,   r   r   r-   r.   r.   r.   r/   r     s   
 r   c                   @  s.   e Zd ZU ded< ded< ded< ded< dS )	APIReturnInfor$   labelzdict[str, Any]rE   zdict[str, str]python_type	componentNr)   r.   r.   r.   r/   r    re   r  c                   @  r   )
APIEndpointInfor   r   zlist[ParameterInfo]
parameterszlist[APIReturnInfo]returnsrM   r   Nr)   r.   r.   r.   r/   r    re   r  c                   @  s   e Zd ZU ded< ded< dS )APIInfozdict[str, APIEndpointInfo]named_endpointsunnamed_endpointsNr)   r.   r.   r.   r/   r    ri   r  )VrY   
__future__r   ry   r{   r   abcr   r   collections.abcr   enumr   r   typingr   r	   r
   r   r   fastapir   gradio_client.data_classesr   gradio_client.documentationr   gradio_client.utilsr   r   pydanticr   r   r   r   r   r   r   r   r   pydantic.json_schemar   pydantic_corer   typing_extensionsr   r   gradio.i18nr   r    ImportErrorr$   r!   r"   r#   r1   r5   PydanticStarletteRequestrI   rW   r[   r]   r_   rb   rg   rj   rk   rp   r   r   r   rs   r   r   rw   r   r   r   r   r   r   r   r   r   r  r  r  r.   r.   r.   r/   <module>   sv    ,


l
(