livetranslator / DEPLOY.md
mohrashid's picture
Upload 49 files
42d1288 verified

Deploy Guide: Render (Backend) + Vercel (Frontend)

A complete, copy-paste guide to launch this project using free tiers.

  • Frontend: React + Vite → Vercel (static site)
  • Backend: FastAPI + Transformers → Render (free web service)

1) Prerequisites

Optional (local dev): Node.js 18+, Python 3.11 or 3.13


2) Local run (optional)

# Python env
python3 -m venv .venv
source .venv/bin/activate
pip install -r server/requirements.txt

# Frontend deps
npm install

# Start both (Vite + FastAPI)
npm run dev:all
# Vite: http://localhost:5174
# API:  http://127.0.0.1:8000  (GET /health)

Tip: In Host view, click "Preload Model" once to warm the translator.


3) Backend on Render (Free)

Render builds and hosts the FastAPI app. Free plan sleeps when idle; next request wakes it.

Two choices:

A) Blueprint (recommended)

This repo includes render.yaml and runtime.txt.

  1. Render → New → Blueprint → Connect repo → choose updated-translator → Apply
  2. Wait for deploy. First translation may take longer while weights download.

What it sets:

  • Build: pip install -r server/requirements.txt
  • Start: uvicorn server.app:app --host 0.0.0.0 --port $PORT
  • Health Check: /health
  • Python: 3.11.9 (via runtime.txt)

B) Manual Web Service

  1. New → Web Service → connect repo → Branch main
  2. Root: . | Runtime: Python
  3. Build:
    pip install -r server/requirements.txt
    
  4. Start:
    uvicorn server.app:app --host 0.0.0.0 --port $PORT
    
  5. Health Check Path: /health | Plan: Free

After deploy, test:

curl -sS https://<service>.onrender.com/health
# -> {"status":"ok"}

Notes:

  • Cold start: free services sleep when idle; first request wakes them.
  • First translation after deploy may download model weights; subsequent calls are fast.

4) Frontend on Vercel (Free)

  1. New Project → Import GitHub → updated-translator
  2. Framework: Vite
  3. Build Command: npm run build | Output: dist
  4. Environment Variables:
    • VITE_API_URL = https://<service>.onrender.com
  5. Deploy. Open your Vercel URL (e.g., https://updated-translator.vercel.app).

5) Troubleshooting

  • Tokenizers/torch build errors on Render

    • Keep Python 3.11 (runtime.txt). server/requirements.txt pins versions with prebuilt wheels.
  • 502/timeout on first call

    • Likely cold start / first-time model download. Wait, then retry. Use “Preload Model”.
  • CORS errors

    • server/app.py enables permissive CORS for demo. If you tighten it, add your Vercel domain.
  • Speech recording not working

    • Some browsers don’t support Web Speech API. Use Manual Input fallback.
  • Duplicate translation shown

    • App suppresses translations equal to the original and avoids saving duplicates.

6) Optional: Single-service Docker on Render (frontend + API + Whisper)

If you prefer one Render service that serves both the UI and the API (and enables Whisper STT), switch to the Docker blueprint:

  1. Ensure your Render blueprint render.yaml has:
services:
  - type: web
    name: updated-translator
    env: docker
    dockerfilePath: ./Dockerfile
    healthCheckPath: /api/health
    envVars:
      - key: STT_ENABLED
        value: "1"
      - key: WHISPER_MODEL
        value: "tiny"
  1. Deploy via Render → New → Blueprint → select repo.

  2. Verify:

curl -sS https://<service>.onrender.com/api/health
curl -sS https://<service>.onrender.com/api/provider

Frontend will call same-origin /api/* automatically. Upload control for audio appears when STT is available.


7) Useful endpoints

  • GET /api/health{ "status": "ok" }
  • POST /api/translate
    • Body: { "text": "...", "source_language": "ur", "target_language": "en" }
    • Response: { "translated_text": "..." }
  • POST /api/preload
    • Body: { "source_language": "ur", "target_language": "en" }
    • Response: { "ok": true, "model": "Helsinki-NLP/opus-mt-ur-en" }

That’s it—Render for the API, Vercel for the UI, both on free plans. If you prefer Hugging Face Spaces for the backend, I can add a Dockerfile-based Space setup as well.