Spaces:
Sleeping
π€ Hugging Face Spaces Deployment Guide
Why Hugging Face Spaces?
β
FREE hosting with your HF Pro account
β
Persistent storage for database and AI models
β
Public URL (e.g., https://your-username-participatory-planner.hf.space)
β
Auto-SSL (HTTPS included)
β
Easy updates via Git
β
No server management needed
β
Pro perks: Better hardware, faster model loading
Deployment Steps
Method 1: Web UI (Easiest - 5 minutes)
Go to Hugging Face Spaces
- Visit: https://huggingface.co/new-space
- Login with your HF Pro account
Create New Space
- Owner: Your username
- Space name:
participatory-planner(or your choice) - License: MIT
- SDK: Select Docker
- Hardware:
- Free tier: CPU Basic (2 vCPU, 16GB RAM) β Sufficient
- Pro upgrade: CPU Upgrade (4 vCPU, 32GB RAM) - Faster AI analysis
- Visibility: Public or Private
Upload Files
Click "Files" tab, then upload these files from your project:
Required files:
π Dockerfile (already configured for HF Spaces) π requirements.txt π app_hf.py π app/ (entire folder) π wsgi.py π .gitignore π README.md (the HF version)Optional but recommended:
π .env (with your FLASK_SECRET_KEY)Configure Secrets (Important!)
Go to "Settings" β "Repository secrets"
Add secret:
- Name:
FLASK_SECRET_KEY - Value:
8606a4f67a03c5579a6e73f47195549d446d1e55c9d41d783b36762fc4cd9d75
- Name:
Wait for Build
- Hugging Face will automatically build and deploy
- First build takes ~5-10 minutes (downloads AI model)
- Watch the "Logs" tab for progress
Access Your App!
- URL:
https://huggingface.co/spaces/YOUR_USERNAME/participatory-planner - Or embedded:
https://YOUR_USERNAME-participatory-planner.hf.space - Login:
<see-startup-logs-or-set-ADMIN_TOKEN>
- URL:
Method 2: Git CLI (For developers)
Initialize Git repo (if not already):
cd /home/thadillo/MyProjects/participatory_planner git initAdd Hugging Face remote:
# Install git-lfs for large files git lfs install # Add remote (replace YOUR_USERNAME) git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/participatory-plannerPrepare files:
# Make sure we're using HF-compatible Dockerfile cp Dockerfile.hf Dockerfile cp README_HF.md README.mdCommit and push:
git add . git commit -m "Initial deployment to Hugging Face Spaces" git push hf mainSet secrets on HF Spaces web UI (Settings β Secrets)
File Structure for HF Spaces
Your Space should have this structure:
participatory-planner/
βββ Dockerfile # HF Spaces configuration (port 7860)
βββ README.md # Space description (with YAML header)
βββ requirements.txt # Python dependencies
βββ app_hf.py # HF Spaces entry point
βββ wsgi.py # WSGI app
βββ .gitignore # Ignore patterns
βββ app/ # Main application
β βββ __init__.py
β βββ analyzer.py
β βββ models/
β βββ routes/
β βββ templates/
βββ instance/ # Created at runtime (database)
Configuration Details
Dockerfile Port
Hugging Face Spaces requires port 7860. This is already configured in Dockerfile.hf and app_hf.py.
README.md Header
The HF version has special YAML metadata at the top: ```yaml
title: Participatory Planning Application emoji: ποΈ colorFrom: blue colorTo: purple sdk: docker pinned: false license: mit
This configures how your Space appears on HF.
### Environment Variables
Set these in Space Settings β Repository secrets:
- `FLASK_SECRET_KEY`: Your secure secret key (already generated)
- `FLASK_ENV`: Set to `production`
### Persistent Storage
- Database stored in `/app/instance/` (persists between restarts)
- AI model cached in `/root/.cache/huggingface/` (persists)
- First run downloads ~1.5GB model (one-time)
---
## Advantages of HF Pro
With your **Hugging Face Pro** account, you get:
β
**Better hardware**:
- CPU Upgrade: 4 vCPU, 32GB RAM
- GPU options available (T4, A10G, A100)
- Faster AI analysis
β
**Private Spaces**:
- Keep your planning sessions confidential
- Password protection available
β
**Persistent storage**:
- 50GB for Pro (vs 5GB free)
- Database and models persist
β
**Custom domains**:
- Use your own domain name
- Better branding
β
**No sleep**:
- Space stays always-on
- No cold starts
β
**Priority support**:
- Faster builds
- Better reliability
---
## Cost Comparison
| Platform | Free Tier | Pro Cost | Our Recommendation |
|----------|-----------|----------|-------------------|
| **Hugging Face Pro** | β
Included | $9/mo (you have!) | β **BEST** |
| Heroku | β None | $7/mo | Limited resources |
| DigitalOcean | β None | $12/mo | Good alternative |
| AWS EC2 | β
12 months | ~$15/mo | Complex setup |
| Railway | β
$5 credit | $5/mo | Good for prototypes |
| Render | β
750 hrs/mo | $7/mo | Good alternative |
**Winner**: Hugging Face Spaces with your Pro account = **FREE + BEST**
---
## GPU Acceleration (Optional)
Your app works fine on CPU, but for **very large sessions** (500+ submissions), you can enable GPU:
1. Go to Space Settings β Hardware
2. Select GPU (T4 is cheapest)
3. Update `app/analyzer.py`:
```python
# Change device from -1 (CPU) to 0 (GPU)
self.classifier = pipeline("zero-shot-classification",
model=self.model_name,
device=0) # Use GPU
Note: GPU costs extra (~$0.60/hr with Pro discount). Only enable if needed.
Updating Your Space
Via Web UI:
- Go to your Space β Files tab
- Click on file to edit
- Make changes and commit
Via Git:
git add .
git commit -m "Update feature X"
git push hf main
Space rebuilds automatically on push.
Monitoring & Logs
View Logs:
- Go to your Space
- Click "Logs" tab
- See real-time application logs
Check Status:
- Green badge = Running
- Yellow badge = Building
- Red badge = Error
Metrics (Pro):
- View CPU/RAM usage
- Monitor request counts
- Track uptime
Troubleshooting
Build fails with "out of memory"
Solution: Upgrade to CPU Upgrade hardware (Settings β Hardware)
AI model download times out
Solution: First build takes 10+ minutes. Be patient. Model caches after first run.
Database resets on restart
Solution: Ensure /app/instance/ is in a persistent volume. Check Dockerfile:
RUN mkdir -p instance
Port errors
Solution: HF Spaces requires port 7860. Verify app_hf.py uses this port.
Can't access Space
Solution: Check Space visibility in Settings. Set to Public or add collaborators.
Advanced: Custom Domain
With HF Pro, you can use your own domain:
- Go to Settings β Custom domains
- Add domain:
planning.yourdomain.com - Configure DNS:
CNAME planning -> YOUR_USERNAME-participatory-planner.hf.space - Wait for verification (5-30 minutes)
- Access:
https://planning.yourdomain.com
SSL certificate automatically provisioned!
Backup Strategy
Since HF Spaces has persistent storage, you should still backup:
Automatic Backups:
Use the Export JSON feature weekly:
- Login as admin
- Click "Save Session" (top nav)
- Downloads complete backup
- Store in cloud (Google Drive, Dropbox, etc.)
Manual Database Backup:
Access Space terminal (if enabled) and copy /app/instance/app.db
Security Best Practices
Change admin token:
- Edit
app/models/models.py - Change
<see-startup-logs-or-set-ADMIN_TOKEN>to secure token - Redeploy
- Edit
Use secrets for sensitive data:
- Never commit
.envwith real keys - Use HF Secrets for configuration
- Never commit
Enable authentication (optional):
- HF Spaces can add login wall
- Settings β Enable authentication
Make Space private (for confidential sessions):
- Settings β Visibility β Private
- Only invited users can access
Next Steps After Deployment
Share your Space:
ποΈ Participatory Planning Platform https://huggingface.co/spaces/YOUR_USERNAME/participatory-planner Admin: ADMIN123Customize branding:
- Edit README.md header (emoji, colors)
- Update templates in
app/templates/
Monitor usage:
- Check Logs regularly
- Export data weekly
- Watch for errors
Scale if needed:
- Upgrade hardware for large sessions
- Enable GPU for faster analysis
- Add custom domain
Support
- HF Spaces Docs: https://huggingface.co/docs/hub/spaces
- HF Community: https://discuss.huggingface.co/
- Your App Logs: Space β Logs tab
Summary
β You have Hugging Face Pro = Perfect fit!
Deploy in 3 steps:
- Create Space on huggingface.co/new-space (SDK: Docker)
- Upload project files
- Access at
https://YOUR_USERNAME-participatory-planner.hf.space
Total cost: $0 (included in your HF Pro)
Time to deploy: 5-10 minutes
Maintenance: Zero (auto-managed)
π This is the best free deployment option for your demo!