o
    0jC?                  &   @   s2  d Z ddlZddlmZ ddlZddlmZmZ ddlm	Z	m
Z
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mZmZmZmZmZmZmZ ddlmZ ed	d
Z e j!dddej"ddfddZ#edd
Z$edd
Z%e j&e$dd e j&e%dd G dd de'ej(Z)ee*dB ej+ddd
f Z,ee*dB ej+ddd
f Z-eedB ej+ddd
f Z.eedB ej+ddd
f Z/ee0dB ej+d d!d
f Z1e j2d"g d#d$ej3dddddd%dddddddddfd&ed'ed(ee'dB ej+d)d
f d*ed+e,d,e-d-ed.ee*ej+d/d
f d0ee'dB ej+d1d
f d2e.d3e/d4e1d5ed6ed7ed8ed9eddf$d:d;Z4e j2d<g d=d$dej3ddddd%ddddddddfd>ed?ee'dB ej5d@d
f d'ed*ed+e,d,e-d-ed.ee*ej+d/d
f d2e.d3e/d4e1d5ed6ed7ed8ed9eddf"dAdBZ6e j2dCdDgd$ej3dd%d%fd&ed'ed-edEee*ej+dFd
f dGee*ej+dHdIdJd
f ddfdKdLZ7e j2dMdNgd$dej3fd>ed?ed-ed'eddf
dOdPZ8e j2dQg dRd$dddddej3fd&edSee)dB ej+dTd
f d*ed+e,d,e-d-ed'eddfdUdVZ9e j2dWg dXd$ej3dddd%dfd&edYee:e' ej5dZd
f d'ed[ed\ee'dB ej+d]d
f d^ee'dB ej+d_d
f d`ee*ej+dad
f d-eddfdbdcZ;e%j2d"dddegd$ddej3d%fd&edee'ej5dfd
f d[ed-ed'ed.ee*ej+dgd
f ddfdhdiZ<e%j2dCdjgd$dej3fd&edee'ej5dkd
f d-ed'eddf
dldmZ=e$j2d"dndogd$dddej3fd&edee'ej5dpd
f dqee'dB ej+drdsdtd
f d[ed-ed'eddfdudvZ>e$j2dwdxgd$dej3fd&ed-ed'eddfdydzZ?e$j2dCd{gd$d%dej3fd&edee'ej5d|d
f dGee*ej+dHdId}d
f d-ed'eddfd~dZ@dS )ae  Contains commands to interact with repositories on the Hugging Face Hub.

Usage:
    # create a new dataset repo on the Hub
    hf repos create my-cool-dataset --repo-type=dataset

    # create a private model repo on the Hub
    hf repos create my-cool-model --private

    # delete files from a repo on the Hub
    hf repos delete-files my-model file.txt
    N)	Annotated)SpaceHardwareSpaceStorage)CLIErrorHfHubHTTPErrorRepositoryNotFoundErrorRevisionNotFoundError   )
EnvFileOptEnvOpt
PrivateOpt	RepoIdArgRepoTypeRepoTypeOptRevisionOptSecretsFileOpt
SecretsOptTokenOpt
VolumesOptenv_map_to_key_value_list
get_hf_apiparse_env_mapparse_volumestyper_factory)outzManage repos on the Hub.)helpT)Zinvoke_without_commandctxreturnc                 C   s   | j dkrtd d S d S )Nrepoz/`hf repo` is deprecated in favor of `hf repos`.)Z	info_namer   warning)r    r    Z/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/huggingface_hub/cli/repos.py_repos_callback;   s   
r"   z"Manage tags for a repo on the Hub.z&Manage branches for a repo on the Hub.tag)namebranchc                   @   s   e Zd ZdZdZdZdS )GatedChoicesautomanualfalseN)__name__
__module____qualname__r'   r(   r)   r    r    r    r!   r&   G   s    r&   z--publiczDWhether to make the repo public. Ignored if the repo already exists.z--protectedzVWhether to make the Space protected (Spaces only). Ignored if the repo already exists.z--flavorzOSpace hardware flavor (e.g. 'cpu-basic', 't4-medium', 'l4x4'). Only for Spaces.z	--storagezq(Deprecated, use volumes instead) Space persistent storage tier ('small', 'medium', or 'large'). Only for Spaces.z--sleep-timez[Seconds of inactivity before the Space is put to sleep. Use -1 to disable. Only for Spaces.create)zhf repos create my-modelz8hf repos create my-dataset --repo-type dataset --privatezxhf repos create my-space --type space --space-sdk gradio --flavor t4-medium --secrets HF_TOKEN -e THEME=dark --protectedzihf repos create my-space --type space --space-sdk gradio -v hf://gpt2:/models -v hf://buckets/org/b:/data)ZexamplesFrepo_id	repo_type	space_sdkzEHugging Face Spaces SDK type. Required when --type is set to 'space'.privatepublic	protectedtokenexist_okz-Do not raise an error if repo already exists.resource_group_idzoResource group in which to create the repo. Resource groups is only available for Enterprise Hub organizations.hardwarestorage
sleep_timesecretssecrets_fileenvenv_filevolumec                 C   sz   t |d}|j| |j|rdn	|rdn|rdnd|||||	|
|tt||tt||t|d}tjd|jt	|d dS )	zCreate a new repo on the Hub.r4   r1   r2   r3   N)r.   r/   
visibilityr4   r5   r6   r0   space_hardwarespace_storagespace_sleep_timespace_secretsspace_variablesspace_volumeszRepo created)r.   url)
r   Zcreate_repovaluer   r   r   r   resultr.   str)r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   apirepo_urlr    r    r!   repo_createu   s"   
,rM   Z	duplicate)z/hf repos duplicate openai/gdpval --type datasetzzhf repos duplicate multimodalart/dreambooth-training my-dreambooth --type space --flavor l4x4 --secrets HF_TOKEN --privatezfhf repos duplicate org/my-space my-space --type space -v hf://gpt2:/models -v hf://buckets/org/b:/datafrom_idto_idz_Destination repo ID (e.g. `myorg/my-copy`). Defaults to your namespace with the same repo name.c                 C   sz   t |d}|j| ||j|rdn	|rdn|rdnd||||	|
tt||tt||t|d}tjd| |jt	|d dS )	z7Duplicate a repo on the Hub (model, dataset, or Space).r?   r1   r2   r3   N)rN   rO   r/   r@   r4   r5   rA   rB   rC   rD   rE   rF   zRepo duplicated)rN   rO   rG   )
r   Zduplicate_reporH   r   r   r   r   rI   r.   rJ   )rN   rO   r/   r1   r2   r3   r4   r5   r7   r8   r9   r:   r;   r<   r=   r>   rK   rL   r    r    r!   repo_duplicate   s    
%rP   deletezhf repos delete my-model
missing_okz=If set to True, do not raise an error if repo does not exist.yesz-yz--yesz#Answer Yes to prompt automatically.c                 C   sL   t jd|j d|  d|d t|d}|j| |j|d t jd| d d	S )
z>Delete a repo from the Hub. This is an irreversible operation.z$You are about to permanently delete  'z'. Proceed?rS   r?   )r.   r/   rR   zRepo deletedr.   N)r   confirmrH   r   Zdelete_reporI   )r.   r/   r4   rR   rS   rK   r    r    r!   repo_delete   s   
rX   movez;hf repos move old-namespace/my-model new-namespace/my-modelc                 C   s0   t |d}|j| ||jd tjd| |d dS )z8Move a repository from a namespace to another namespace.r?   )rN   rO   r/   z
Repo moved)rN   rO   N)r   Z	move_reporH   r   rI   )rN   rO   r4   r/   rK   r    r    r!   	repo_move
  s   
rZ   settings)z$hf repos settings my-model --privatez'hf repos settings my-model --gated autoz8hf repos settings my-space --repo-type space --protectedgatedz$The gated status for the repository.c                 C   sd   t |d}|j| |du rdn	|tju rdn|j|rdn	|rdn|r#dnd|jd tjd| d	 dS )
z$Update the settings of a repository.r?   NFr1   r2   r3   )r.   r\   r@   r/   zRepo settings updatedrV   )r   Zupdate_repo_settingsr&   r)   rH   r   rI   )r.   r\   r1   r2   r3   r4   r/   rK   r    r    r!   repo_settings  s   
r]   zdelete-files)z'hf repos delete-files my-model file.txtz'hf repos delete-files my-model "*.json"z&hf repos delete-files my-model folder/patternszXGlob patterns to match files to delete. Based on fnmatch, '*' matches files recursively.revisioncommit_messagez9The summary / title / first line of the generated commit.commit_descriptionz(The description of the generated commit.	create_prz7Whether to create a new Pull Request for these changes.c           
   	   C   s8   t |d}|j|| |j||||d}	tjd| |	d dS )z$Delete files from a repo on the Hub.r?   )Zdelete_patternsr.   r/   r_   r`   ra   rb   zFiles deleted)r.   Z
commit_urlN)r   Zdelete_filesrH   r   rI   )
r.   r^   r/   r_   r`   ra   rb   r4   rK   rG   r    r    r!   repo_delete_files<  s   
'	rc   z#hf repos branch create my-model devz5hf repos branch create my-model dev --revision abc123z!The name of the branch to create.z?If set to True, do not raise an error if branch already exists.c                 C   s8   t |d}|j| |||j|d tjd||j| d dS )z*Create a new branch for a repo on the Hub.r?   )r.   r%   r_   r/   r5   zBranch createdr%   r/   r.   N)r   Zcreate_branchrH   r   rI   )r.   r%   r_   r4   r/   r5   rK   r    r    r!   branch_createp  s   
re   z#hf repos branch delete my-model devz!The name of the branch to delete.c                 C   s4   t |d}|j| ||jd tjd||j| d dS )z'Delete a branch from a repo on the Hub.r?   )r.   r%   r/   zBranch deletedrd   N)r   Zdelete_branchrH   r   rI   )r.   r%   r4   r/   rK   r    r    r!   branch_delete  s   
rf   z!hf repos tag create my-model v1.0z4hf repos tag create my-model v1.0 -m "First release"zThe name of the tag to create.messagez-mz	--messagez%The description of the tag to create.c           	   
   C   s   |j }t|d}z|j| ||||d W nK ty- } zt|  d|  d|d}~w tyA } z	td| d|d}~w ty_ } z|jj	dkrZtd| d	|  d
| d}~ww t
jd||| d dS )zCreate a tag for a repo.r?   )r.   r#   Ztag_messager_   r/   rT   ' not found.Nz
Revision 'i  Tag 'z' already exists on ''.zTag createdr#   r/   r.   )rH   r   Z
create_tagr   r   
capitalizer   r   responsestatus_coder   rI   )	r.   r#   rg   r_   r4   r/   repo_type_strrK   er    r    r!   
tag_create  s"   
rq   z	list | lszhf repos tag list my-modelc              
   C   st   |j }t|d}z	|j| |d}W n ty* } zt|  d|  d|d}~ww dd |jD }t| dS )zList tags for a repo.r?   )r.   r/   rT   rh   Nc                 S   s   g | ]}|j |j|jd qS )r$   Ztarget_commitrefrr   ).0tr    r    r!   
<listcomp>  s    ztag_list.<locals>.<listcomp>)	rH   r   Zlist_repo_refsr   r   rl   tagsr   table)r.   r4   r/   ro   rK   refsrp   itemsr    r    r!   tag_list  s   
r{   z!hf repos tag delete my-model v1.0zThe name of the tag to delete.z"Answer Yes to prompt automaticallyc              
   C   s   |j }td| d| d|   tjd|d t|d}z
|j| ||d W n0 ty@ } zt|  d|  d	|d
}~w t	yW } ztd| d|  d|d
}~ww tj
d||| d d
S )zDelete a tag for a repo.zYou are about to delete tag z on  zProceed?rU   r?   )r.   r#   r/   rT   rh   Nri   z' not found on 'rj   zTag deletedrk   )rH   r   textrW   r   Z
delete_tagr   r   rl   r   rI   )r.   r#   rS   r4   r/   ro   rK   rp   r    r    r!   
tag_delete  s   
r~   )A__doc__enumtypingr   ZtyperZhuggingface_hubr   r   Zhuggingface_hub.errorsr   r   r   r   Z
_cli_utilsr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _outputr   Z	repos_clicallbackContextr"   Ztag_cliZ
branch_cliZ	add_typerrJ   Enumr&   boolOptionZ	PublicOptZProtectedOptZSpaceHardwareOptZSpaceStorageOptintZSpaceSleepTimeOptcommandmodelrM   ZArgumentrP   rX   rZ   r]   listrc   re   rf   rq   r{   r~   r    r    r    r!   <module>   s  H



		
 !6	
/
	
	
,	
		
$