Translation_app_ / docs /DEPLOYMENT_GUIDE.md
Athena1621's picture
feat: Implement Multi-Lingual Product Catalog Translator frontend with Streamlit
67f25fb

A newer version of the Streamlit SDK is available: 1.53.1

Upgrade

πŸš€ Multi-Lingual Catalog Translator - Deployment Guide

πŸ“‹ Pre-Deployment Checklist

βœ… Current Status Verification

  • Real IndicTrans2 models working
  • Backend API running on port 8001
  • Frontend running on port 8501
  • Database properly initialized
  • Language mapping working correctly

βœ… Required Files Check

  • Backend requirements.txt
  • Frontend requirements.txt
  • Environment configuration (.env)
  • IndicTrans2 models downloaded
  • Database schema ready

🎯 Deployment Options (Choose Your Level)

🟒 Option 1: Quick Demo Deployment (5 minutes)

Perfect for interviews and quick demos

🟑 Option 2: Docker Deployment (15 minutes)

Professional containerized deployment

πŸ”΄ Option 3: Cloud Production Deployment (30+ minutes)

Full production-ready deployment


🟒 Option 1: Quick Demo Deployment

Step 1: Create Startup Scripts

Windows (startup.bat):

@echo off
echo Starting Multi-Lingual Catalog Translator...

echo Starting Backend...
start "Backend" cmd /k "cd backend && uvicorn main:app --host 0.0.0.0 --port 8001"

echo Waiting for backend to start...
timeout /t 5

echo Starting Frontend...
start "Frontend" cmd /k "cd frontend && streamlit run app.py --server.port 8501"

echo.
echo βœ… Deployment Complete!
echo.
echo πŸ”— Frontend: http://localhost:8501
echo πŸ”— Backend API: http://localhost:8001
echo πŸ”— API Docs: http://localhost:8001/docs
echo.
echo Press any key to stop all services...
pause
taskkill /f /im python.exe

Linux/Mac (startup.sh):

#!/bin/bash
echo "Starting Multi-Lingual Catalog Translator..."

# Start backend in background
echo "Starting Backend..."
cd backend
uvicorn main:app --host 0.0.0.0 --port 8001 &
BACKEND_PID=$!

# Wait for backend to start
sleep 5

# Start frontend
echo "Starting Frontend..."
cd ../frontend
streamlit run app.py --server.port 8501 &
FRONTEND_PID=$!

echo ""
echo "βœ… Deployment Complete!"
echo ""
echo "πŸ”— Frontend: http://localhost:8501"
echo "πŸ”— Backend API: http://localhost:8001"
echo "πŸ”— API Docs: http://localhost:8001/docs"
echo ""
echo "Press Ctrl+C to stop all services..."

# Wait for interrupt
trap "kill $BACKEND_PID $FRONTEND_PID" EXIT
wait

Step 2: Environment Setup

# Create production environment file
cp .env .env.production

# Update for production
echo "MODEL_TYPE=indictrans2" >> .env.production
echo "MODEL_PATH=models/indictrans2" >> .env.production
echo "DEVICE=cpu" >> .env.production
echo "DATABASE_PATH=data/translations.db" >> .env.production

Step 3: Quick Start

# Make script executable (Linux/Mac)
chmod +x startup.sh
./startup.sh

# Or run directly (Windows)
startup.bat

🟑 Option 2: Docker Deployment

Step 1: Create Dockerfiles

Backend Dockerfile:

# backend/Dockerfile
FROM python:3.11-slim

# Set working directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

# Create data directory
RUN mkdir -p /app/data

# Expose port
EXPOSE 8001

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s \
  CMD curl -f http://localhost:8001/ || exit 1

# Start application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8001"]

Frontend Dockerfile:

# frontend/Dockerfile
FROM python:3.11-slim

# Set working directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

# Expose port
EXPOSE 8501

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s \
  CMD curl -f http://localhost:8501/_stcore/health || exit 1

# Start application
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]

Step 2: Docker Compose

# docker-compose.yml
version: '3.8'

services:
  backend:
    build: 
      context: ./backend
      dockerfile: Dockerfile
    ports:
      - "8001:8001"
    volumes:
      - ./models:/app/models
      - ./data:/app/data
      - ./.env:/app/.env
    environment:
      - MODEL_TYPE=indictrans2
      - MODEL_PATH=models/indictrans2
      - DEVICE=cpu
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8001/"]
      interval: 30s
      timeout: 10s
      retries: 3
    restart: unless-stopped

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    ports:
      - "8501:8501"
    depends_on:
      backend:
        condition: service_healthy
    environment:
      - API_BASE_URL=http://backend:8001
    restart: unless-stopped

  # Optional: Add database service
  # postgres:
  #   image: postgres:15
  #   environment:
  #     POSTGRES_DB: translations
  #     POSTGRES_USER: translator
  #     POSTGRES_PASSWORD: secure_password
  #   volumes:
  #     - postgres_data:/var/lib/postgresql/data
  #   ports:
  #     - "5432:5432"

volumes:
  postgres_data:

networks:
  default:
    name: translator_network

Step 3: Build and Deploy

# Build and start services
docker-compose up --build

# Run in background
docker-compose up -d --build

# View logs
docker-compose logs -f

# Stop services
docker-compose down

πŸ”΄ Option 3: Cloud Production Deployment

πŸ”΅ 3A: AWS Deployment

Prerequisites

# Install AWS CLI
pip install awscli

# Configure AWS
aws configure

ECS Deployment

# Create ECR repositories
aws ecr create-repository --repository-name translator-backend
aws ecr create-repository --repository-name translator-frontend

# Get login token
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin <account-id>.dkr.ecr.us-west-2.amazonaws.com

# Build and push images
docker build -t translator-backend ./backend
docker tag translator-backend:latest <account-id>.dkr.ecr.us-west-2.amazonaws.com/translator-backend:latest
docker push <account-id>.dkr.ecr.us-west-2.amazonaws.com/translator-backend:latest

docker build -t translator-frontend ./frontend
docker tag translator-frontend:latest <account-id>.dkr.ecr.us-west-2.amazonaws.com/translator-frontend:latest
docker push <account-id>.dkr.ecr.us-west-2.amazonaws.com/translator-frontend:latest

πŸ”΅ 3B: Google Cloud Platform Deployment

Cloud Run Deployment

# Install gcloud CLI
curl https://sdk.cloud.google.com | bash

# Login and set project
gcloud auth login
gcloud config set project YOUR_PROJECT_ID

# Build and deploy backend
gcloud run deploy translator-backend \
  --source ./backend \
  --platform managed \
  --region us-central1 \
  --allow-unauthenticated \
  --memory 2Gi \
  --cpu 2 \
  --max-instances 10

# Build and deploy frontend
gcloud run deploy translator-frontend \
  --source ./frontend \
  --platform managed \
  --region us-central1 \
  --allow-unauthenticated \
  --memory 1Gi \
  --cpu 1 \
  --max-instances 5

πŸ”΅ 3C: Heroku Deployment

Backend Deployment

# Install Heroku CLI
# Create Procfile for backend
echo "web: uvicorn main:app --host 0.0.0.0 --port \$PORT" > backend/Procfile

# Create Heroku app
heroku create translator-backend-app

# Add Python buildpack
heroku buildpacks:set heroku/python -a translator-backend-app

# Set environment variables
heroku config:set MODEL_TYPE=indictrans2 -a translator-backend-app
heroku config:set MODEL_PATH=models/indictrans2 -a translator-backend-app

# Deploy
cd backend
git init
git add .
git commit -m "Initial commit"
heroku git:remote -a translator-backend-app
git push heroku main

Frontend Deployment

# Create Procfile for frontend
echo "web: streamlit run app.py --server.port \$PORT --server.address 0.0.0.0" > frontend/Procfile

# Create Heroku app
heroku create translator-frontend-app

# Deploy
cd frontend
git init
git add .
git commit -m "Initial commit"
heroku git:remote -a translator-frontend-app
git push heroku main

πŸ› οΈ Production Optimizations

1. Environment Configuration

# .env.production
MODEL_TYPE=indictrans2
MODEL_PATH=/app/models/indictrans2
DEVICE=cpu
DATABASE_URL=postgresql://user:pass@localhost/translations
REDIS_URL=redis://localhost:6379
LOG_LEVEL=INFO
DEBUG=False
CORS_ORIGINS=["https://yourdomain.com"]

2. Nginx Configuration

# nginx.conf
upstream backend {
    server backend:8001;
}

upstream frontend {
    server frontend:8501;
}

server {
    listen 80;
    server_name yourdomain.com;

    location /api/ {
        proxy_pass http://backend/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location / {
        proxy_pass http://frontend/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

3. Database Migration

# migrations/001_initial.py
def upgrade():
    """Create initial tables"""
    # Add database migration logic here
    pass

def downgrade():
    """Remove initial tables"""
    # Add rollback logic here
    pass

πŸ“Š Monitoring & Maintenance

Health Checks

# Check backend health
curl http://localhost:8001/

# Check frontend health
curl http://localhost:8501/_stcore/health

# Check model loading
curl http://localhost:8001/supported-languages

Log Management

# View Docker logs
docker-compose logs -f backend
docker-compose logs -f frontend

# Save logs to file
docker-compose logs > deployment.log

Performance Monitoring

# Add to backend/main.py
import time
from fastapi import Request

@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
    start_time = time.time()
    response = await call_next(request)
    process_time = time.time() - start_time
    response.headers["X-Process-Time"] = str(process_time)
    return response

🎯 Recommended Deployment Path

For Interview Demo:

  1. Start with Option 1 (Quick Demo) - Shows it works end-to-end
  2. Mention Option 2 (Docker) - Shows production awareness
  3. Discuss Option 3 (Cloud) - Shows scalability thinking

For Production:

  1. Use Option 2 (Docker) for consistent environments
  2. Add monitoring and logging
  3. Set up CI/CD pipeline
  4. Implement proper security measures

πŸš€ Next Steps After Deployment

  1. Performance Testing - Load test the APIs
  2. Security Audit - Check for vulnerabilities
  3. Backup Strategy - Database and model backups
  4. Monitoring Setup - Alerts and dashboards
  5. Documentation - API docs and user guides

Would you like me to help you with any specific deployment option?