wL i\dZddlmZddlmZmZddlmZddlm Z ddl m Z ddl m Z dd lmZmZmZmZdd lmZmZmZd d lmZmZej4eZ dd lmZddlm Z dZ!Gdde Z#GddZ$Gdde$Z%Gdde$Z&Gdde$Z'Gdde$Z(Gdde$Z)y#e"$rdZ!YVwxYw) aDContains 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 )_SubParsersAction)ListOptional) HTTPError)BaseHuggingfaceCLICommand)ENDPOINT)HfApi) auth_list auth_switchloginlogout)get_stored_tokens get_tokenlogging)ANSIshow_deprecation_warning)inquirer)ChoiceTFc"eZdZedefdZy) UserCommandsparserc|jdd}|jdtd|jddd |jd |jd d}|jd |jdd}|jdtd|jd |jdd}|j d}|jdd}|jdtd|jddd |jd |jdd}|jd y)Nr z8Log in using a token from huggingface.co/settings/tokens)helpz--tokenz;Token generated from https://huggingface.co/settings/tokens)typerz--add-to-git-credential store_truez.Optional: Save token to git credential helper.)actionrct|SN) LoginCommandargss c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/huggingface_hub/commands/user.pyz2UserCommands.register_subcommand..Hs L4F)funcwhoamiz;Find out which huggingface.co account you are logged in as.ct|Sr ) WhoamiCommandr"s r$r%z2UserCommands.register_subcommand..J ]45Hr&rzLog outz --token-namez3Optional: Name of the access token to log out from.ct|Sr ) LogoutCommandr"s r$r%z2UserCommands.register_subcommand..Rr+r&authz%Other authentication related commandszAuthentication subcommandsswitchzSwitch between access tokensz0Optional: Name of the access token to switch to.ct|Sr )AuthSwitchCommandr"s r$r%z2UserCommands.register_subcommand..as :KD:Qr&listzList all stored access tokensct|Sr )AuthListCommandr"s r$r%z2UserCommands.register_subcommand..cs 8Mr&) add_parser add_argumentstr set_defaultsadd_subparsers)r login_parser whoami_parser logout_parser auth_parserauth_subparsersauth_switch_parserauth_list_parsers r$register_subcommandz UserCommands.register_subcommand;s((7q(r !! N " !! %A " !!'F!G))(9v)w ""(H"I))()C "" F # ""(H"I''5\'] %44:V4W,77Ge7f'' C ( '' %A ( ''-Q'R*55fCb5c%%+M%Nr&N)__name__ __module__ __qualname__ staticmethodrrAr&r$rr:s'O$5'O'Or&rceZdZdZy)BaseUserCommandc0||_t|_yr )r#r _api)selfr#s r$__init__zBaseUserCommand.__init__gs G r&N)rBrCrDrLrFr&r$rHrHfsr&rHceZdZdZy)r!ctddtjt|jj |jj y)Nzhuggingface-cli loginz hf auth login)tokenadd_to_git_credential)rrset_verbosity_infor r#rOrPrKs r$runzLoginCommand.runms9 !8/J""$ ))//"&))"A"A r&NrBrCrDrSrFr&r$r!r!ls r&r!ceZdZdZy)r-ctddtjt|jj y)Nzhuggingface-cli logoutzhf auth logout) token_name)rrrQrr#rWrRs r$rSzLogoutCommand.runxs, !9;KL""$$))../r&NrTrFr&r$r-r-ws0r&r-c@eZdZdZdeefdZdeedeefdZy)r1ctddtj|jj}||j }|t dtt||jjy)Nzhuggingface-cli auth switchzhf auth switchz!No token name provided. Aborting.)rP) rrrQr#rW_select_token_nameprintexitr rP)rKrWs r$rSzAuthSwitchCommand.runse !>@PQ""$YY))  002J   5 6 FJdii6U6UVr&returncttj}|stj dyt r|j |Stdt|dD]\}}t|d| td}|jdk(ryt|dz }d|cxkrt|krnn||Std W#t$rtd YwxYw) Nz+No stored tokens found. Please login first.zAvailable stored tokens:rz. z=Enter the number of the token to switch to (or 'q' to quit): qrz$Invalid selection. Please try again.z4Invalid input. Please enter a number or 'q' to quit.)r2rkeysloggererror_inquirer_py_available_select_token_name_tuir[ enumerateinputlowerintlen ValueError)rK token_namesirWchoiceindexs r$rZz$AuthSwitchCommand._select_token_names,.3356  LLF G !..{; ; ()&{A6 (MAz QCr*& ' ( N^_<<>S(F a0K 00&u--@A NLM NsC!)C CC/.C/rkc|Dcgc]}t||}} tjd|djScc}w#t$rt j dYywxYw)N)namezSelect a token to switch to:)messagechoicesdefaultzToken selection cancelled.)rrselectexecuteKeyboardInterruptrainfo)rKrkrWrrs r$rdz(AuthSwitchCommand._select_token_name_tuiskITU:6*:6UU ??6gi  V!  KK4 5 sA%AA('A(N) rBrCrDrSrr7rZrrdrFr&r$r1r1s5 WNHSMN4 $s)  r&r1ceZdZdZy)r4cXtddtjty)Nzhuggingface-cli auth listz hf auth list)rrrQr rRs r$rSzAuthListCommand.runs !:33@ KL4 9   !H $((1::??+ , GG s+0B? B:+A B?:B?? DADDNrTrFr&r$r*r*sr&r*N)*__doc__argparsertypingrrrequests.exceptionsrhuggingface_hub.commandsrhuggingface_hub.constantsrhuggingface_hub.hf_apir _loginr r r rutilsrrr _cli_utilsrr get_loggerrBra InquirerPyrInquirerPy.base.controlrrc ImportErrorrrHr!r-r1r4r*rFr&r$rs&'!)>.(::996   H %##.! )O,)OX  ? 0O022joOM#"#sB55B?>B?