File size: 4,094 Bytes
4d67ec7 | 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 139 140 141 142 143 144 145 146 | # π Deployment Guide β Railway (Backend) + Vercel (Frontend)
## β οΈ Key Constraint: BERT Model Size
The trained BERT model is **418 MB** (`model.safetensors`).
GitHub blocks files >100MB. We use **Git LFS** to handle this.
---
## PART 1: Setup Git LFS + Push to GitHub
### Step 1 β Install Git LFS
Download and install: https://git-lfs.com
Then in your terminal:
```bash
git lfs install
```
### Step 2 β Track large model file
```bash
cd "d:\Users\Pranil\Github Repos\Question_AndAnswerGeneration"
git lfs track "Classification/checkpoints/best_model/model.safetensors"
git add .gitattributes
```
### Step 3 β Stage and commit everything
```bash
git add .
git commit -m "Add deployment files + BERT model via LFS"
git push origin main
```
> β³ This will take a few minutes β the 418MB file uploads via LFS.
---
## PART 2: Deploy Backend to Railway
### Step 4 β Create Railway account
Go to: https://railway.app
Sign up with **GitHub** account (easiest β auto-imports repos)
### Step 5 β Create new project
1. Click **"New Project"**
2. Choose **"Deploy from GitHub repo"**
3. Select your `Question_AndAnswerGeneration` repo
4. Railway auto-detects Python β click **"Deploy"**
### Step 6 β Set environment variables
In your Railway project β **Variables** tab β add these:
| Variable | Value |
|---|---|
| `SUPABASE_URL` | `https://your-project.supabase.co` |
| `SUPABASE_KEY` | `your-supabase-anon-key` |
| `GROQ_API_KEY` | `your-groq-api-key` |
| `GROQ_MODEL` | `llama-3.3-70b-versatile` |
| `EMBEDDING_MODEL` | `BAAI/bge-small-en-v1.5` |
### Step 7 β Get your backend URL
After deployment completes (3β8 mins):
Go to **Settings β Domains** β Copy your URL
It looks like: `https://question-andanswer-production.up.railway.app`
### Step 8 β Verify backend is live
Open in browser:
```
https://YOUR-RAILWAY-URL.up.railway.app/health
https://YOUR-RAILWAY-URL.up.railway.app/docs
```
---
## PART 3: Update Frontend with Backend URL
### Step 9 β Update API_BASE in app.js
Open `Frontend/app.js` and change line 14:
```javascript
// Before (local):
const API_BASE = "http://localhost:8000";
// After (production):
const API_BASE = "https://YOUR-RAILWAY-URL.up.railway.app";
```
### Step 10 β Commit the frontend update
```bash
git add Frontend/app.js
git commit -m "Update API_BASE to Railway URL"
git push origin main
```
---
## PART 4: Deploy Frontend to Vercel
### Step 11 β Create Vercel account
Go to: https://vercel.com
Sign up with **GitHub** account
### Step 12 β Import project
1. Click **"New Project"**
2. Import your `Question_AndAnswerGeneration` repo
3. In **"Configure Project"**:
- **Root Directory**: `Frontend`
- **Framework Preset**: `Other` (it's vanilla HTML)
- Leave everything else default
4. Click **"Deploy"**
### Step 13 β Get your frontend URL
Vercel gives you: `https://question-andanswer.vercel.app`
---
## β
Final Test
1. Open your Vercel URL
2. Type a question: *"What is the role of cofactors in enzyme activity?"*
3. Click **π¬ Full Analysis**
4. Should classify β retrieve β answer in ~10 seconds
---
## π§ Troubleshooting
| Problem | Fix |
|---|---|
| Railway deploy fails | Check **Deploy Logs** in Railway dashboard |
| BERT model not found | Confirm `model.safetensors` was pushed via Git LFS |
| CORS error in browser | Verify Railway URL in `API_BASE` has no trailing slash |
| Supabase timeout | Check your Supabase project is not paused (free tier pauses after inactivity) |
| Railway out of memory | Upgrade to Hobby plan ($5/mo) β BERT needs ~1.5GB RAM |
---
## π° Cost Summary
| Service | Free Tier | Paid |
|---|---|---|
| **Railway** | 500MB RAM, limited hours | $5/mo Hobby |
| **Vercel** | Unlimited static hosting | Free |
| **Supabase** | 500MB DB, 2GB bandwidth | $25/mo Pro |
| **Groq** | Free tier (limited RPM) | Pay-per-use |
| **Git LFS** | 1GB free | $5/mo per 50GB |
> π‘ For a student project / demo: everything fits in free tiers.
> Railway free tier may sleep after inactivity (cold start ~30s on first request).
|