
    +j.                        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m	Z	m
Z
  G d dee          Z G d d	ee          Z G d
 dee          Ze G d d                      Ze G d d                      Ze G d d                      Ze G d d                      Ze G d d                      Ze G d d                      ZdS )    )	dataclass)datetime)Enum)Literal)HfMountHfUriparse_datetimec                   B    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        ^/home/wildlama/visual-decline/.venv/lib/python3.11/site-packages/huggingface_hub/_space_api.pyr   r      sZ        	 	  K!LHKG)#MHGF!L1r   r   c                   V    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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	zero-a10gzt4-smallz	t4-mediuml4x1l4x4l40sx1l40sx4l40sx8z
a10g-smallz
a10g-largeza10g-largex2za10g-largex4z
a100-largea100x4a100x8N)r   r   r   r   	CPU_BASICCPU_UPGRADE	ZERO_A10GT4_SMALL	T4_MEDIUML4X1L4X4L40SX1L40SX4L40SX8
A10G_SMALL
A10G_LARGEA10G_LARGEX2A10G_LARGEX4
A100_LARGEA100X4A100X8r   r   r   r    r    1   ss        	 	 IK I HIDDFFFJJ!L!LJFFFFr   r    c                       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).
    smallmediumlargeN)r   r   r   r   SMALLMEDIUMLARGEr   r   r   r:   r:   U   s)        	 	 EFEEEr   r:   c                       e Zd ZU dZed         ed<   eed<   eed<   dZedz  ed<   dZe	dz  ed<   dZ
edz  ed	<   ddZd
efdZd
ef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"`.
    )bucketmodeldatasetspacetypesource
mount_pathNrevision	read_onlypathreturnc                 p   |                     dd          | _        |d         | _        |                     d          }||n|d         | _        |                     d          | _        |                     d          }||n|                     d          | _        |                     d	          | _        d S )
NrG   rD   rH   	mountPathrI   rJ   readOnlyrK   rL   )getrG   rH   rI   rJ   rK   rL   )selfkwargsrI   rK   s       r   __init__zVolume.__init__   s    JJvw//	X&ZZ,,
(2(>**F<DX

:..JJz**	&/&;KAXAXJJv&&			r   c                     | j         | j        | j        d}| j        
| j        |d<   | j        
| j        |d<   | j        
| j        |d<   |S )z6Serialize to the JSON payload expected by the Hub API.)rG   rH   rO   NrJ   rP   rL   )rG   rH   rI   rJ   rK   rL   rR   datas     r   to_dictzVolume.to_dict   sa     Ik
 

 =$#}D>%#~D9 9DLr   c                     t          t          | j        | j        | j        | j        pd          | j        | j                                                  S )zGReturn the volume as an HF mount URI in the format expected by the CLI. )rG   idrJ   path_in_repo)rH   rI   rK   )	r   r   rG   rH   rJ   rL   rI   rK   to_uri)rR   s    r   r]   zVolume.to_uri   sR    diDK$-^b^g^mkmnnnn
 
 
 &((		r   )rM   N)r   r   r   r   r   __annotations__strrJ   rK   boolrL   rT   dictrX   r]   r   r   r   rB   rB   f   s          $ 7
8888KKKOOOHcDj!Itd{!!!D#*' ' ' '          r   rB   c                   l    e Zd ZU ed         ed<   eeeedz  f                  ed<   eed<   deddfdZ	dS )	SpaceHotReloading)createdcanceledstatusNreplica_statusesrawrW   rM   c                 H    |d         | _         |d         | _        || _        d S )Nrf   replicaStatuses)rf   rg   rh   rV   s     r   rT   zSpaceHotReloading.__init__   s&    8n $%6 7r   )
r   r   r   r   r^   listtupler_   ra   rT   r   r   r   rc   rc      sq         )****5cDj12222	IIIT d      r   rc   c                       e Zd ZU dZeed<   edz  ed<   edz  ed<   edz  ed<   edz  ed<   e	ed<   e
dz  ed	<   ee         dz  ed
<   eed<   deddf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dev_modehot_reloadingvolumesrh   rW   rM   c                 2   |d         | _         |                    di                               d          | _        |                    di                               d          | _        |                    d          | _        |                    d          | _        |                    dd          | _        |                    d	          x}t          |          nd | _        |                    d
          }|d |D             nd | _	        || _
        d S )Nro   rp   current	requested	gcTimeoutrs   devModeFhotReloadingrv   c                 &    g | ]}t          d i |S )r   )rB   ).0vs     r   
<listcomp>z)SpaceRuntime.__init__.<locals>.<listcomp>   s"    999999r   )ro   rQ   rp   rq   rr   rs   rt   rc   ru   rv   rh   )rR   rW   raw_hrraw_volumess       r   rT   zSpaceRuntime.__init__   s    ']
R0044Y??"&((:r":":">">{"K"K((;//xx	**E22EIXXnE]E];]6:j.v666pthhy))=H=T99[9999Z^r   )r   r   r   r   r   r^   r    intr:   r`   rc   rk   rB   ra   rT   r   r   r   rn   rn      s          2 d""""%,,,,d
D    NNN$t++++&\D    	III
T 
d 
 
 
 
 
 
r   rn   c                   R    e Zd ZU dZeed<   edz  ed<   edz  ed<   dededdf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valuesrM   c                     || _         |                    d          | _        |                    d          }|t          |          nd | _        d S )Nr   	updatedAt)r   rQ   r   r	   r   rR   r   r   r   s       r   rT   zSpaceSecret.__init__   sL    !::m44ZZ,,
8B8N.444TXr   	r   r   r   r   r_   r^   r   ra   rT   r   r   r   r   r      s}           
HHHt4YC Y Y$ Y Y Y Y Y Yr   r   c                   \    e Zd ZU dZeed<   eed<   edz  ed<   edz  ed<   dededdf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).
    r   valueNr   r   r   rM   c                     || _         |d         | _        |                    d          | _        |                    d          }|t	          |          nd | _        d S )Nr   r   r   )r   r   rQ   r   r	   r   r   s       r   rT   zSpaceVariable.__init__  sW    G_
!::m44ZZ,,
8B8N.444TXr   r   r   r   r   r   r      s           
HHHJJJt4YC Y Y$ Y Y Y Y Y Yr   r   c                       e Zd ZU dZeed<   eed<   eed<   edz  ed<   edz  ed<   eed<   eed	<   ee         dz  ed
<   e	dz  ed<   edz  ed<   edz  ed<   e
dz  ed<   edz  ed<   deddf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.
    r[   authortitleNemojisdklikesprivatetagsruntimeai_short_descriptionai_categorysemantic_relevancy_scoretrending_scorerW   rM   c                    |                     d          }|d         | _        |                     dd          | _        |                     dd          | _        |                     d          | _        |                     d          | _        |                     dd	          | _        |                     d
d          | _        |                     d          | _        |rt          |          nd | _
        |                     d          | _        |                     d          | _        |                     d          | _        |                     d          | _        d S )Nr   r[   r   rZ   r   r   r   r   r   r   Fr   r   r   semanticRelevancyScoretrendingScore)rQ   r[   r   r   r   r   r   r   r   rn   r   r   r   r   r   )rR   rW   r   s      r   rT   zSpaceSearchResult.__init__K  s   ((9%%t*hhx,,XXgr**
XXg&&
88E??XXgq))
xx	511HHV$$	07A|G,,,T$(HH-C$D$D!88M22(,1I(J(J%"hh77r   )r   r   r   r   r_   r^   r   r`   rk   rn   floatra   rT   r   r   r   r   r     s          B 	GGGKKKJJJ:	tOOOJJJMMM
s)d
D    *$$$t#dl***$J8T 8d 8 8 8 8 8 8r   r   N)dataclassesr   r   enumr   typingr   huggingface_hub.utilsr   r   r	   r_   r   r    r:   rB   rc   rn   r   r   r   r   r   r   <module>r      sF   " ! ! ! ! !                   @ @ @ @ @ @ @ @ @ @2 2 2 2 2d 2 2 26! ! ! ! !C ! ! !H    3   " 9 9 9 9 9 9 9 9x         . . . . . . . .b Y Y Y Y Y Y Y Y6 Y Y Y Y Y Y Y Y8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8r   