o
    0j/                     @   s   d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ G dd de	eZ
G dd	 d	e	eZG d
d de	eZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZdS )    )	dataclass)datetime)Enum)Literal)parse_datetimec                   @   s@   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdS )
SpaceStagea  
    Enumeration of possible stage of a Space on the Hub.

    Value can be compared to a string:
    ```py
    assert SpaceStage.BUILDING == "BUILDING"
    ```

    Taken from https://github.com/huggingface/moon-landing/blob/main/server/repo_types/SpaceInfo.ts#L61 (private url).
    NO_APP_FILECONFIG_ERRORBUILDINGBUILD_ERRORRUNNINGRUNNING_BUILDINGRUNTIME_ERRORDELETINGSTOPPEDPAUSEDAPP_STARTINGRUNNING_APP_STARTINGN)__name__
__module____qualname____doc__r   r	   r
   r   r   r   r   r   r   r   r   r    r   r   [/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/huggingface_hub/_space_api.pyr      s    r   c                   @   st   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdS )SpaceHardwarea=  
    Enumeration of hardwares available to run your Space on the Hub.

    Value can be compared to a string:
    ```py
    assert SpaceHardware.CPU_BASIC == "cpu-basic"
    ```

    Taken from https://github.com/huggingface-internal/moon-landing/blob/main/server/repo_types/SpaceHardwareFlavor.ts (private url).
    z	cpu-basiczcpu-upgradezcpu-performancezcpu-xlZsprx8z	zero-a10gzt4-smallz	t4-mediumZl4x1Zl4x4Zl40sx1Zl40sx4Zl40sx8z
a10g-smallz
a10g-largeza10g-largex2za10g-largex4z
a100-largeZa100x4Za100x8Zh200Zh200x2Zh200x4Zh200x8Zinf2x6N)r   r   r   r   Z	CPU_BASICZCPU_UPGRADEZCPU_PERFORMANCEZCPU_XLZSPRX8Z	ZERO_A10GZT4_SMALLZ	T4_MEDIUMZL4X1ZL4X4ZL40SX1ZL40SX4ZL40SX8Z
A10G_SMALLZ
A10G_LARGEZA10G_LARGEX2ZA10G_LARGEX4Z
A100_LARGEZA100X4ZA100X8ZH200ZH200X2ZH200X4ZH200X8ZINF2X6r   r   r   r   r   1   s6    r   c                   @   s   e Zd ZdZdZdZdZdS )SpaceStoragea5  
    Enumeration of persistent storage available for your Space on the Hub.

    Value can be compared to a string:
    ```py
    assert SpaceStorage.SMALL == "small"
    ```

    Taken from https://github.com/huggingface/moon-landing/blob/main/server/repo_types/SpaceHardwareFlavor.ts#L24 (private url).
    ZsmallZmediumZlargeN)r   r   r   r   ZSMALLZMEDIUMZLARGEr   r   r   r   r   _   s
    r   c                   @   s   e Zd ZU dZed ed< eed< eed< dZedB ed< dZe	dB ed< dZ
edB ed	< dddZd
efddZd
efddZdS )Volumea  
    Describes a volume to mount in a Space or Job container.

    Args:
        type (`str`):
            Type of volume: `"bucket"`, `"model"`, `"dataset"`, or `"space"`.
        source (`str`):
            Source identifier, e.g. `"username/my-bucket"` or `"username/my-model"`.
        mount_path (`str`):
            Mount path inside the container, e.g. `"/data"`. Must start with `/`.
        revision (`str` or `None`):
            Git revision (only for repos, defaults to `"main"`).
        read_only (`bool` or `None`):
            Read-only mount. Forced `True` for repos, defaults to `False` for buckets.
        path (`str` or `None`):
            Subfolder prefix inside the bucket/repo to mount, e.g. `"path/to/dir"`.
    )ZbucketmodelZdatasetspacetypesource
mount_pathNrevision	read_onlypathreturnc                 K   sv   | dd| _|d | _| d}|d ur|n|d | _| d| _| d}|d ur-|n| d| _| d	| _d S )
Nr   r   r    	mountPathr!   r"   readOnlyr#   r$   )getr   r    r!   r"   r#   r$   )selfkwargsr!   r#   r   r   r   __init__   s   


zVolume.__init__c                 C   sR   | j | j| jd}| jdur| j|d< | jdur| j|d< | jdur'| j|d< |S )z6Serialize to the JSON payload expected by the Hub API.)r   r    r&   Nr"   r'   r$   )r   r    r!   r"   r#   r$   r)   datar   r   r   to_dict   s   





zVolume.to_dictc              	   C   sj   | j r	d| j  nd}| jrd| j nd}dddd| jd}d| j d| j | | d	| j | 	S )
zDReturn the volume as an HF handle in the format expected by the CLI./ @z:roz:rw)TFNzhf://zs/:)r$   r"   r(   r#   r   r    r!   )r)   r$   r"   ror   r   r   to_hf_handle   s   (zVolume.to_hf_handle)r%   N)r   r   r   r   r   __annotations__strr"   r#   boolr$   r+   dictr.   r4   r   r   r   r   r   p   s   
 

r   c                   @   sL   e Zd ZU ed ed< eeeedB f  ed< eed< deddfdd	Z	dS )
SpaceHotReloading)createdcanceledstatusNreplica_statusesrawr-   r%   c                 C   s   |d | _ |d | _|| _d S )Nr<   ZreplicaStatuses)r<   r=   r>   r,   r   r   r   r+      s   


zSpaceHotReloading.__init__)
r   r   r   r   r5   listtupler6   r8   r+   r   r   r   r   r9      s
   
 r9   c                   @   s   e Zd ZU dZeed< edB ed< edB ed< edB ed< edB ed< e	dB ed< e
e dB ed	< eed
< deddfddZdS )SpaceRuntimea  
    Contains information about the current runtime of a Space.

    Args:
        stage (`str`):
            Current stage of the space. Example: RUNNING.
        hardware (`str` or `None`):
            Current hardware of the space. Example: "cpu-basic". Can be `None` if Space
            is `BUILDING` for the first time.
        requested_hardware (`str` or `None`):
            Requested hardware. Can be different from `hardware` especially if the request
            has just been made. Example: "t4-medium". Can be `None` if no hardware has
            been requested yet.
        sleep_time (`int` or `None`):
            Number of seconds the Space will be kept alive after the last request. By default (if value is `None`), the
            Space will never go to sleep if it's running on an upgraded hardware, while it will go to sleep after 48
            hours on a free 'cpu-basic' hardware. For more details, see https://huggingface.co/docs/hub/spaces-gpus#sleep-time.
        volumes (`list[Volume]` or `None`):
            List of volumes mounted in the Space. Each volume is a [`Volume`] object describing its type, source,
            mount path, and optional settings. `None` if no volumes are attached.
        raw (`dict`):
            Raw response from the server. Contains more information about the Space
            runtime like number of replicas, number of cpu, memory size,...
    stageNhardwarerequested_hardware
sleep_timestoragehot_reloadingvolumesr>   r-   r%   c                 C   s   |d | _ |di d| _|di d| _|d| _|d| _|d }d ur2t|nd | _|d}|d urEd	d
 |D nd | _|| _	d S )NrB   rC   current	requestedZ	gcTimeoutrF   ZhotReloadingrH   c                 S   s   g | ]	}t d i |qS )r   )r   ).0vr   r   r   
<listcomp>   s    z)SpaceRuntime.__init__.<locals>.<listcomp>)
rB   r(   rC   rD   rE   rF   r9   rG   rH   r>   )r)   r-   Zraw_hrZraw_volumesr   r   r   r+      s   
 

zSpaceRuntime.__init__)r   r   r   r   r   r5   r   intr   r9   r?   r   r8   r+   r   r   r   r   rA      s   
 rA   c                   @   sH   e Zd ZU dZeed< edB ed< edB ed< dededdfdd	ZdS )
SpaceSecreta&  
    Contains information about a secret of a Space.

    Secret values are write-only and cannot be read back. Only the key, description,
    and last update time are returned by the API.

    Args:
        key (`str`):
            Secret key. Example: `"GITHUB_API_KEY"`
        description (`str` or None):
            Description of the secret. Example: `"Github API key to access the Github API"`.
        updated_at (`datetime` or None):
            datetime of the last update of the secret (if the secret has been updated at least once).
    keyNdescription
updated_atvaluesr%   c                 C   s<   || _ |d| _|d}|d urt|| _d S d | _d S )NrQ   	updatedAt)rP   r(   rQ   r   rR   r)   rP   rS   rR   r   r   r   r+      s   
 zSpaceSecret.__init__	r   r   r   r   r6   r5   r   r8   r+   r   r   r   r   rO      s   
 rO   c                   @   sP   e Zd ZU dZeed< eed< edB ed< edB ed< dededdfd	d
ZdS )SpaceVariablea  
    Contains information about the current variables of a Space.

    Args:
        key (`str`):
            Variable key. Example: `"MODEL_REPO_ID"`
        value (`str`):
            Variable value. Example: `"the_model_repo_id"`.
        description (`str` or None):
            Description of the variable. Example: `"Model Repo ID of the implemented model"`.
        updatedAt (`datetime` or None):
            datetime of the last update of the variable (if the variable has been updated at least once).
    rP   valueNrQ   rR   rS   r%   c                 C   sF   || _ |d | _|d| _|d}|d urt|| _d S d | _d S )NrX   rQ   rT   )rP   rX   r(   rQ   r   rR   rU   r   r   r   r+     s
   

 zSpaceVariable.__init__rV   r   r   r   r   rW     s   
 rW   c                   @   s   e Zd ZU dZeed< eed< eed< edB ed< edB ed< eed< eed	< ee dB ed
< e	dB ed< edB ed< edB ed< e
dB ed< edB ed< deddfddZdS )SpaceSearchResulta  A single result from the Spaces semantic search API.

    Returned by [`HfApi.search_spaces`].

    Attributes:
        id (`str`):
            ID of the Space (e.g. `"username/repo-name"`).
        author (`str`):
            Author of the Space.
        title (`str`):
            Display title of the Space.
        emoji (`str` or `None`):
            Emoji icon of the Space.
        sdk (`str` or `None`):
            SDK used by the Space (e.g. `"gradio"`, `"docker"`, `"static"`).
        likes (`int`):
            Number of likes.
        private (`bool`):
            Whether the Space is private.
        tags (`list[str]` or `None`):
            List of tags.
        runtime ([`SpaceRuntime`] or `None`):
            Runtime information (stage, hardware, etc.).
        ai_short_description (`str` or `None`):
            AI-generated short description.
        ai_category (`str` or `None`):
            AI-generated category (e.g. `"Image Generation"`).
        semantic_relevancy_score (`float` or `None`):
            Semantic relevancy score (0-1) relative to the search query.
        trending_score (`int` or `None`):
            Trending score.
    idauthortitleNemojisdklikesprivatetagsruntimeai_short_descriptionai_categorysemantic_relevancy_scoretrending_scorer-   r%   c                 C   s   | d}|d | _| dd| _| dd| _| d| _| d| _| dd	| _| d
d| _| d| _|r>t	|nd | _
| d| _| d| _| d| _| d| _d S )Nrb   rZ   r[   r0   r\   r]   r^   r_   r   r`   Fra   rc   rd   ZsemanticRelevancyScoreZtrendingScore)r(   rZ   r[   r\   r]   r^   r_   r`   ra   rA   rb   rc   rd   re   rf   )r)   r-   rb   r   r   r   r+   R  s   

zSpaceSearchResult.__init__)r   r   r   r   r6   r5   rN   r7   r?   rA   floatr8   r+   r   r   r   r   rY   !  s    
 !rY   N)dataclassesr   r   enumr   typingr   Zhuggingface_hub.utilsr   r6   r   r   r   r   r9   rA   rO   rW   rY   r   r   r   r   <module>   s(   .;/