How to login to Huggingface Hub with Access Token

I initially created read and write tokens at Hugging Face – The AI community building the future. as below:

In the python code, I am using the following import and the necessary access token.

from huggingface_hub import login
access_token_read = “abc”
access_token_write = “xyz”
login(token = access_token_read)

11 Likes

That worked !!

So I’m guessing you guys are on Windows, the EASIEST thing is in your command prompt set the environment variable HF_TOKEN and the download-model.py script will do the rest assuming you’re using oogabooga

set HF_TOKEN=<YOUR_TOKEN>

ctrl + “right click”

solution simple

!huggingface-cli login --token hf_KjwGsxQLUR6ydfyhyuyDvObzCcRXaeTC

6 Likes

solution
with your command pass --token

This is for Windows!

  1. After Token: just Right-click and yes you won’t see anything actually pasting there but it actually was pasted just due to the sensitivity of the information, it is not visible.
  2. Hit Enter.
  3. It will probably ask you to add the token as git credential. Press “y” or “n” according to your situation and hit enter.
  4. You will be logged in! (hopefully) :smiling_face:

thank you,it’s very helpful

Same way how arguments are passed in Linux sys.argv().
Anyways like you, I was also skeptical about keeping my key in the open, so I pasted it in a txt file and then read that line inside the load() function in string format. Works as well. :slight_smile:

Thank you for posting your solution…I’m still new to CLI and didn’t realize the password wouldn’t show up.

$ huggingface-cli login --token cat token # where token is a file with your token

1 Like

Careful with this @Malveserai. You just exposed your token, allowing anyone to access your account.