algospeak / HF_TOKEN_SETUP.md
travahacker
Fix: Add HF token support and error handling for API authentication
d3d6e15

A newer version of the Gradio SDK is available: 6.0.0

Upgrade

πŸ”‘ How to Add HuggingFace Token to Your Space

The AlgoSpeak AI app needs a HuggingFace token to access the Mistral-7B model for better translation quality.

Why do I need this?

  • Without token: Uses Google Flan-T5 (smaller, limited quality)
  • With token: Uses Mistral-7B (better understanding, higher quality)

Step-by-Step Instructions

1. Create a HuggingFace Access Token

  1. Go to HuggingFace Settings β†’ Tokens
  2. Click "New token"
  3. Give it a name like algospeak-space
  4. Select permission: Read (sufficient for inference)
  5. Click "Generate"
  6. Copy the token (you won't see it again!)

2. Add Token as Secret to Your Space

  1. Go to your Space: https://huggingface.co/spaces/Veronyka/algospeak
  2. Click on "Settings" tab (βš™οΈ)
  3. Scroll to "Repository secrets" section
  4. Click "New secret"
  5. Fill in:
    • Name: HF_TOKEN
    • Value: Paste your token here
  6. Click "Add secret"

3. Restart Your Space

  1. Go to "Settings" β†’ "Factory reboot"
  2. Or just wait ~1 minute for automatic restart

4. Verify It's Working

  • The app header should now show: πŸ€– Current Model: mistralai/Mistral-7B-Instruct-v0.3
  • Translations should be more contextual and higher quality

Troubleshooting

Still seeing errors?

  • Check if the secret name is exactly HF_TOKEN (case-sensitive)
  • Make sure your token has "Read" permission
  • Try Factory reboot in Settings

Token not being used?

  • The app will automatically detect the token via environment variable
  • No code changes needed!

Security Note: Secrets in HF Spaces are encrypted and not visible to visitors. Only the Space owner can see/edit them.