Spaces:
Running
Running
A newer version of the Gradio SDK is available:
5.46.1
Hugging Face Space Environment Variables Setup
After your GitHub Actions deploys your app to Hugging Face Spaces, you need to configure the API keys directly in your Hugging Face Space.
Step 1: Go to Your Space Settings
- Visit your deployed space:
https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
- Click the "Settings" tab (next to "App", "Files", etc.)
Step 2: Add Environment Variables
In the Settings page, scroll down to find the "Repository secrets" or "Variables and secrets" section.
Add these secrets:
Variable Name | Value | Description |
---|---|---|
OPENAI_API_KEY |
sk-... |
Your OpenAI API key (if using OpenAI models) |
ANTHROPIC_API_KEY |
sk-ant-... |
Your Anthropic API key (if using Claude) |
Step 3: How to Add Each Secret
- Click "New secret"
- Name: Enter the variable name exactly (e.g.,
OPENAI_API_KEY
) - Value: Enter your API key
- Click "Add secret"
- Repeat for each API key
Step 4: Restart Your Space
After adding the secrets:
- Go back to the "App" tab
- Your space should automatically restart
- If not, click the "β³ Restart" button
Important Notes:
- β Secrets are secure - They won't be visible in logs or to other users
- β Environment variables override .env - Even if there's a .env file, the Space secrets take priority
- β No need to redeploy - Changes take effect immediately after restart
- β οΈ Case sensitive - Variable names must match exactly
Verification:
Your app should now work with the API keys. Check the Space logs:
- Go to your Space
- Click "Logs" tab
- Look for successful API connections
Troubleshooting:
If your app still shows API key errors:
- Check variable names - Must be exactly
OPENAI_API_KEY
orANTHROPIC_API_KEY
- Check API key format - OpenAI keys start with
sk-
, Anthropic withsk-ant-
- Restart the space - Changes may require a restart
- Check logs - Look for specific error messages in the Logs tab
Alternative: Using Hugging Face CLI (Advanced)
You can also set secrets via CLI if you have huggingface_hub
installed:
# Install the CLI
pip install huggingface_hub
# Login
huggingface-cli login
# Add secrets
huggingface-cli repo add-secret YOUR_USERNAME/YOUR_SPACE_NAME OPENAI_API_KEY "your_key_here"
huggingface-cli repo add-secret YOUR_USERNAME/YOUR_SPACE_NAME ANTHROPIC_API_KEY "your_key_here"
Once you've set up these environment variables in your Hugging Face Space, your fitness app should work perfectly! π