Spaces:
Sleeping
Sleeping
π QUICK DEPLOYMENT GUIDE
β Files Changed (Production-Ready)
- β
requirements.txt - Added
psycopg2-binary,gunicorn - β app/database.py - Hybrid SQLite/PostgreSQL support with Render URL fix
- β
app/config.py - Environment variable support for
SECRET_KEY - β main.py - Auto-migration, production settings
π Render Configuration
Web Service Settings
Name: vietnamese-rating-prediction
Runtime: Python 3
Build Command: pip install -r requirements.txt
Start Command: gunicorn main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:$PORT
Environment Variables (Required)
SECRET_KEY = <generate-with-openssl-rand-hex-32>
PYTHON_VERSION = 3.11.0
PostgreSQL Database
Name: vietnamese-rating-db
PostgreSQL Version: 15
Instance Type: Free
Link database to web service - DATABASE_URL will be auto-populated.
π― Deployment Steps
1. Push to GitHub
git add .
git commit -m "Deploy to Render"
git push origin master
2. Create Render Web Service
- Go to https://dashboard.render.com/
- New β Web Service
- Connect GitHub repo
- Use settings above
3. Create PostgreSQL Database
- New β PostgreSQL
- Use free tier
- Link to web service
4. Deploy
- Click "Manual Deploy"
- Watch logs for success
5. Test
https://your-app.onrender.com/health
https://your-app.onrender.com/docs
https://your-app.onrender.com/dashboard
π§ Local Testing Before Deploy
Test hybrid database locally:
# Test with SQLite (no DATABASE_URL)
python main.py
# Test with PostgreSQL (set DATABASE_URL)
export DATABASE_URL=postgresql://user:pass@localhost/dbname
python main.py
Expected output:
π§ Development Mode: Using SQLite
# OR
π Production Mode: Using PostgreSQL
π Creating database tables...
β
Database tables created successfully!
β οΈ Important Notes
Render Free Tier Limitations:
- App sleeps after 15 minutes of inactivity (first request takes 30-60s)
- 512MB RAM (may need optimization for ML model)
- 1GB PostgreSQL storage
ML Model Optimization:
- Consider lazy loading (load on first request)
- Use CPU-optimized PyTorch
- Cache predictions if possible
Static Files:
- Uploads are ephemeral on Render Free Tier
- WordClouds will be deleted on container restart
- Use cloud storage (S3, Cloudinary) for production
Database:
- SQLite NOT recommended for production (file locking issues)
- PostgreSQL required for concurrent requests
- Free tier: 1GB storage, 97 connections
π Common Issues
"Module not found"
β Run pip install -r requirements.txt locally first
"Port binding error"
β Use $PORT in start command (auto-set by Render)
"Database connection failed"
β Check DATABASE_URL in environment variables
"Model loading timeout"
β Free tier has 512MB RAM limit, optimize model or upgrade
Read DEPLOYMENT.md for detailed guide!