
    ߔ9i+                        d dl 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
mZ d dlmZ ddlmZmZmZmZmZmZ dd	lmZ d
dlmZ  G d de      Z G d d      Z G d de      Z G d de      Z G d de      Z G d de      Zy)    N)_SubParsersAction)	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loginlogoutnotebook_login)HfFolder   )ANSIc                   "    e Zd Zedefd       Zy)UserCommandsparserc                    | j                  dd      }|j                  dt        d       |j                  ddd	
       |j                  d        | j                  dd      }|j                  d        | j                  dd      }|j                  d        | j                  dd      }|j	                  d      }|j                  dd      }|j                  dt        d       |j                  dt        d       |j                  dt        d       |j                  dt        dt
                |j                  d!d"dd#
       |j                  d$        y )%Nr   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                     t        |       S N)LoginCommandargss    g/var/www/html/backtest/airagagent/rag_env/lib/python3.12/site-packages/huggingface_hub/commands/user.py<lambda>z2UserCommands.register_subcommand.<locals>.<lambda>6   s    L4F     )funcwhoamiz;Find out which huggingface.co account you are logged in as.c                     t        |       S r   )WhoamiCommandr    s    r"   r#   z2UserCommands.register_subcommand.<locals>.<lambda>8       ]45H r$   r   zLog outc                     t        |       S r   )LogoutCommandr    s    r"   r#   z2UserCommands.register_subcommand.<locals>.<lambda>:   r)   r$   repozG{create, ls-files} 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                     t        |       S r   )RepoCreateCommandr    s    r"   r#   z2UserCommands.register_subcommand.<locals>.<lambda>Z   s    :KD:Q r$   )
add_parseradd_argumentstrset_defaultsadd_subparsersr	   )r   login_parserwhoami_parserlogout_parserrepo_parserrepo_subparsersrepo_create_parsers          r"   register_subcommandz UserCommands.register_subcommand)   s   ((7q(r!!N 	" 	

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

 	!!'F!G))(9v)w""(H"I))()C""(H"I ''Z ( 
 &44:a4b,77Gl7m''c 	( 	

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

 	''(8sIl'm''b$	 	( 	
 	''5	 	( 	
 	''-Q'Rr$   N)__name__
__module____qualname__staticmethodr   r=    r$   r"   r   r   (   s    0S$5 0S 0Sr$   r   c                       e Zd Zd Zy)BaseUserCommandc                 0    || _         t               | _        y r   )r!   r
   _api)selfr!   s     r"   __init__zBaseUserCommand.__init__^   s    	G	r$   N)r>   r?   r@   rH   rB   r$   r"   rD   rD   ]   s    r$   rD   c                       e Zd Zd Zy)r   c                 n    t        | j                  j                  | j                  j                         y )N)tokenadd_to_git_credential)r   r!   rK   rL   rG   s    r"   runzLoginCommand.rund   s    DIIOO499;Z;Z[r$   Nr>   r?   r@   rN   rB   r$   r"   r   r   c   s    \r$   r   c                       e Zd Zd Zy)r+   c                     t                y r   )r   rM   s    r"   rN   zLogoutCommand.runi   s    r$   NrO   rB   r$   r"   r+   r+   h   s    r$   r+   c                       e Zd Zd Zy)r(   c                 6   t        j                         }|t        d       t                	 | j                  j                  |      }t        |d          |d   D cg c]  }|d   	 }}|r.t        t        j                  d      dj                  |             t        dk7  rt        dt                y y c c}w # t        $ rR}t        |       t        t        j                  |j                  j                               t        d       Y d }~y d }~ww xY w)	NNot logged inr.   orgszorgs: ,zhttps://huggingface.coz(Authenticated through private endpoint: r   )r   	get_tokenprintexitrF   r&   r   boldjoinr   r   redresponsetext)rG   rK   infoorgrU   es         r"   rN   zWhoamiCommand.runn   s    ""$=/"F	99##E*D$v,+/<8CCK8D8dii)388D>:33@
KL 4	 9  	!H$((1::??+,GG	s+   0B= B8)AB= 8B= =	DADDNrO   rB   r$   r"   r(   r(   m   s    r$   r(   c                       e Zd Zd Zy)r1   c                    t        j                         }|t        d       t        d       	 t	        j
                  ddg      j                  d      }t        t        j                  |j                                      	 t	        j
                  ddg      j                  d      }t        t        j                  |j                                      t        d	       | j                  j                  |      d
   }| j                  j                  | j                  j                  n|}| d| j                  j                    }| j                  j"                  t$        vrt        d       t        d       | j                  j"                  t&        v r!t&        | j                  j"                     |z   }n|}t        dt        j(                  |              | j                  j*                  s=t-        d      j/                         }|d	k(  s|dk(  s|dk(  st        d       t                	 | j                  j1                  ||| j                  j"                  | j                  j2                        }t        d       t        dt        j(                                t        d       t        d|        t        d	       y # t        $ r t        d       Y Zw xY w# t        $ r" t        t        j                  d             Y 5w xY w# t4        $ rR}	t        |	       t        t        j                  |	j6                  j8                               t        d       Y d }	~	d }	~	ww xY w)NrT   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_idrK   	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   rY   
subprocesscheck_outputdecoder   graystripFileNotFoundErrorr\   rF   r&   r!   organizationr.   r   r   r   rZ   rh   inputlowercreate_reporl   r   r]   r^   )
rG   rK   stdoutuser	namespacerj   prefixed_repo_idchoiceurlra   s
             r"   rN   z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 +AL KK'L	L		M'AM""M'NrO   rB   r$   r"   r1   r1      s    <r$   r1   )rm   argparser   requests.exceptionsr   huggingface_hub.commandsr   huggingface_hub.constantsr   r   r   r	   huggingface_hub.hf_apir
   _loginr   r   r   r   r   r   utilsr   
_cli_utilsr   r   rD   r   r+   r(   r1   rB   r$   r"   <module>r      s     & ) >  )   2S, 2Sj \? \
O 
O *= =r$   