
    rhP)                     ,   d Z ddlZ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
 ddlmZmZ dd	lmZmZmZ dd
lmZ ddlmZ  ej,                  e      Z G d de      Z G d d      Z G d d      Z G d de      Z G d de      Z G d de      Zy)a  Contains commands to interact with repositories on the Hugging Face Hub.

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

    # create a private model repo on the Hub
    hf repo create my-cool-model --private
    N)_SubParsersAction)Optional)	HTTPError)BaseHuggingfaceCLICommand)ANSI)
REPO_TYPESSPACES_SDK_TYPES)HfHubHTTPErrorRepositoryNotFoundErrorRevisionNotFoundError)HfApi)loggingc                   "    e Zd Zedefd       Zy)RepoCommandsparserc                    | j                  dd      j                  d      }j                  fd       |j                  dd      }|j                  d	t        d
       |j                  dt        d       |j                  dt        dt
               |j                  ddd       |j                  dt        d       |j                  ddd       |j                  dt        d       |j                  d        |j                  dd      }|j                  ddd !      }|j                  dd"      }|j                  d	t        d#       |j                  dt        d$       |j                  d%d&t        d'       |j                  d(t        d)       |j                  dt        d*       |j                  dg d+d,d-.       |j                  d/        |j                  d0d1      }|j                  d	t        d2       |j                  dt        d*       |j                  dg d+d,d-.       |j                  d3        |j                  d4d5      }|j                  d	t        d6       |j                  dt        d7       |j                  d8d9dd:       |j                  dt        d*       |j                  dg d+d,d-.       |j                  d;        y )<NrepozManage repos on the Hub.)helpz%huggingface.co repos related commandsc                 $    j                         S N)
print_help)argsrepo_parsers    k/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/huggingface_hub/cli/repo.py<lambda>z2RepoCommands.register_subcommand.<locals>.<lambda>0   s    ;3I3I3K     )funccreatez#Create a new repo on huggingface.corepo_idzThe ID of the repo to create to (e.g. `username/repo-name`). The username is optional and will be set to your username if not provided.)typer   z--repo-typezWOptional: set to "dataset" or "space" if creating a dataset or space, default is model.z--space_sdkzOOptional: Hugging Face Spaces SDK type. Required when --type is set to "space".)r    r   choicesz	--private
store_truezhWhether to create a private repository. Defaults to public unless the organization's default is private.)actionr   z--tokenzLHugging Face token. Will default to the locally saved token if not provided.z
--exist-okz-Do not raise an error if repo already exists.z--resource-group-idzoResource group in which to create the repo. Resource groups is only available for Enterprise Hub organizations.c                     t        |       S r   )RepoCreateCommandr   s    r   r   z2RepoCommands.register_subcommand.<locals>.<lambda>X   s    :KD:Q r   tagz"Manage tags for a repo on the Hub.zTag actions
tag_actionT)r   destrequiredzCreate a tag for a repo.z6The ID of the repo to tag (e.g. `username/repo-name`).zThe name of the tag to create.z-mz	--messagez%The description of the tag to create.z
--revisionzThe git revision to tag.zJA User Access Token generated from https://huggingface.co/settings/tokens.)modeldatasetspacer+   z6Set the type of repository (model, dataset, or space).)r!   defaultr   c                     t        |       S r   )RepoTagCreateCommandr&   s    r   r   z2RepoCommands.register_subcommand.<locals>.<lambda>o       9Md9S r   listzList tags for a repo.z@The ID of the repo to list tags for (e.g. `username/repo-name`).c                     t        |       S r   )RepoTagListCommandr&   s    r   r   z2RepoCommands.register_subcommand.<locals>.<lambda>   s    7I$7O r   deletezDelete a tag from a repo.zFThe ID of the repo to delete the tag from (e.g. `username/repo-name`).zThe name of the tag to delete.z-yz--yesz$Answer Yes to prompts automatically.c                     t        |       S r   )RepoTagDeleteCommandr&   s    r   r   z2RepoCommands.register_subcommand.<locals>.<lambda>   r1   r   )
add_parseradd_subparsersset_defaultsadd_argumentstrr	   )	r   repo_subparsersrepo_create_parserrepo_tag_parsertag_subparserstag_create_parsertag_list_parsertag_delete_parserr   s	           @r   register_subcommandz RepoCommands.register_subcommand*   s{   ''5O'P%44:a4b 	  &K L -77Gl7m'' [ 	( 	

 	''j 	( 	

 	''b$	 	( 	
 	''{ 	( 	

 	''_ 	( 	

 	''@ 	( 	

 	''! C 	( 	

 	''-Q'R *44UAe4f(77]Q]hl7m +55hE_5`&&C&^ 	' 	
 	&&u3=]&^&&t[sIp&q&&|#D^&_&&C&r 	' 	
 	&&1I	 	' 	
 	&&,S&T )33FAX3Y$$C&h 	% 	
 	$$C&r 	% 	
 	$$1I	 	% 	
 	$$*O$P +55hE`5a&&C&n 	' 	
 	&&u3=]&^&&tW\Pv&w&&C&r 	' 	
 	&&1I	 	' 	
 	&&,S&Tr   N)__name__
__module____qualname__staticmethodr   rD    r   r   r   r   )   s"    fU$5 fU fUr   r   c                   2    e Zd Zdej                  fdZd Zy)r%   r   c                    |j                   | _         |j                  | _        |j                  | _        |j                  | _        |j                  | _        |j
                  | _        |j                  | _        t               | _        y r   )	r   	repo_type	space_sdkprivatetokenexist_okresource_group_idr   _apiselfr   s     r   __init__zRepoCreateCommand.__init__   s[     LL(,(,!\\$(JJ
"mm040F0FG	r   c           	      n   | j                   j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                        }t        dt        j                  |j                         d       t        dt        j                  |              y )N)r   rL   rN   rO   rP   rQ   rM   zSuccessfully created z on the Hub.zYour repo is now available at )rR   create_repor   rL   rN   rO   rP   rQ   rM   printr   bold)rT   repo_urls     r   runzRepoCreateCommand.run   s    99((LLnnLL**]]"44nn ) 
 	%dii0@0@&A%B,OP.tyy/B.CDEr   N)rE   rF   rG   argparse	NamespacerU   r[   rI   r   r   r%   r%      s    X// Fr   r%   c                       e Zd Zd Zy)RepoTagCommandc                     || _         t        t        |dd             | _        |j                  | _        t        |dd      | _        | j
                  t        vrt        d       t        d       y y )NrO   )rO   rL   r+   zInvalid repo --repo-type   )	r   r   getattrapir   rL   r   rX   exitrS   s     r   rU   zRepoTagCommand.__init__   sZ    	wtWd;<|| {G<>>+,-G ,r   N)rE   rF   rG   rU   rI   r   r   r_   r_      s    r   r_   c                       e Zd Zd Zy)r0   c                    t        dt        j                  | j                  j                         d| j
                   dt        j                  | j                                	 | j                  j                  | j                  | j                  j                  t        | j                  dd       t        | j                  dd       | j
                         t        dt        j                  | j                  j                         dt        j                  | j                                y # t        $ rT t        | j
                  j                          dt        j                  | j                         d       t        d       Y t        $ rE t        d	t        j                  t        | j                  dd              d       t        d       Y t        $ r}|j                  j                   d
k(  r`t        dt        j                  | j                  j                         dt        j                  | j                                t        d       |d }~ww xY w)NzYou are about to create tag  on  messagerevision)r   r'   tag_messagerj   rL    not found.ra   z	Revision i  Tag z already exists on z created on )rX   r   rY   r   r'   rL   r   rc   
create_tagrb   r   
capitalizerd   r   r
   responsestatus_code)rT   es     r   r[   zRepoTagCreateCommand.run   s   ,TYYtyy}}-E,Fd4>>JZZ[\`\e\efjfrfr\s[tuv	HHIIMM#DIIy$? J=..   $ 	TYYtyy}}-.l499T\\;R:STU ' 	T^^..01499T\\3J2K;WXG$ 	Idii		:t(LMNkZ[G 	zz%%,TYYtyy}}566I$))TXT`T`JaIbcdQG		s(   $A2D, ,AIA
IIA;IINrE   rF   rG   r[   rI   r   r   r0   r0      s    Vr   r0   c                       e Zd Zd Zy)r4   c                    	 | j                   j                  | j                  | j                        }t        j                        dk(  rt        d       t        d       t        d| j                   dt        j                  | j                         d       |j                  D ]  }t        |j                           y # t        $ rT t        | j                  j                          dt        j                  | j                         d       t        d       Y t        $ rS}t        |       t        t        j                  |j                  j                               t        d       Y d }~@d }~ww xY w)	N)r   rL   rh   rl   ra   r   zNo tags foundz	Tags for :)rc   list_repo_refsr   rL   r   rX   ro   r   rY   rd   r   redrp   textlentagsname)rT   refsrr   r'   s       r   r[   zRepoTagListCommand.run   s   	88**.. + D tyy>Q/"G	$..)499T\\+B*C1EF99 	C#((O	 ' 	T^^..01499T\\3J2K;WXG 	!H$((1::??+,GG	s   1C AE8E8%AE33E8Nrs   rI   r   r   r4   r4      s    r   r4   c                       e Zd Zd Zy)r7   c           
      (   t        dt        j                  | j                  j                         d| j
                   dt        j                  | j                                t        | j                  dd      s2t        d      j                         }|dvrt        d       t                	 | j                  j                  | j                  | j                  j                  | j
                  	       t        dt        j                  | j                  j                         dt        j                  | j                                y # t        $ rT t        | j
                  j                          dt        j                  | j                         d
       t        d       Y t        $ rd t        dt        j                  | j                  j                         dt        j                  | j                                t        d       Y w xY w)NzYou are about to delete tag rg   rh   yesFzProceed? [Y/n] ) yr   Abort)r   r'   rL   rl   ra   rm   z not found on z deleted on )rX   r   rY   r   r'   rL   r   rb   inputlowerrd   rc   
delete_tagr   ro   r   )rT   choices     r   r[   zRepoTagDeleteCommand.run   sx   ,TYYtyy}}-E,Fd4>>JZZ[\`\e\efjfrfr\s[tuvtyy%/,-335F--g	HH$))--SWSaSab 	TYYtyy}}-.l499T\\;R:STU ' 	T^^..01499T\\3J2K;WXG$ 	D499==12.4<<AX@YZ[G	s   -AE	 	AH%A(HHNrs   rI   r   r   r7   r7      s    Vr   r7   )__doc__r\   r   typingr   requests.exceptionsr   huggingface_hub.commandsr   #huggingface_hub.commands._cli_utilsr   huggingface_hub.constantsr   r	   huggingface_hub.errorsr
   r   r   huggingface_hub.hf_apir   huggingface_hub.utilsr   
get_loggerrE   loggerr   r%   r_   r0   r4   r7   rI   r   r   <module>r      s     &  ) > 4 B a a ( ) 
		H	%hU, hUVF F2 V> V2 ,V> Vr   