Star β this repository if VerbaDoc helps you translate documents efficiently!
Transform multilingual PDFs while preserving their exact layout, formatting, and mathematical expressions.
VerbaDoc is a full-stack web application that intelligently detects document layout, extracts text and formulas, translates content using Google Gemini AI, and reconstructs PDFs with selectable textβall while maintaining the original visual structure.
- π― Layout-Aware Translation: Preserves tables, paragraphs, titles, and mathematical formulas
- π§ AI-Powered OCR: Uses Google Gemini 2.0 Flash for accurate text extraction and LaTeX conversion
- π Mathematical Expression Support: Handles complex formulas with XeLaTeX rendering
- π Side-by-Side Viewer: Compare original and translated PDFs in real-time
- β‘ High Performance: Multi-threaded processing with API key load balancing
- π³ Docker Ready: One-command deployment with isolated environments
- π Multi-Language Support: Vietnamese, Chinese, Japanese, Korean, Arabic, and more
| Component | Technology Stack |
|---|---|
| Frontend | React 18 + TypeScript + Vite + Bootstrap 5 + React Router + PDF.js viewer |
| Backend | Python 3.11 + FastAPI + PyMuPDF + DocLayout-YOLO + Google Gemini API + XeLaTeX + Poppler |
| AI Models | DocLayout-YOLO (layout detection) + Google Gemini 2.0 Flash (OCR & translation) |
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β React Client βββββΆβ FastAPI Server βββββΆβ Gemini AI API β
β β β β β β
β β’ File Upload β β β’ Layout Detectionβ β β’ Text Extract β
β β’ PDF Viewer β β β’ OCR Processing β β β’ Translation β
β β’ Side-by-side β β β’ LaTeX Rendering β β β’ Math OCR β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
translate-pdf-app/
βββ translate-pdf-app_BACKEND/ # Python FastAPI server
β βββ core/ # Core processing modules
β β βββ api_manager.py # Multi-API key management
β β βββ detect_layout.py # DocLayout-YOLO integration
β β βββ extract_info.py # OCR & content extraction
β β βββ translate_text.py # Gemini translation
β β βββ render_latex.py # LaTeX PDF generation
β β βββ pdf_utils.py # PDF manipulation utilities
β βββ pipeline.py # Main processing pipeline
β βββ main.py # FastAPI application
β βββ requirements.txt # Python dependencies
β βββ Dockerfile # Backend container config
βββ translate-pdf-app_FRONTEND/ # React TypeScript client
β βββ src/
β β βββ components/ # Reusable UI components
β β βββ pages/ # Application pages
β β β βββ LandingPage.tsx # Home page with features
β β β βββ UploadPage.tsx # PDF upload interface
β β β βββ ViewPage.tsx # Side-by-side PDF viewer
β β βββ main.tsx # Application entry point
β βββ package.json # Node.js dependencies
β βββ Dockerfile # Frontend container config
βββ docker-compose.yml # Multi-service orchestration
βββ README.md # This comprehensive guide
- Docker Desktop 24.0+ (includes Docker Compose v2)
- Git for cloning the repository
- Google Gemini API Keys (get from Google AI Studio)
git clone <your-repository-url>
cd translate-pdf-app
cp translate-pdf-app_BACKEND/.env.example translate-pdf-app_BACKEND/.env
# Edit .env file with your API keys (see configuration section below)
docker compose up --buildπ That's it! Your application will be available at:
| Service | URL | Purpose |
|---|---|---|
| Frontend | http://localhost:5173 | Upload PDFs and view translations |
| Backend | http://localhost:8000 | API endpoints |
| API Docs | http://localhost:8000/docs | Interactive Swagger documentation |
β±οΈ First Launch: Initial build takes ~10-15 minutes due to TeX packages and AI model downloads (~1GB)
# CORS Configuration - Critical for frontend-backend communication
FRONTEND_ORIGIN=http://localhost:5173 # Development frontend URL
FRONTEND_HOST=https://your-production-domain.com # Production frontend URL
# File Storage
UPLOAD_FOLDER=storage # Local storage directory name
# Google Gemini API Keys - Multiple keys for load balancing and rate limit management
GEMINI_API_KEY_0=your_first_api_key_here # Primary API key
GEMINI_API_KEY_1=your_second_api_key_here # Secondary API key (optional)
GEMINI_API_KEY_2=your_third_api_key_here # Tertiary API key (optional)| Variable | Required | Purpose | Example |
|---|---|---|---|
FRONTEND_ORIGIN |
β Yes | Development CORS origin | http://localhost:5173 |
FRONTEND_HOST |
β Yes | Production CORS origin | https://myapp.vercel.app |
UPLOAD_FOLDER |
β No | Storage directory name | storage (default) |
GEMINI_API_KEY_0 |
β Yes | Primary Gemini API key | AIzaSy... |
GEMINI_API_KEY_1 |
β No | Load balancing key #2 | AIzaSy... |
GEMINI_API_KEY_2 |
β No | Load balancing key #3 | AIzaSy... |
π Getting API Keys: Visit Google AI Studio β Create API Key β Copy key value
Create translate-pdf-app_FRONTEND/.env for custom backend URL:
VITE_BACKEND_URL=http://localhost:8000 # Backend API base URLsudo apt update && sudo apt install -y \
texlive-xetex texlive-latex-base texlive-extra-utils \
poppler-utils libgl1 libglib2.0-0 \
build-essential wget curl gitcd translate-pdf-app_BACKEND
# Create virtual environment
python3.11 -m venv .venv
source .venv/bin/activate # Linux/Mac
# or
.venv\Scripts\activate # Windows
# Install dependencies
pip install --upgrade pip
pip install -r requirements.txtpython -c "
from huggingface_hub import hf_hub_download
hf_hub_download(
repo_id='juliozhao/DocLayout-YOLO-DocStructBench',
filename='doclayout_yolo_docstructbench_imgsz1024.pt'
)
print('β
DocLayout-YOLO model downloaded successfully')
"uvicorn main:app --reload --host 0.0.0.0 --port 8000cd translate-pdf-app_FRONTEND
# Install dependencies
npm install
# or
pnpm install
# or
yarn install
# Start development server with hot reload
npm run devDevelopment URLs:
- Frontend: http://localhost:5173 (auto-reload on changes)
- Backend: http://localhost:8000 (auto-reload on changes)
# Production deployment
docker compose -f docker-compose.yml up -d
# Check service health
docker compose ps
docker compose logs -f backendcd translate-pdf-app_BACKEND
docker build -t verbaDoc-backend:latest .
docker run -d \
--name verbaDoc-backend \
-p 8000:8000 \
--env-file .env \
verbaDoc-backend:latestcd translate-pdf-app_FRONTEND
docker build -t verbaDoc-frontend:latest .
docker run -d \
--name verbaDoc-frontend \
-p 80:80 \
verbaDoc-frontend:latest- Connect your GitHub repository
- Set environment variables in dashboard
- Deploy backend as Web Service (port 8000)
- Deploy frontend as Static Site
- Deploy frontend to Vercel
- Deploy backend to Railway
- Update CORS origins in environment variables
- Input: PDF pages converted to high-resolution images (300 DPI)
- Model: DocLayout-YOLO trained on DocStructBench dataset
- Output: Bounding boxes for paragraphs, titles, tables, formulas, figures
- Text Regions: Direct text extraction using PyMuPDF
- Complex Regions: Google Gemini 2.0 Flash OCR with LaTeX conversion
- Mathematical Formulas: Preserved as LaTeX markup
- Engine: Google Gemini 2.0 Flash with specialized prompts
- Features: Context-aware translation, mathematical expression preservation
- Rate Limiting: Intelligent API key rotation and request queuing
- Text: Direct insertion with font matching
- Formulas: XeLaTeX compilation and PDF overlay
- Layout: Exact coordinate-based positioning
| Problem | Symptoms | Solutions |
|---|---|---|
| CORS Errors | Frontend can't reach backend | β’ Check FRONTEND_ORIGIN in .envβ’ Verify URLs match exactly β’ Restart backend service |
| API Key Issues | "No API key available" errors | β’ Verify Gemini API keys are valid β’ Check key quotas in Google Cloud β’ Add more keys for load balancing |
| Build Failures | Docker build timeouts | β’ Increase Docker memory to 4GB+ β’ Use --no-cache flagβ’ Check internet connection |
| Port Conflicts | "Port already in use" | β’ Change ports in docker-compose.ymlβ’ Kill existing processes β’ Use different port mapping |
| Translation Errors | Incomplete or failed translations | β’ Check API key quotas β’ Verify PDF file integrity β’ Check backend logs |
# Check container status
docker compose ps
# View real-time logs
docker compose logs -f backend
docker compose logs -f frontend
# Enter container for debugging
docker compose exec backend bash
docker compose exec frontend sh
# Check API health
curl http://localhost:8000/health
# Test file upload
curl -X POST -F "file=@test.pdf" http://localhost:8000/upload-pdf/# docker-compose.yml
services:
backend:
deploy:
replicas: 3
environment:
- GEMINI_API_KEY_0=key1
- GEMINI_API_KEY_1=key2
- GEMINI_API_KEY_2=key3
# Add more API keys for better rate limiting- Minimum: 4GB RAM for basic operation
- Recommended: 8GB RAM for production
- Storage: 2GB for AI models + user files
- Upload a multi-language PDF with tables and formulas
- Verify layout detection visualization
- Check translation accuracy
- Confirm PDF output maintains formatting
# Health check
curl http://localhost:8000/health
# Upload test
curl -X POST \
-F "file=@sample.pdf" \
http://localhost:8000/upload-pdf/ \
-H "Content-Type: multipart/form-data"- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow TypeScript best practices for frontend
- Use Python type hints for backend
- Add comprehensive error handling
- Update documentation for new features
- DocLayout-YOLO: Document layout detection model
- Google Gemini: AI-powered OCR and translation
- PyMuPDF: PDF processing and manipulation
- React & FastAPI: Modern web framework foundation
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: This README + inline code comments