gunashree_hackathon / SETUP_ENV.md
anish
Anish done
d647a11

Setting Environment Variables in Hugging Face Spaces

Method 1: Web UI (Recommended)

  1. Go to your Space: https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
  2. Click Settings tab (⚙️ icon)
  3. Scroll to Repository secrets section
  4. Click Add secret
  5. Enter:
    • Name: API_KEY
    • Value: Your secret API key (e.g., my-secure-key-2024)
  6. Click Add secret
  7. The Space will automatically rebuild with the new environment variable

Method 2: Using Hugging Face CLI

# Install CLI if needed
pip install huggingface_hub

# Login
huggingface-cli login

# Set environment variable
huggingface-cli env set API_KEY "your-secret-key-here" --space YOUR_USERNAME/YOUR_SPACE_NAME

Method 3: In Dockerfile (Not Recommended for Secrets)

You can also set default values in Dockerfile, but this is NOT secure for secrets:

ENV API_KEY=default-key

Current API Key Behavior

  • Reads from API_KEY environment variable
  • Falls back to "hackathon-secret" if not set
  • Recommendation: Always set API_KEY in Spaces settings for production