
    ITh+                        S r SSKrSSKJr  SSKJrJr  SSKJr  SSK	J
r
  SSKJrJrJrJr  SSKJr  S	S
KJrJrJrJrJrJrJrJr  S	SKJrJrJr  SSKJ r   \RB                  " \"5      r# SSK$J%r%  SSK&J'r'  Sr( " S S\
5      r* " S S5      r+ " S S\+5      r, " S S\+5      r- " S S\+5      r. " S S\+5      r/ " S S\+5      r0 " S  S!\+5      r1g! \) a    Sr( Nbf = f)"a  Contains commands to authenticate to the Hugging Face Hub and interact with your repositories.

Usage:
    # login and save token locally.
    huggingface-cli login --token=hf_*** --add-to-git-credential

    # switch between tokens
    huggingface-cli auth switch

    # list all tokens
    huggingface-cli auth list

    # logout from a specific token, if no token-name is provided, all tokens will be deleted from your machine.
    huggingface-cli logout --token-name=your_token_name

    # find out which huggingface.co account you are logged in as
    huggingface-cli whoami

    # create a new dataset repo on the Hub
    huggingface-cli repo create mydataset --type=dataset

    N)_SubParsersAction)ListOptional)	HTTPError)BaseHuggingfaceCLICommand)ENDPOINT
REPO_TYPESREPO_TYPES_URL_PREFIXESSPACES_SDK_TYPES)HfApi   )NOTEBOOK_LOGIN_PASSWORD_HTMLNOTEBOOK_LOGIN_TOKEN_HTML_ENDNOTEBOOK_LOGIN_TOKEN_HTML_START	auth_listauth_switchloginlogoutnotebook_login)get_stored_tokens	get_tokenlogging   )ANSI)inquirer)ChoiceTFc                   ,    \ rS rSr\S\4S j5       rSrg)UserCommandsH   parserc                    U R                  SSS9nUR                  S[        SS9  UR                  SSS	S
9  UR                  S S9  U R                  SSS9nUR                  S S9  U R                  SSS9nUR                  S[        SS9  UR                  S S9  U R                  SSS9nUR	                  SS9nUR                  SSS9nUR                  S[        SS9  UR                  SSS	S
9  UR                  S S9  UR                  SSS9nUR                  S S9  U R                  SS S9nUR	                  S!S9n	U	R                  S"S#S9n
U
R                  S$[        S%S9  U
R                  S&[        S'S9  U
R                  S([        S)S9  U
R                  S*[        S+[
        S,9  U
R                  S-S.SS/S
9  U
R                  S0 S9  g )1Nr   z8Log in using a token from huggingface.co/settings/tokens)helpz--tokenz;Token generated from https://huggingface.co/settings/tokens)typer"   z--add-to-git-credential
store_truez.Optional: Save token to git credential helper.)actionr"   c                     [        U 5      $ N)LoginCommandargss    U/var/www/auris/envauris/lib/python3.13/site-packages/huggingface_hub/commands/user.py<lambda>2UserCommands.register_subcommand.<locals>.<lambda>V   s	    L4F    )funcwhoamiz;Find out which huggingface.co account you are logged in as.c                     [        U 5      $ r'   )WhoamiCommandr)   s    r+   r,   r-   X   	    ]45Hr.   r   zLog outz--token-namez3Optional: Name of the access token to log out from.c                     [        U 5      $ r'   )LogoutCommandr)   s    r+   r,   r-   `   r3   r.   authz%Other authentication related commandszAuthentication subcommandsswitchzSwitch between access tokensz0Optional: Name of the access token to switch to.c                     [        U 5      $ r'   )AuthSwitchCommandr)   s    r+   r,   r-   o   
    :KD:Qr.   listzList all stored access tokensc                     [        U 5      $ r'   )AuthListCommandr)   s    r+   r,   r-   q   s	    8Mr.   repoz={create} Commands to interact with your huggingface.co repos.z%huggingface.co repos related commandscreatez#Create a new repo on huggingface.conamezPName for your repo. Will be namespaced under your username to build the repo id.z--typezbOptional: repo_type: set to "dataset" or "space" if creating a dataset or space, default is model.z--organizationz!Optional: organization namespace.z--space_sdkzOOptional: Hugging Face Spaces SDK type. Required when --type is set to "space".)r#   r"   choicesz-yz--yesz"Optional: answer Yes to the promptc                     [        U 5      $ r'   )RepoCreateCommandr)   s    r+   r,   r-      r:   r.   )
add_parseradd_argumentstrset_defaultsadd_subparsersr   )r    login_parserwhoami_parserlogout_parserauth_parserauth_subparsersauth_switch_parserauth_list_parserrepo_parserrepo_subparsersrepo_create_parsers              r+   register_subcommand UserCommands.register_subcommandI   ss   ((7q(r!!N 	" 	

 	!!%A 	" 	

 	!!'F!G))(9v)w""(H"I))()C""F 	# 	

 	""(H"I''5\']%44:V4W,77Ge7f''C 	( 	

 	''%A 	( 	

 	''-Q'R*55fCb5c%%+M%N''5t'u%44:a4b,77Gl7m''c 	( 	

 	''u 	( 	

 	''(8sIl'm''b$	 	( 	
 	''5	 	( 	
 	''-Q'Rr.    N)__name__
__module____qualname____firstlineno__staticmethodr   rS   __static_attributes__rU   r.   r+   r   r   H   s"    CS$5 CS CSr.   r   c                       \ rS rSrS rSrg)BaseUserCommand   c                 .    Xl         [        5       U l        g r'   )r*   r   _api)selfr*   s     r+   __init__BaseUserCommand.__init__   s    	G	r.   )r`   r*   N)rV   rW   rX   rY   rb   r[   rU   r.   r+   r]   r]      s    r.   r]   c                       \ rS rSrS rSrg)r(      c                     [         R                  " 5         [        U R                  R                  U R                  R
                  S9  g )N)tokenadd_to_git_credential)r   set_verbosity_infor   r*   rg   rh   ra   s    r+   runLoginCommand.run   s.    ""$))//"&))"A"A	
r.   rU   NrV   rW   rX   rY   rk   r[   rU   r.   r+   r(   r(      s    
r.   r(   c                       \ rS rSrS rSrg)r5      c                 h    [         R                  " 5         [        U R                  R                  S9  g )N)
token_name)r   ri   r   r*   rq   rj   s    r+   rk   LogoutCommand.run   s     ""$$))../r.   rU   Nrm   rU   r.   r+   r5   r5      s    0r.   r5   c                   L    \ rS rSrS rS\\   4S jrS\\   S\\   4S jr	Sr
g)	r9      c                     [         R                  " 5         U R                  R                  nUc  U R	                  5       nUc  [        S5        [        5         [        XR                  R                  S9  g )Nz!No token name provided. Aborting.)rh   )	r   ri   r*   rq   _select_token_nameprintexitr   rh   )ra   rq   s     r+   rk   AuthSwitchCommand.run   sW    ""$YY))
002J56FJii6U6UVr.   returnc                    [        [        5       R                  5       5      nU(       d  [        R	                  S5        g [
        (       a  U R                  U5      $ [        S5        [        US5       H  u  p#[        U SU 35        M       [        S5      nUR                  5       S:X  a  g [        U5      S-
  nSUs=::  a  [        U5      :  a  O  OX   $ [        S5         MZ  ! [         a    [        S	5         Nf = f)
Nz+No stored tokens found. Please login first.zAvailable stored tokens:r   z. z=Enter the number of the token to switch to (or 'q' to quit): qr   z$Invalid selection. Please try again.z4Invalid input. Please enter a number or 'q' to quit.)r;   r   keysloggererror_inquirer_py_available_select_token_name_tuirw   	enumerateinputlowerintlen
ValueError)ra   token_namesirq   choiceindexs         r+   rv   $AuthSwitchCommand._select_token_name   s    ,.3356LLFG!!..{;;()&{A6MAQCr*&' 7
N^_<<>S(Fa0K 00&--@A   NLMNs   C& -*C& C& &C>=C>r   c                     U Vs/ s H  n[        X"S9PM     nn [        R                  " SUS S9R                  5       $ s  snf ! [         a    [
        R                  S5         g f = f)N)r@   zSelect a token to switch to:)messagerA   defaultzToken selection cancelled.)r   r   selectexecuteKeyboardInterruptr~   info)ra   r   rq   rA   s       r+   r   (AuthSwitchCommand._select_token_name_tui   sj    ITU:6*6U	??6 gi	 V ! 	KK45	s   ?#A A&%A&rU   N)rV   rW   rX   rY   rk   r   rF   rv   r   r   r[   rU   r.   r+   r9   r9      s5    	WNHSM N4
$s) 
 
r.   r9   c                       \ rS rSrS rSrg)r=      c                 B    [         R                  " 5         [        5         g r'   )r   ri   r   rj   s    r+   rk   AuthListCommand.run   s    ""$r.   rU   Nrm   rU   r.   r+   r=   r=      s    r.   r=   c                       \ rS rSrS rSrg)r2      c                 :   [        5       nUc  [        S5        [        5          U R                  R	                  U5      n[        US   5        US    Vs/ s H  o3S   PM	     nnU(       a/  [        [
        R                  " S5      SR                  U5      5        [        S:w  a  [        S[         35        g g s  snf ! [         aS  n[        U5        [        [
        R                  " UR                  R                  5      5        [        S5         S nAg S nAff = f)	NNot logged inr@   orgszorgs: ,zhttps://huggingface.coz(Authenticated through private endpoint: r   )r   rw   rx   r`   r0   r   boldjoinr   r   redresponsetext)ra   rg   r   orgr   es         r+   rk   WhoamiCommand.run   s    =/"F	99##E*D$v,+/<8<CK<D8dii)388D>:33@
KL 4	 9  	!H$((1::??+,GG	s+   0B= B8"AB= 8B= =
DA	DDrU   Nrm   rU   r.   r+   r2   r2      s    r.   r2   c                       \ rS rSrS rSrg)rC      c                    [        5       nUc  [        S5        [        S5         [        R                  " SS/5      R                  S5      n[        [        R                  " UR                  5       5      5         [        R                  " SS/5      R                  S5      n[        [        R                  " UR                  5       5      5        [        S	5        U R                  R                  U5      S
   nU R                  R                  b  U R                  R                  OUnU SU R                  R                   3nU R                  R                   ["        ;  a  [        S5        [        S5        U R                  R                   [$        ;   a!  [$        U R                  R                      U-   nOUn[        S[        R&                  " U5       35        U R                  R(                  (       d@  [+        S5      R-                  5       nUS	:X  d!  US:X  d  US:X  d  [        S5        [        5          U R                  R/                  UUU R                  R                   U R                  R0                  S9n[        S5        [        S[        R&                  " W5       35        [        S5        [        SU 35        [        S	5        g ! [         a    [        S5         GNif = f! [         a#    [        [        R                  " S5      5         GNDf = f! [2         aS  n	[        U	5        [        [        R                  " U	R4                  R6                  5      5        [        S5         S n	A	NS n	A	ff = f)Nr   r   gitz	--versionzutf-8z9Looks like you do not have git installed, please install.zgit-lfszLooks like you do not have git-lfs installed, please install. You can install from https://git-lfs.github.com/. Then run `git lfs install` (you only have to do this once). r@   /zInvalid repo --typezYou are about to create zProceed? [Y/n] yyesAbort)repo_idrg   	repo_type	space_sdkz
Your repo now lives at:z  zK
You can clone it locally with the command below, and commit/push as usual.z
  git clone )r   rw   rx   
subprocesscheck_outputdecoder   graystripFileNotFoundErrorr   r`   r0   r*   organizationr@   r#   r	   r
   r   r   r   r   create_repor   r   r   r   )
ra   rg   stdoutuser	namespacer   prefixed_repo_idr   urlr   s
             r+   rk   RepoCreateCommand.run   s   =/"G	O,,e[-ABII'RF$))FLLN+,
	,,i-EFMMgVF$))FLLN+, 	b	yy&v..2ii.D.D.PDII**VZ	Kq 0199>>+'(G99>>446tyy~~FP&(3C)D(EFGyy}},-335FbLFcMVu_g
	))''))..))--	 ( C 	)*499S>"#$\]se$%b	i ! 	OMN	O ! 	S	L  	!H$((1::??+,GG	s?   AK
 :AK& 4AL 
K#"K#&)LL
M3 A	M..M3rU   Nrm   rU   r.   r+   rC   rC      s    <r.   rC   )2__doc__r   argparser   typingr   r   requests.exceptionsr   huggingface_hub.commandsr   huggingface_hub.constantsr   r	   r
   r   huggingface_hub.hf_apir   _loginr   r   r   r   r   r   r   r   utilsr   r   r   
_cli_utilsr   
get_loggerrV   r~   
InquirerPyr   InquirerPy.base.controlr   r   ImportErrorr   r]   r(   r5   r9   r=   r2   rC   rU   r.   r+   <module>r      s   .  & ! ) > e e (	 	 	 : 9  
		H	%##.!
ES, ESP 
? 
0O 00 0fo O *= =_  #"#s   *C CC