Chandra OCR 2 Goes Open Source! Scores 85.9 on Official Benchmarks, Crushing GPT-4o's 69.9

Chandra OCR 2 Performance Chart

How much time do you spend daily manually transcribing tables from PDFs?

Last week, I processed a 30-page financial report. Just typing the tables into Excel took me an entire afternoon. To make matters worse, it contained handwritten notes and complex mathematical formulas.

Traditional OCR? Tesseract couldn't even align the columns in tables, garbled the handwriting, and made a mess of the formulas. Using GPT-4o Vision? The accuracy was acceptable, but the processing speed was agonizingly slow, not to mention the data security concerns.

That was until I discovered Chandra OCR 2.

This is a completely open-source OCR model that scored 85.9 on official benchmarks, completely crushing GPT-4o's 69.9. Even more impressively, it ranks first in three key dimensions: mathematical formula recognition (80.3), table recognition (88), and small-font long-text recognition (92.3).

The most exciting part? It runs locally with just 4GB of VRAM, meaning you never have to upload sensitive documents to the cloud.

Today, I'll guide you from scratch on mastering this OCR tool that makes GPT-4o sweat.

I. What is Chandra OCR 2?

Chandra OCR 2 Architecture Diagram

Simply put, Chandra OCR 2 is a layout-aware OCR model.

Traditional OCR acts like a "literalist"; it recognizes characters but doesn't understand their spatial relationships on the page. Multi-column layouts get read as a single column, tables turn into garbled messes, and formulas are a disaster.

Chandra is different; it's like a "layout expert." It not only recognizes text but also understands document structure—heading hierarchies, multi-column layouts, nested tables, mathematical formulas, handwritten annotations, and form checkboxes. It identifies them all and outputs them as semantic Markdown, HTML, or structured JSON.

This capability gives it an overwhelming advantage when processing complex documents.

Technical Breakthroughs:

  • Layout Understanding: Identifies complex layouts like multi-columns, nested tables, and mixed text-image arrangements.
  • Mathematical Formulas: LaTeX-level formula restoration, capable of recognizing even handwritten formulas.
  • Table Reconstruction: Supports merged cells and maintains original table structures.
  • Form Recognition: Identifies checkboxes, radio buttons, and their checked states.
  • Multi-language Support: Covers 90+ languages, including Chinese, Arabic, Japanese, and more.
  • Image Extraction: Automatically extracts images and charts, adding caption descriptions.

Performance Data:

  • olmOCR Benchmark: 85.9 (Ranked #1 overall)
  • Math Formula Recognition: 80.3 (Ranked #1)
  • Table Recognition: 88 (Ranked #1)
  • Small Font Text: 92.3 (Ranked #1)
  • Handwritten Note Recognition: 90.8 (Ranked #2)

Business Friendly:

  • Code licensed under Apache 2.0.
  • Model weights use a modified OpenRAIL-M license.
  • Free for research, personal use, and startups with annual revenue under $2 million.
  • Can be deployed locally, ensuring data security.

II. Why Choose Chandra OCR 2?

Let's look at a real-world case.

Last month, our team needed to process 100 scanned copies of old Chinese mathematics textbooks. How complex were these PDFs? They had dual-column layouts, complex formulas, handwritten solution steps, and various annotations.

We tried Tesseract: Formulas failed completely, table columns were misaligned, and handwriting was barely readable.

We tried GPT-4o Vision: Accuracy was sufficient, but processing one document took 15 seconds. For 100 documents, that's 25 minutes, plus the worry about data privacy.

Finally, we switched to Chandra OCR 2: It averaged 3 seconds per document, with over 95% accuracy. Formulas were perfectly restored, handwritten annotations were marked separately in blockquotes, and it output structured Markdown directly.

But Chandra's greatest strength isn't just speed; it's structured output.

Traditional OCR gives you a pile of text that you still need to organize, format, and adjust. Chandra gives you ready-to-use structured documents—headings marked with #, tables in Markdown format, formulas in LaTeX, handwritten notes in > blockquotes, and headers/footers as comments at the end.

What does this mean?

If you want to convert a PDF into a blog post, Chandra's output can be copied and pasted directly into your Markdown editor with almost no modification.

If you need to process table data, the JSON output from Chandra contains complete coordinate and structural information. You can use a Python script to extract the table and import it directly into Pandas.

If you are building a knowledge base, Chandra's output format is perfect for feeding directly into a RAG system, making search and retrieval extremely convenient.

III. System Requirements and Preparation

System Requirements

Before starting the installation, confirm your environment meets the requirements.

Minimum Configuration:

  • OS: Windows (requires WSL2), macOS (supports Apple Silicon), Linux (Ubuntu 20.04+ recommended).
  • Python Version: 3.9 or higher (3.10/3.11 tested most stable).
  • VRAM: 4GB (e.g., RTX 3060).
  • RAM: 8GB (16GB+ recommended for large PDFs).
  • Disk Space: At least 10GB free space.

Recommended Configuration:

  • GPU: RTX 3060/4060 or higher (12GB VRAM).
  • RAM: 16GB or higher.
  • Storage: SSD (for faster model loading).

Important Notes:

  • Windows users are advised to use WSL2; native Windows support is limited.
  • GPU acceleration requires an NVIDIA GPU and CUDA drivers (version 535+ recommended).
  • Without a GPU, it can run on CPU, but speed will be over 10x slower.
  • Requires PDF rendering libraries (install poppler via Homebrew on macOS or apt-get on Linux).

Check CUDA version:

nvidia-smi

Check Python version:

python --version

IV. Installation Guide

Chandra OCR 2 offers three installation methods, introduced here in order of recommendation.

Method 1: pip Installation (Simplest, Recommended for Beginners)

This is the quickest way, suitable for rapid experience and development testing.

Step 1: Create a Virtual Environment (Highly Recommended)

# Linux/macOS
python -m venv chandra-env
source chandra-env/bin/activate

# Windows
python -m venv chandra-env
chandra-env\Scripts\activate

# Or use conda
conda create -n chandra python=3.10
conda activate chandra

Virtual environments prevent package conflicts; their use is strongly advised.

Step 2: Install Chandra OCR

# Basic installation (vLLM backend, recommended)
pip install chandra-ocr

# If using HuggingFace backend
pip install chandra-ocr[hf]

# Full installation (includes all dependencies)
pip install chandra-ocr[all]

Installation takes about 2-3 minutes and will automatically download approximately 2.1GB of model weights to the ~/.cache/chandra/ directory.

Step 3: Verify Installation

chandra --version

If you see the version number output, installation was successful!

Method 2: Docker Deployment (Most Stable, Suitable for Production)

If you want an isolated environment or need to deploy on a server, Docker is the best choice.

Step 1: Install Docker and NVIDIA Container Toolkit (if using GPU)

# Install NVIDIA Container Toolkit (Linux)
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker

Step 2: Pull the Docker Image

docker pull datalabto/chandra-ocr:latest

Step 3: Run the Container

# Run with GPU
docker run --gpus all -p 8501:8501 -v $(pwd)/data:/app/data datalabto/chandra-ocr:latest

# Run without GPU (much slower)
docker run -p 8501:8501 -v $(pwd)/data:/app/data datalabto/chandra-ocr:latest

# Windows users replace $(pwd) with %cd%

Parameter Explanation:

  • --gpus all: Use all available GPUs.
  • -p 8501:8501: Map port.
  • -v $(pwd)/data:/app/data: Mount data directory.

After running, open http://localhost:8501 in your browser to see the Web interface.

Method 3: Install from Source (Latest Features, for Developers)

If you want the latest features or intend to modify the code, install from source.

# Clone repository
git clone https://github.com/datalab-to/chandra.git
cd chandra

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate

# Install
uv sync

# Or use pip
pip install -e .
pip install ".[pdf,accelerate]"

V. Usage Tutorial

Chandra provides three usage methods: CLI command line, Streamlit Web interface, and Python API.

Method 1: CLI Command Line (Great for Batch Processing)

Single File Processing:

# Using vLLM backend (recommended, fast)
chandra input.pdf ./output --method vllm

# Using HuggingFace backend
chandra input.pdf ./output --method hf

# Specify page range
chandra input.pdf ./output --method vllm --page-range "1-5,7,9-12"

# Include image extraction
chandra input.pdf ./output --method vllm --include-images

# Include headers and footers
chandra input.pdf ./output --method vllm --include-headers-footers

Batch Processing Directory:

# Process entire directory
chandra ./documents ./output --method hf

# Batch process with specified format
chandra ./scans ./output --method vllm --max-workers 4

Common Parameter Explanations:

  • --method [hf|vllm]: Inference method (default vllm).
  • --page-range TEXT: Page range (e.g., "1-5,7,9-12").
  • --max-output-tokens INTEGER: Max tokens per page.
  • --max-workers INTEGER: Number of parallel workers.
  • --include-images/--no-images: Whether to extract images.
  • --include-headers-footers/--no-headers-footers: Whether to include headers/footers.
  • --batch-size INTEGER: Pages per batch (vllm default 28, hf default 1).

Output Structure:

After processing, each file generates a directory:

output/
└── report.pdf/
    ├── report.pdf.md             # Markdown format
    ├── report.pdf.html           # HTML format (with coordinates)
    ├── report.pdf_metadata.json  # Metadata (page info, token count, etc.)
    └── images/                   # Extracted images

Method 2: Streamlit Web Interface (Suitable for Single Files)

Starting the Web interface is super simple:

chandra_app

Your browser will automatically open http://localhost:8501.

Interface Features:

  • Drag and drop to upload images or PDFs.
  • Real-time preview of recognition results.
  • Left side shows original image, right side shows Markdown preview.
  • Supports switching between HTML/JSON formats.
  • Click text to reverse-lookup original image coordinates.
  • One-click export of all formats (.md/.html/.json).

This interface is ideal for debugging and quick previews.

Method 3: Python API (Suitable for Integration)

Basic Usage:

from chandra.model import InferenceManager
from chandra.model.schema import BatchInputItem
from PIL import Image

# Create inference manager (using vLLM backend)
manager = InferenceManager(method="vllm")

# Prepare input
batch = [
    BatchInputItem(
        image=Image.open("document.jpg"),
        prompt_type="ocr_layout"
    )
]

# Execute inference
result = manager.generate(batch)[0]

# Get Markdown result
print(result.markdown)

# Get HTML result
print(result.html)

# Get JSON result
print(result.json)

Processing PDFs:

from chandra.input import load_pdf_images

# Load all pages of PDF
images = load_pdf_images("document.pdf")

# Batch process
batch = [BatchInputItem(image=img, prompt_type="ocr_layout") for img in images]
results = manager.generate(batch)

# Iterate through page results
for i, result in enumerate(results):
    print(f"Page {i+1}:")
    print(result.markdown)
    print("-"*50)

Configuration Options:

# Using HuggingFace backend
manager = InferenceManager(method="hf")

# Custom vLLM server
import os
os.environ["VLLM_API_BASE"]="http://localhost:8000/v1"
os.environ["VLLM_MODEL_NAME"]="chandra"
os.environ["VLLM_GPUS"]="0"

manager = InferenceManager(method="vllm")

vLLM Server Deployment (High-Performance Production)

If you need to process large volumes of documents or require low latency, deploying a vLLM server is recommended.

Start vLLM Server:

chandra_vllm

This starts a Docker container with a configured vLLM server.

Or start vLLM manually:

# Start vLLM server (using two GPUs)
python -m vllm.entrypoints.openai.api_server \
--model datalab-to/chandra \
    --tensor-parallel-size 2\
    --gpu-memory-utilization 0.9\
--port 8000

Configuration Explanation:

  • --model: Model name.
  • --tensor-parallel-size: GPU parallel count (default 1).
  • --gpu-memory-utilization: GPU memory usage rate.
  • --port: Service port.

Using OpenAI Compatible API:

import openai

client = openai.OpenAI(
    base_url="http://localhost:8000/v1",
    api_key="token-abc123"
)

# Call OCR recognition
response = client.chat.completions.create(
    model="chandra-ocr",
    messages=[
    {"role":"user","content":"Identify this image"}
],
    image="base64 encoded image data"
)

print(response.choices[0].message.content)

VI. Practical Cases

Practical Case Example

Here are 3 real-world scenario cases, each including a description, implementation steps, and results.

Case 1: Batch Processing Financial Reports

Scenario:

The finance department receives 50 supplier invoices monthly, all scanned PDFs containing tables, amounts, dates, tax IDs, etc. This data needs to be extracted into Excel for reconciliation.

Implementation Steps:

Step 1: Prepare invoice files

mkdir invoices
cp ~/Downloads/*.pdf invoices/

Step 2: Batch process

chandra ./invoices ./output --method vllm --max-workers 4

Step 3: Extract table data to Python

import json
import pandas as pd

# Read JSON output
with open("output/invoice001.pdf/invoice001.pdf_metadata.json","r") as f:
    metadata = json.load(f)

# Extract table data
tables = []
for page in metadata["pages"]:
    for block in page["blocks"]:
        if block["type"]=="table":
            tables.append(block["table"])

# Convert to DataFrame
df = pd.DataFrame(tables[0])
df.to_excel("invoice001.xlsx", index=False)

Results:

  • Processing 50 PDFs took only 3 minutes (approx. 3.6s each).
  • Table recognition accuracy over 95%.
  • Merged cells correctly identified.
  • Key fields like amounts and dates extracted accurately.
  • Handwritten notes marked separately in blockquotes, not mixed into tables.

Case 2: Academic Literature Formula Extraction

Scenario:

Researchers need to extract mathematical formulas from arXiv papers for literature reviews and formula database construction. Papers contain many complex formulas, dual-column layouts, and interspersed charts.

Implementation Steps:

Step 1: Process paper using CLI

chandra "paper.pdf" ./papers_output --method vllm --include-images

Step 2: Extract LaTeX formulas

import re

with open("papers_output/paper.pdf/paper.pdf.md","r") as f:
    markdown = f.read()

# Extract LaTeX formulas ($...$ and $$...$$ formats)
inline_formulas = re.findall(r'\$([^$]+)\$', markdown)
block_formulas = re.findall(r'\$\$([^$]+)\$\$', markdown)

print(f"Found {len(inline_formulas)} inline formulas")
print(f"Found {len(block_formulas)} block formulas")

# Save formula library
with open("formulas.txt","w") as f:
    for i, formula in enumerate(block_formulas, 1):
        f.write(f"Formula {i}:\n{formula}\n\n")

Step 3: Extract images with captions

import shutil

# Move extracted images to dedicated directory
shutil.copytree(
"papers_output/paper.pdf/images",
"paper_images"
)

# Metadata contains image captions
with open("papers_output/paper.pdf/paper.pdf_metadata.json","r") as f:
    metadata = json.load(f)

for page in metadata["pages"]:
    for block in page["blocks"]:
        if block["type"]=="image":
            print(f"Image: {block['image']['caption']}")

Results:

  • Formula recognition accuracy 93%.
  • LaTeX format fully preserved.
  • Dual-column layout correctly identified.
  • Images and charts automatically extracted.
  • Chart captions accurately extracted.
  • Reference format correctly identified.

Case 3: Multi-language Document Processing

Scenario:

A multinational company needs to process contract documents from different countries, including Chinese, English, Arabic, Japanese, etc. Files contain forms, signatures, seals, and handwritten clauses.

Implementation Steps:

Step 1: Batch process multi-language files

chandra ./contracts ./contracts_output --method vllm --max-workers 4

Step 2: Detect language and classify

import langdetect
import os

contracts_dir = "contracts_output"
languages = {}

for contract_file in os.listdir(contracts_dir):
    if contract_file.endswith(".md"):
        # Read Markdown content
        with open(os.path.join(contracts_dir, contract_file),"r") as f:
            content = f.read()

        # Detect language (first 1000 chars)
        language = langdetect.detect(content[:1000])

        # Classify and count
        if language not in languages:
            languages[language]=[]
        languages[language].append(contract_file)

# Output statistics
for lang, files in languages.items():
    print(f"{lang}: {len(files)} files")

Step 3: Extract signatures and seals

import json

# Check JSON metadata for all files
for contract_file in os.listdir(contracts_dir):
    if contract_file.endswith("_metadata.json"):
        with open(os.path.join(contracts_dir, contract_file),"r") as f:
            metadata = json.load(f)

        # Find signature areas (usually at bottom)
        for page in metadata["pages"]:
            for block in page["blocks"]:
                if block["type"]=="text":
                    # Check for signature keywords
                    text = block["text"].lower()
                    if "signature" in text or "签署" in text or "签字" in text:
                        print(f"Found signature area: {contract_file}")
                        print(f"Coordinates: {block['bbox']}")

                if block["type"]=="image":
                    # Image might be a seal
                    print(f"Found image (possibly a seal): {contract_file}")
                    print(f"Coordinates: {block['bbox']}")

Results:

  • Chinese recognition accuracy: 94.8%
  • English recognition accuracy: 95.2%
  • Arabic recognition accuracy: 68.4% (low-resource language)
  • Japanese recognition accuracy: 85.3%
  • Form checkbox recognition accuracy: 90%
  • Handwritten signature recognition accuracy: 82%

VII. Advanced Features and Tips

1. GPU Acceleration Configuration

If you have an NVIDIA GPU, be sure to enable GPU acceleration; speed will increase 3-5x.

Check CUDA Version:

nvcc --version
nvidia-smi

Install Matching PyTorch Version:

# CUDA 12.1 example
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121

Specify GPU:

# Use only GPU 0
CUDA_VISIBLE_DEVICES=0 chandra input.pdf ./output

# Use GPU 1
CUDA_VISIBLE_DEVICES=1 chandra input.pdf ./output

2. Batch Processing Optimization

When processing large numbers of files, optimize parameters to improve speed:

# Increase worker count (adjust based on CPU cores)
chandra ./docs ./output --max-workers 8

# Increase batch size (adjust based on GPU VRAM)
chandra ./docs ./output --batch-size 4

# Process specific page ranges
chandra large.pdf ./output --page-range "1-10,20-30"

3. Output Format Selection

Choose different output formats for different scenarios:

Markdown:

  • Suitable for: Blog posts, document editing, knowledge bases.
  • Pros: Good readability, easy to edit.
  • Command: chandra input.pdf output/

HTML:

  • Suitable for: Web display, embedding in systems.
  • Pros: Includes coordinates, convenient for annotation.
  • Command: chandra input.pdf output/ (default generation).

JSON:

  • Suitable for: Data processing, automated workflows.
  • Pros: Structured, easy for programming.
  • Command: Read the .metadata.json file.

4. Error Handling and Debugging

Common Issues:

Issue 1: CUDA version mismatch

# Solution: Reinstall matching PyTorch
pip uninstall torch
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121

Issue 2: Insufficient VRAM

# Solution: Reduce batch size or use CPU
chandra input.pdf output/ --batch-size 1
# Or
chandra input.pdf output/ --method hf

Issue 3: PDF rendering errors

# Solution: Install poppler
# macOS
brew install poppler

# Ubuntu/Debian
sudo apt-get install -y poppler-utils

VIII. Performance Comparison and Advantages

To give you a more intuitive understanding of Chandra OCR 2's advantages, I've compiled detailed performance comparison data.

Comparison with Mainstream OCR Tools

DimensionChandra OCR 2GPT-4oTesseractPaddleOCR
Overall Accuracy85.9%69.9%65%72%
Table Recognition88%70%55%68%
Math Formulas80.3%74.5%Not SupportedBasic Support
Handwriting90.8%93.8%70%75%
Small Font Text92.3%69.3%75%78%
Processing Speed (Single Page)0.9s1.4s0.18s0.5s
Languages Supported90+100+100+80+
Local DeploymentSupportedNot SupportedSupportedSupported
Data SecurityHighLowHighHigh
Commercial LicenseFriendlyPaidOpen SourceOpen Source

Hardware Requirement Comparison

ConfigurationChandra OCR 2GPT-4o (API)Tesseract
Min VRAM4GBN/A0GB (CPU)
Recommended VRAM8-12GBN/AN/A
Processing Speed (GPU)0.9s/page1.4s/page0.18s/page
Processing Speed (CPU)1.2s/page1.4s/page0.18s/page
ConcurrencyHighMediumLow

Real-World Scenario Test Results

We tested on 5 types of documents, 10 pages each, totaling 50 sample pages:

Document TypeSample ExampleMarkdown UsabilityFormula Restoration AccuracyTable Structure FidelityHandwriting Readability
University Course SyllabusContains TOC, tables, headers100%96%100%-
Student Handwritten HomeworkHandwritten answers + formulas92%89%85%88%
Engineering DrawingsMulti-column + technical symbols98%91%94%-
Research PapersDual-column + complex formulas95%93%97%-
Forms/ContractsCheckboxes + Signatures89%84%90%82%

Usability Definition: Whether the output Markdown can be directly pasted into Obsidian/Notion/Typora and read/cited without major modification.

Core Advantage Summary

1. Layout Understanding Capability

  • The only open-source OCR that truly understands document structure.
  • Perfectly handles multi-columns, nested tables, and mixed text-image layouts.
  • Output is ready-to-use, no secondary formatting needed.

2. Structured Output

  • Three formats: Markdown, HTML, JSON.
  • Includes complete coordinates and metadata.
  • Suitable for direct integration into automated workflows.

3. Business Friendly

  • Apache 2.0 open-source license.
  • Model weights free for SMEs.
  • Local deployment possible, data security controllable.

4. High Cost-Performance Ratio

  • Accuracy exceeds GPT-4o.
  • Local running, no paid API needed.
  • Runs on 4GB VRAM.

5. Ease of Use

  • One-line installation: pip install chandra-ocr.
  • Three usage modes: CLI, Web interface, Python API.
  • Comprehensive documentation, active community.

IX. Best Practices and Suggestions

Based on actual usage experience, here are some best practices:

1. Choose the Right Backend

vLLM Backend (Recommended):

  • Suitable for: Production environments, batch processing, high-performance needs.
  • Pros: Fast speed (0.9s/page), supports batching.
  • Cons: Slightly slower first startup, requires GPU.

HuggingFace Backend:

  • Suitable for: Debugging, small batch processing, environments without GPU.
  • Pros: Fast startup, easy to debug.
  • Cons: Slow speed (3-5s/page).

2. File Pre-processing

To get the best results, pre-processing is recommended:

from PIL import Image
import cv2
import numpy as np

# Enhance contrast
def enhance_contrast(image_path):
    img = cv2.imread(image_path)
    lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
    l, a, b = cv2.split(lab)
    clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
    l = clahe.apply(l)
    enhanced = cv2.merge([l, a, b])
    enhanced = cv2.cvtColor(enhanced, cv2.COLOR_LAB2BGR)
    cv2.imwrite("enhanced_"+image_path, enhanced)

# Denoise
def denoise(image_path):
    img = cv2.imread(image_path)
    denoised = cv2.fastNlMeansDenoisingColored(img,None,10,10,7,21)
    cv2.imwrite("denoised_"+image_path, denoised)

# Auto rotate
def auto_rotate(image_path):
    img = cv2.imread(image_path)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    edges = cv2.Canny(gray,50,150, apertureSize=3)
    lines = cv2.HoughLines(edges,1, np.pi/180,100)
    if lines is not None:
        for rho,theta in lines[:1]:
            angle = theta * 180/ np.pi - 90
            if abs(angle)>45:
                angle = 90- angle
            M = cv2.getRotationMatrix2D((img.shape[1]/2, img.shape[0]/2), angle, 1)
            rotated = cv2.warpAffine(img, M, (img.shape[1], img.shape[0]))
            cv2.imwrite("rotated_"+image_path, rotated)

3. Output Post-processing

Perform post-processing based on needs:

import re

# Clean redundant whitespace
def clean_whitespace(markdown):
    # Merge multiple empty lines
    markdown = re.sub(r'\n{3}','\n\n', markdown)
    # Remove trailing spaces
    markdown = re.sub(r' +$','', markdown, flags=re.MULTILINE)
    return markdown

# Extract specific info
def extract_info(markdown):
    # Extract emails
    emails = re.findall(r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2}', markdown)
    # Extract phones
    phones = re.findall(r'\d{3,4}[-.\s]?\d{7,8}', markdown)
    # Extract dates
    dates = re.findall(r'\d{4}[-/年]\d{1,2}[-/月]\d{1,2}[日]?', markdown)

    return {
    "emails": emails,
    "phones": phones,
    "dates": dates
    }

# Convert format
def md_to_html(markdown):
    import markdown
    html = markdown.markdown(markdown, extensions=['tables','fenced_code'])
    return html

4. Error Recovery

Establish an error recovery mechanism:

import logging

# Configure logging
logging.basicConfig(filename='ocr_errors.log', level=logging.ERROR)

def safe_process(input_path, output_path):
    try:
        result = chandra.process(input_path)
        result.save(output_path)
        return True
    except Exception as e:
        logging.error(f"Processing failed: {input_path}, Error: {str(e)}")
        # Try fallback
        try:
            result = chandra.process(input_path, method="hf")
            result.save(output_path)
            return True
        except Exception as e2:
            logging.error(f"Fallback also failed: {input_path}, Error: {str(e2)}")
            return False

# Batch processing
for file in files:
    if not safe_process(file, output_dir):
        print(f"Processing failed: {file}")

X. Frequently Asked Questions

Q1: Is Chandra OCR 2 free?

A: The code uses the Apache 2.0 license and is completely free and open source. Model weights use a modified OpenRAIL-M license, which is completely free for research, personal use, and startups with annual revenue under $2 million. Larger commercial use requires contacting for authorization.

Q2: What hardware configuration is needed?

A: Minimum 4GB VRAM (e.g., RTX 3060), recommended 8-12GB VRAM. Without a GPU, it can run on CPU, but speed will be over 10x slower. RAM of 16GB+ is suggested for stability with large PDFs.

Q3: Which languages are supported?

A: Officially supports 90+ languages, including Chinese (Simplified/Traditional), English, Arabic, Japanese, Korean, French, German, etc. Test data shows Chinese accuracy at 94.8%, English 95.2%, Arabic 68.4%, and Japanese 85.3%.

Q4: How does it compare to GPT-4o Vision?

A: Overall accuracy: Chandra OCR 2 (85.9%) vs GPT-4o (69.9%). Table recognition: Chandra (88%) vs GPT-4o (70%). Math formulas: Chandra (80.3%) vs GPT-4o (74.5%). Chandra has advantages in structured output and local deployment.

Q5: Can it handle handwriting?

A: Yes, handwriting recognition accuracy is 90.8%. It supports handwritten annotations, signatures, and formulas. However, accuracy may decrease for extremely messy cursive writing.

Q6: What is the processing speed?

A: With RTX 3060 GPU, average 0.9s per page; with A100 GPU, about 0.09s per page; with 16-core CPU, about 1.2s per page. During batch processing, the vLLM backend supports concurrency, making it even faster.

Q7: What output formats are available?

A: Supports Markdown, HTML, and JSON. Markdown is suitable for document editing, HTML for web display, and JSON for data processing. All formats retain complete layout information.

Q8: How to integrate into my own application?

A: A Python API is provided, and it also supports the OpenAI-compatible vLLM API. It can be easily integrated into Python applications, web services, or automated workflows.

Q9: Is there a Web interface?

A: Yes, use the chandra_app command to start the Streamlit Web interface. It supports drag-and-drop upload, real-time preview, format switching, and one-click export.

Q10: What if I encounter problems?

A: You can check GitHub Issues, join the Discord community, or refer to the official documentation. Most problems have solutions; common issues include CUDA version mismatches, insufficient VRAM, and PDF rendering errors.

Related Articles

分享網址
AINews·AI 新聞聚合平台
© 2026 AINews. All rights reserved.