Module 5 Resources#

Setting Up Your Hugging Face Token in Google Colab#

Some notebooks download models from Hugging Face. To avoid download limits and errors, each student must use their own Hugging Face Read token.

This is free, safe, and takes about 2–3 minutes.


Step 1: Create a Hugging Face token#

  1. Go to: https://huggingface.co/settings/tokens

  2. Click New token

  3. Choose:

    • Name: anything (e.g. colab)

    • Role: Read

  4. Click Create token

  5. Copy the token (you won’t see it again)

Do not share your token with anyone.


Step 2: Add the token to Colab (Key icon)#

  1. Open the notebook in Google Colab

  2. Look at the left sidebar

  3. Click the Secrets icon (key symbol)

  4. Click “Add a new secret”

  5. Enter:

    • Name: HF_TOKEN

    • Value: paste your token

  6. Turn ON: “Available to all notebooks”

  7. Restart the runtime

There is no “Runtime → Secrets” menu anymore — the key icon is the correct place.


Step 3: Verify it worked#

Run this cell in the notebook:

import os

assert "HF_TOKEN" in os.environ, "HF_TOKEN not found"
print("HF_TOKEN loaded successfully")

If you see:

HF_TOKEN loaded successfully

you’re done!


Common issues & fixes#

Secrets icon missing?

  • Make sure you are using Google Colab (not local Jupyter)

  • Click the menu icon to expand the sidebar

  • Try zooming out slightly in your browser

Still getting warnings?

  • Restart the runtime again

  • Re-check the secret name is exactly HF_TOKEN (case-sensitive)


Important rules#

  • Do not hard-code tokens in code cells

  • Do not share tokens

  • Do not upload tokens to GitHub

  • Use Read access only


Additional Learning Materials#