
    g                     ^   d dl 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  G d d	e          Z G d
 d          Zdeeeeef                           dee         defd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dS )    N)ArgumentParser)ListUnion)HfFoldercreate_repowhoami)	HTTPError   )BaseTransformersCLICommandc                   *    e Zd Zedefd            ZdS )UserCommandsparserc                 v   |                      dd          }|                    d            |                      dd          }|                    d            |                      d	d
          }|                    d            |                      dd          }|                    d          }|                     dd          }|                    dt          d           |                    dt          d           |                    dddd           |                    d            d S )Nloginz6Log in using the same credentials as on huggingface.co)helpc                      t          |           S N)LoginCommandargss    V/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/commands/user.py<lambda>z2UserCommands.register_subcommand.<locals>.<lambda>   s    L4F4F     )funcr   z;Find out which huggingface.co account you are logged in as.c                      t          |           S r   )WhoamiCommandr   s    r   r   z2UserCommands.register_subcommand.<locals>.<lambda>       ]45H5H r   logoutzLog outc                      t          |           S r   )LogoutCommandr   s    r   r   z2UserCommands.register_subcommand.<locals>.<lambda>!   r   r   repoz_Deprecated: use `huggingface-cli` instead. Commands to interact with your huggingface.co repos.zPDeprecated: use `huggingface-cli` instead. huggingface.co repos related commandscreatezNDeprecated: use `huggingface-cli` instead. Create a new repo on huggingface.conamezYName for your model's repo. Will be namespaced under your username to build the model id.)typer   z--organizationz!Optional: organization namespace.z-yz--yes
store_truez"Optional: answer Yes to the prompt)actionr   c                      t          |           S r   )RepoCreateCommandr   s    r   r   z2UserCommands.register_subcommand.<locals>.<lambda>5   s    :KD:Q:Q r   )
add_parserset_defaultsadd_subparsersadd_argumentstr)r   login_parserwhoami_parserlogout_parserrepo_parserrepo_subparsersrepo_create_parsers          r   register_subcommandz UserCommands.register_subcommand   s   ((7o(pp!!'F'F!GGG))(9v)ww""(H(H"III))()CC""(H(H"III ''r ( 
 
 &44c 5 
 
 -77k 8 
 
 	''l 	( 	
 	
 	

 	''(8sIl'mmm''glQu'vvv''-Q-Q'RRRRRr   N)__name__
__module____qualname__staticmethodr   r4    r   r   r   r      s@        SN S S S \S S Sr   r   c                   d    e Zd ZdZdZdZdZdZed             Z	ed             Z
ed             Zd	S )
ANSIz;
    Helper for en.wikipedia.org/wiki/ANSI_escape_code
    z[1mz[31mz[90mz[0mc                 &    | j          | | j         S r   )_bold_resetclsss     r   boldz	ANSI.boldB       ),Q,
,,,r   c                 4    | j          | j         | | j         S r   )r=   _redr>   r?   s     r   redzANSI.redF   s#    )6SX6q6#*666r   c                 &    | j          | | j         S r   )_grayr>   r?   s     r   grayz	ANSI.grayJ   rC   r   N)r5   r6   r7   __doc__r=   rE   rH   r>   classmethodrB   rF   rI   r9   r   r   r;   r;   8   s          EDEF- - [- 7 7 [7 - - [- - -r   r;   rowsheadersreturnc                 `   d t          g | |R  D             } dt          |          z  j        | }g }|                     |j        |            |                     |j        d |D                         | D ]}|                     |j        |             d                    |          S )z
    Inspired by:

    - stackoverflow.com/a/8356620/593036
    - stackoverflow.com/questions/9535954/printing-lists-as-tabular-data
    c                 @    g | ]}t          d  |D                       S )c              3   N   K   | ] }t          t          |                    V  !d S r   )lenr-   ).0xs     r   	<genexpr>z&tabulate.<locals>.<listcomp>.<genexpr>V   s.      //ac#a&&kk//////r   )max)rS   cols     r   
<listcomp>ztabulate.<locals>.<listcomp>V   s/    OOOC#//3/////OOOr   z{{:{}}} c                     g | ]}d |z  S )-r9   )rS   ws     r   rX   ztabulate.<locals>.<listcomp>Z   s    $A$A$AS1W$A$A$Ar   
)ziprR   formatappendjoin)rL   rM   
col_widths
row_formatlinesrows         r   tabulatere   O   s     PO3;N;Ng;N;N;NOOOJ3*s7||+3Z@JE	LL""G,---	LL""$A$Aj$A$A$ABCCC . .&Z&,----99Ur   c                       e Zd Zd ZdS )BaseUserCommandc                     || _         d S r   r   )selfr   s     r   __init__zBaseUserCommand.__init__a   s    			r   N)r5   r6   r7   rj   r9   r   r   rg   rg   `   s#            r   rg   c                       e Zd Zd ZdS )r   c                 T    t          t                              d                     d S )NzERROR! `huggingface-cli login` uses an outdated login mechanism that is not compatible with the Hugging Face Hub backend anymore. Please use `huggingface-cli login instead.printr;   rF   ri   s    r   runzLoginCommand.runf   s4    HH= 	
 	
 	
 	
 	
r   Nr5   r6   r7   rp   r9   r   r   r   r   e   #        
 
 
 
 
r   r   c                       e Zd Zd ZdS )r   c                 H   t          t                              d                     t          j                    }|t          d           t                       	 t          |          \  }}t          |           |r=t          t                              d          d                    |                     d S d S # t          $ rZ}t          |           t          t                              |j
        j                             t          d           Y d }~d S d }~ww xY w)NzxWARNING! `transformers-cli whoami` is deprecated and will be removed in v5. Please use `huggingface-cli whoami` instead.Not logged inzorgs: ,r
   )rn   r;   rF   r   	get_tokenexitr   rB   r`   r	   responsetext)ri   tokenuserorgses        r   rp   zWhoamiCommand.runq   s   HH4 	
 	
 	
 "$$=/"""FFF	JD$$KKK ;dii))388D>>:::::; ; 	 	 	!HHH$((1:?++,,,GGGGGGGGG	s   AB= =
D!ADD!Nrq   r9   r   r   r   r   p   s#            r   r   c                       e Zd Zd ZdS )r    c                 T    t          t                              d                     d S )NzERROR! `transformers-cli logout` uses an outdated logout mechanism that is not compatible with the Hugging Face Hub backend anymore. Please use `huggingface-cli logout instead.rm   ro   s    r   rp   zLogoutCommand.run   s4    HH> 	
 	
 	
 	
 	
r   Nrq   r9   r   r   r    r       rr   r   r    c                       e Zd Zd ZdS )r(   c                 ^   t          t                              d                     t          j                    }|t          d           t          d           	 t          j        ddg                              d          }t          t          	                    |
                                                     n# t          $ r t          d           Y nw xY w	 t          j        ddg                              d          }t          t          	                    |
                                                     n7# t          $ r* t          t                              d	                     Y nw xY wt          d
           t          |          \  }}| j        j        | j        j        n|}| d| j        j         }t          dt                              |                      | j        j        sPt%          d                                          }|d
k    s)|dk    s#|dk    st          d           t                       	 t)          ||          }nf# t*          $ rY}	t          |	           t          t                              |	j        j                             t          d           Y d }	~	nd }	~	ww xY wt          d           t          dt                              |                      t          d           t          d|            t          d
           d S )NzlWARNING! Managing repositories through transformers-cli is deprecated. Please use `huggingface-cli` instead.ru   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). /zYou are about to create zProceed? [Y/n] yyesAbort)repo_idr{   z
Your repo now lives at:z  zK
You can clone it locally with the command below, and commit/push as usual.z
  git clone )rn   r;   rF   r   rw   rx   
subprocesscheck_outputdecoderI   stripFileNotFoundErrorr   r   organizationr#   rB   r   inputlowerr   r	   ry   rz   )
ri   r{   stdoutr|   _	namespace	full_namechoiceurlr~   s
             r   rp   zRepoCreateCommand.run   s   HH8 	
 	
 	
 "$$=/"""GGG	O,e[-ABBII'RRF$))FLLNN++,,,,  	O 	O 	OMNNNNN	O
	,i-EFFMMgVVF$))FLLNN++,,,,  	 	 	S     	 	b			--a.2i.D.PDI**VZ	 3349>33	?9)=)=??@@@y} 	,--3355FbLLFcMMVu__g	iu===CC 	 	 	!HHH$((1:?++,,,GGGGGGGG	 	)***#499S>>##$$$\]]]$s$$%%%b					s?   A"B? ?CCA"E 1E65E6I 
K(AJ<<KNrq   r9   r   r   r(   r(      s#        2 2 2 2 2r   r(   )r   argparser   typingr   r   huggingface_hub.hf_apir   r   r   requests.exceptionsr	   r   r   r   r;   r-   intre   rg   r   r   r    r(   r9   r   r   <module>r      s       # # # # # #         @ @ @ @ @ @ @ @ @ @ ) ) ) ) ) ) ( ( ( ( ( (S S S S S- S S S>- - - - - - - -.4U38_-. c s    "       

 
 
 
 
? 
 
 
    O   .
 
 
 
 
O 
 
 
3 3 3 3 3 3 3 3 3 3r   