o
    0j                     @   s  d Z ddlmZ ddl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mZmZ d	d
lmZmZ d	dlmZ eeZeddZejdg dd			d6dedeeejddf deeejddf ddfddZejdddgd	d7deedB ejddf ddfdd ZdedB fd!d"Z ejd#d$d%gd		d8deedB ejd&df deeejddf ddfd'd(Z!ejd)d*gdd9d+d,Z"ejdd-d.gdd9d/d0Z#ejd1d2d3gdd9d4d5Z$dS ):a  Contains commands to authenticate to the Hugging Face Hub and interact with your repositories.

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

    # switch between tokens
    hf auth switch

    # list all tokens
    hf auth list

    # logout from all tokens
    hf auth logout

    # check which account you are logged in as
    hf auth whoami
    )	AnnotatedN)ENDPOINT)whoami   )	auth_listauth_switchloginlogout)get_stored_tokens	get_tokenlogging   )TokenOpttyper_factory)outz,Manage authentication (login, logout, etc.).)helpr   )zhf auth loginzhf auth login --token $HF_TOKENz7hf auth login --token $HF_TOKEN --add-to-git-credentialzhf auth login --force)ZexamplesFtokenadd_to_git_credentialzTSave to git credential helper. Useful only if you plan to run git commands directly.forcez)Force re-login even if already logged in.returnc                 C   s   t | || d dS )z8Login using a token from huggingface.co/settings/tokens.)r   r   Zskip_if_logged_inN)r   )r   r   r    r   Y/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/huggingface_hub/cli/auth.py
auth_login4   s   r   r	   zhf auth logoutz$hf auth logout --token-name my-token
token_namezName of token to logoutc                 C   s   t | d dS )zLogout from a specific token.r   N)r	   r   r   r   r   auth_logoutP   s   r   c                  C   s   t t  } | std d S td t| dD ]\}}t| d|  q	 z,td}| dkr6W d S t	|d }d|  krHt
| k rOn n| | W S td	 W n tya   td
 Y nw q()Nz+No stored tokens found. Please login first.zAvailable stored tokens:r   z. Tz=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.)listr
   keysloggererrorprint	enumerateinputlowerintlen
ValueError)Ztoken_namesir   choiceindexr   r   r   _select_token_name^   s(   

r+   switchzhf auth switchz$hf auth switch --token-name my-tokenzName of the token to switch toc                 C   s6   | du rt  } | du rtd t t| |d dS )zSwitch between access tokens.Nz!No token name provided. Aborting.)r   )r+   r!   typerExitr   )r   r   r   r   r   auth_switch_cmdv   s   r/   z	list | lszhf auth listc                   C   s
   t   dS )zList all stored access tokens.N)r   r   r   r   r   auth_list_cmd   s   
r0   zhf auth tokenz8hf auth token | xargs curl -H 'Authorization: Bearer {}'c                  C   s:   t  } | du rtd tjddt|  td dS )z)Print the current access token to stdout.Nz)Not logged in. Run `hf auth login` first.r   codez@Run `hf auth whoami` to see which account this token belongs to.)r   r   r    r-   r.   r!   hint)r   r   r   r   
auth_token   s   
r4   r   zhf auth whoamizhf auth whoami --format jsonc                  C   sr   t  } | du rtd tjddt| }ddd |d D p#d}td	kr*tnd}tjd
|d ||d dS )z;Find out which huggingface.co account you are logged in as.NzNot logged inr   r1   ,c                 s   s    | ]}|d  V  qdS )nameNr   ).0orgr   r   r   	<genexpr>   s    zauth_whoami.<locals>.<genexpr>orgszhttps://huggingface.coz	Logged inr6   )userr:   endpoint)	r   r   r    r-   r.   r   joinr   result)r   infor:   r<   r   r   r   auth_whoami   s   
r@   )NFF)N)NF)r   N)%__doc__typingr   r-   Zhuggingface_hub.constantsr   Zhuggingface_hub.hf_apir   Z_loginr   r   r   r	   utilsr
   r   r   Z
_cli_utilsr   r   _outputr   Z
get_logger__name__r   Zauth_clicommandboolOptionr   strr   r+   r/   r0   r4   r@   r   r   r   r   <module>   s   






