Hugging Face Spaces Deployment
Complete guide to deploy Open Navigator to Hugging Face Spaces with all three applications running together.
📋 What Gets Deployed
This deployment runs all three apps in a single Docker Space:
| Component | Access Path | Description |
|---|---|---|
| Documentation | /docs | Docusaurus documentation site |
| Main App | / | React frontend application |
| API | /api | FastAPI backend server |
All served through nginx reverse proxy on port 7860 (Hugging Face Spaces default).
🚀 Quick Start for Developers
TL;DR - Deploy in 3 commands:
# 1. Set your Hugging Face username in .env
echo "HF_USERNAME=your_username" >> .env
# 2. Run the deployment script (includes testing)
./deploy-huggingface.sh
# 3. Configure your Space
# - Go to https://huggingface.co/spaces/YOUR_USERNAME/www.communityone.com
# - Settings → Resource configuration → Select "CPU Basic"
# - Settings → Variables and secrets → Add your API keys
The script will:
- ✅ Test Docusaurus build (catches config errors)
- ✅ Test Docker build locally (validates deployment)
- ✅ Create the Space on Hugging Face
- ✅ Push your code
- ✅ Trigger automatic build (~10-15 minutes)
Note: This project uses Apache 2.0 license (updated from MIT in April 2026).
💰 Cost Breakdown
Required:
- CPU Basic Hardware: ~$0.03/hour = ~$22/month
- 2 vCPU, 16 GB RAM
- Required to run Docker Spaces
Optional:
- Pro Plan: $9/month
- Persistent storage (keeps data between restarts)
- Better performance
- Private Spaces option
- Longer timeout limits
Total Cost: $22-31/month depending on plan
🛠️ Prerequisites
- Hugging Face Account: Sign up at huggingface.co
- Hugging Face Token: Create at Settings → Access Tokens
- Needs
writepermission
- Needs
- API Keys: Your OpenAI/Anthropic keys for LLM features
- Git: Installed locally
📦 Step 1: Prepare Your Repository
The deployment files are already created:
.huggingface/
├── README.md # Space description (shown on HF)
├── nginx.conf # Reverse proxy config
├── supervisord.conf # Process manager config
└── start.sh # Startup script
Dockerfile.huggingface # Multi-stage Docker build
🚀 Step 2: Create the Hugging Face Space
Option A: Using the Web UI
- Go to huggingface.co/new-space
- Configure:
- Space name:
open-navigator-for-engagement - License:
Apache 2.0 - Space SDK: Select
Docker - Visibility: Public or Private
- Space name:
- Click Create Space
Option B: Using the CLI
# Install huggingface-hub
pip install huggingface-hub
# Login with your token
huggingface-cli login
# Create the Space
huggingface-cli repo create open-navigator-for-engagement --type space --space-sdk docker
📤 Step 3: Deploy Your Code
Option A: Automated Deployment (Recommended)
Use the deployment script for easy one-command deployment:
Step 1: Set your username
Add to your .env file:
echo "HF_USERNAME=your_hf_username" >> .env
Or export for current session:
export HF_USERNAME=getcommunityone # Replace with your username
Step 2: Run deployment script
./deploy-huggingface.sh
The script automatically:
- Creates the Space on Hugging Face
- Sets up deployment branch
- Configures Dockerfile and README
- Pushes to Hugging Face
You can also pass username as argument: ./deploy-huggingface.sh YOUR_USERNAME
Option B: Manual Deployment
If you prefer manual control:
# Add Hugging Face as a remote
git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/open-navigator-for-engagement
# Create a deployment branch with the right Dockerfile
git checkout -b huggingface-deploy
# Rename Dockerfile.huggingface to Dockerfile (HF looks for this)
cp Dockerfile.huggingface Dockerfile
# Copy the HF README to root (HF displays this)
cp .huggingface/README.md README_HF.md
# Commit changes
git add Dockerfile README_HF.md .huggingface/
git commit -m "Configure Hugging Face Space deployment"
# Push to Hugging Face
git push hf huggingface-deploy:main
🔧 Step 4: Configure Space Settings
- Go to your Space:
https://huggingface.co/spaces/YOUR_USERNAME/open-navigator-for-engagement - Click Settings
- Under Resource configuration:
- Select CPU Basic (minimum required)
- Or CPU Upgrade for better performance
- Under Variables and secrets (⚠️ IMPORTANT):
- Add your API keys as secrets:
OPENAI_API_KEY = sk-your-key-hereANTHROPIC_API_KEY = sk-ant-your-key-hereHUGGINGFACE_TOKEN = hf_your-token-here
- Set environment variables:
LOG_LEVEL = INFOPYTHONUNBUFFERED = 1
- Add your API keys as secrets:
- Click Save
🔄 Step 5: Wait for Build
The Space will automatically build when you push. This takes 10-15 minutes:
- Building documentation (Docusaurus)
- Building frontend (React + Vite)
- Installing Python dependencies
- Configuring nginx reverse proxy
- Starting services
Watch build progress in the Logs tab.
✅ Step 6: Verify Deployment
Once built, test each component:
1. Check Main App
https://YOUR_USERNAME-open-navigator-for-engagement.hf.space/
Should show the React dashboard.
2. Check Documentation
https://YOUR_USERNAME-open-navigator-for-engagement.hf.space/docs
Should show Docusaurus docs.
3. Check API
https://YOUR_USERNAME-open-navigator-for-engagement.hf.space/api/docs
Should show FastAPI Swagger docs.
4. Test API Endpoint
curl https://YOUR_USERNAME-open-navigator-for-engagement.hf.space/api/health
Should return: {"status": "healthy"}
🔄 Updating Your Space
When you make changes to your code:
# Make your changes in your main branch
git checkout main
# ... make edits ...
git commit -am "Update feature X"
# Merge to deployment branch
git checkout huggingface-deploy
git merge main
# Update Dockerfile if needed
cp Dockerfile.huggingface Dockerfile
git add Dockerfile
git commit -m "Update deployment"
# Push to Hugging Face
git push hf huggingface-deploy:main
The Space will automatically rebuild.
🐛 Troubleshooting
Build Fails
Check logs: Click Logs tab in your Space
Common issues:
- Missing dependencies → Check
requirements.txt - Node.js build errors → Check
package.jsonversions - Out of memory → Upgrade to larger hardware
App Doesn't Start
- Check environment variables are set
- Verify API keys are correct
- Check logs for Python errors
- Ensure port 7860 is exposed
404 Errors
/works but/docsdoesn't → Check nginx.conf routing/apireturns 404 → Check FastAPI is running on port 8000- Static files not loading → Check build output directories
Performance Issues
- Slow response: Upgrade to CPU Upgrade or GPU
- Timeouts: Enable Pro plan for longer limits
- Out of memory: Reduce concurrent workers or upgrade hardware
📊 Monitoring
View Logs
Settings → Logs → Container logs
Check Resource Usage
Settings → Resource configuration → Usage metrics
Monitor API Calls
FastAPI automatically logs requests to /var/log/supervisor/api.log
🔒 Security Best Practices
Secrets Management
✅ DO:
- Add API keys in Space Settings → Variables and secrets
- Use
Secrets(encrypted), notVariablesfor sensitive data - Set secrets as "Private" in settings
❌ DON'T:
- Commit
.envfiles with real keys - Hardcode secrets in code
- Share your Space's API keys
Access Control
- Set Space to Private if using sensitive data
- Use Hugging Face OAuth for user authentication
- Enable rate limiting in FastAPI
💡 Optimization Tips
Reduce Build Time
- Use smaller Docker base images
- Cache npm dependencies
- Use multi-stage builds (already configured)
Improve Performance
- Enable gzip compression (already configured in nginx)
- Set cache headers for static assets (already configured)
- Use CDN for large static files
Save Costs
- Use CPU Basic instead of GPU (unless you need it)
- Set Sleep timeout for inactive Spaces
- Use Persistent storage only if needed (requires Pro)
🎯 Advanced: Custom Domain
Hugging Face Spaces supports custom domains:
- Go to Space Settings
- Under Custom domain
- Add your domain (e.g.,
opennavigator.org) - Configure DNS:
CNAME record: opennavigator.org → YOUR_USERNAME-open-navigator-for-engagement.hf.space
📚 Additional Resources
🆘 Getting Help
- Hugging Face Discord: hf.co/join/discord
- GitHub Issues: Your repo issues
- Space Discussions: Comment on your Space page
🎉 Next Steps
After deployment:
- ✅ Test all three apps thoroughly
- ✅ Share your Space URL with users
- ✅ Monitor usage and costs
- ✅ Set up persistent storage if needed (Pro plan)
- ✅ Configure custom domain (optional)
Your Space URL:
https://huggingface.co/spaces/YOUR_USERNAME/open-navigator-for-engagement
Enjoy your fully deployed civic engagement platform! 🚀