Spaces:
Sleeping
Sleeping
File size: 3,060 Bytes
92db116 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# π QUICK DEPLOYMENT GUIDE
## β
Files Changed (Production-Ready)
1. β
**requirements.txt** - Added `psycopg2-binary`, `gunicorn`
2. β
**app/database.py** - Hybrid SQLite/PostgreSQL support with Render URL fix
3. β
**app/config.py** - Environment variable support for `SECRET_KEY`
4. β
**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
```bash
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:
```bash
# 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
1. **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
2. **ML Model Optimization:**
- Consider lazy loading (load on first request)
- Use CPU-optimized PyTorch
- Cache predictions if possible
3. **Static Files:**
- Uploads are ephemeral on Render Free Tier
- WordClouds will be deleted on container restart
- Use cloud storage (S3, Cloudinary) for production
4. **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!**
|