Spaces:
Build error
Build error
π€ Hugging Face Token Setup Guide
Why You Need This
AudioForge uses AI models from Hugging Face:
- MusicGen (Facebook) - Music generation
- Bark (Suno) - Vocal synthesis
- Demucs (Facebook) - Audio separation
These models require a Hugging Face token to download.
π Quick Setup (Automated)
Option 1: Interactive Setup Script (Recommended)
# Run the interactive setup
python scripts/setup_env.py
This will:
- β Prompt you for your Hugging Face token
- β Configure all environment variables
- β Generate a secure secret key
- β
Create your
.envfile automatically
π Get Your Hugging Face Token
Step 1: Create Account (if needed)
- Go to https://huggingface.co/join
- Sign up (it's free!)
Step 2: Generate Token
- Go to https://huggingface.co/settings/tokens
- Click "New token"
- Give it a name (e.g., "AudioForge")
- Select "Read" permissions (sufficient for model downloads)
- Click "Generate token"
- Copy the token (you won't see it again!)
π Manual Setup
If you prefer to configure manually:
1. Create .env file
cd backend
cp .env.example .env
2. Edit .env and add your token
# Open in your editor
code .env # VS Code
# or
notepad .env # Windows
# or
nano .env # Linux/Mac
3. Add these lines (minimum required):
# Hugging Face Token (REQUIRED)
HUGGINGFACE_TOKEN=hf_your_token_here
HF_TOKEN=hf_your_token_here
# Device (cpu or cuda)
MUSICGEN_DEVICE=cpu
BARK_DEVICE=cpu
DEMUCS_DEVICE=cpu
# Database
DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/audioforge
# Redis
REDIS_URL=redis://localhost:6379/0
# Secret Key (generate with: python -c "import secrets; print(secrets.token_urlsafe(32))")
SECRET_KEY=your-generated-secret-key
# CORS
ALLOWED_ORIGINS=http://localhost:3000
β Verify Setup
Check if token is configured:
cd backend
python -c "from app.core.config import settings; print('β
Token configured!' if settings.HUGGINGFACE_TOKEN else 'β Token missing!')"
Test model download:
cd backend
python -c "
from transformers import AutoProcessor
processor = AutoProcessor.from_pretrained('facebook/musicgen-small')
print('β
Models can be downloaded!')
"
π₯οΈ GPU Acceleration (Optional)
If you have an NVIDIA GPU with CUDA:
1. Check CUDA availability:
python -c "import torch; print('β
CUDA available!' if torch.cuda.is_available() else 'β CUDA not available')"
2. Update .env to use GPU:
MUSICGEN_DEVICE=cuda
BARK_DEVICE=cuda
DEMUCS_DEVICE=cuda
Benefits:
- β‘ 10-50x faster generation
- π΅ Can generate longer audio
- π Better for production
π Security Best Practices
β DO:
- Keep your token private
- Add
.envto.gitignore(already done) - Use read-only tokens
- Rotate tokens periodically
β DON'T:
- Commit
.envto git - Share your token publicly
- Use tokens with write permissions
- Hardcode tokens in code
π Troubleshooting
Problem: "401 Unauthorized" when downloading models
Solution: Check your token is valid
curl -H "Authorization: Bearer YOUR_TOKEN" https://huggingface.co/api/whoami
Problem: "Token not found"
Solution: Make sure .env file exists and has the token
cat backend/.env | grep HF_TOKEN
Problem: Models downloading to wrong location
Solution: Set cache directory in .env
TRANSFORMERS_CACHE=/path/to/cache
HF_HOME=/path/to/huggingface
Problem: Out of memory when loading models
Solutions:
Use smaller models:
MUSICGEN_MODEL=facebook/musicgen-small BARK_MODEL=suno/bark-smallUse CPU instead of GPU:
MUSICGEN_DEVICE=cpuIncrease system swap space
π Model Sizes
| Model | Size | Device | RAM Required |
|---|---|---|---|
| MusicGen Small | ~1.5GB | CPU | 4GB+ |
| MusicGen Small | ~1.5GB | CUDA | 6GB+ VRAM |
| Bark Small | ~2GB | CPU | 4GB+ |
| Bark Small | ~2GB | CUDA | 8GB+ VRAM |
| Demucs | ~300MB | CPU | 2GB+ |
Recommendation: Start with small models on CPU for testing, then upgrade to GPU for production.
π Quick Start After Setup
# 1. Verify setup
python scripts/setup_env.py
# 2. Install dependencies
cd backend
pip install -e ".[dev]"
# 3. Initialize database
python scripts/init_db.py
# 4. Start backend
uvicorn app.main:app --reload
# 5. Test generation
curl -X POST http://localhost:8000/api/v1/generations \
-H "Content-Type: application/json" \
-d '{"prompt": "A calm acoustic guitar melody", "duration": 10}'
π Additional Resources
- Hugging Face Docs: https://huggingface.co/docs
- MusicGen Model: https://huggingface.co/facebook/musicgen-small
- Bark Model: https://huggingface.co/suno/bark-small
- Transformers Library: https://huggingface.co/docs/transformers
π Still Need Help?
- Check the main
SETUP.mdguide - Run the verification script:
python backend/scripts/verify_setup.py - Check logs:
tail -f backend/logs/app.log - Review
LAUNCH_GUIDE.mdfor detailed troubleshooting
πΌβ‘ Once configured, models will download automatically on first use. Be patientβthe first download takes a few minutes!