FBR65/chandr

A FastAPI-based web service that performs optical character recognition using the chandra-ocr library and integrates transformer models for enhanced text processing.

0

stars

0

commits

Python

primary language

Apr 18, 2026

updated

api
fastapi
machine-learning
nlp
ocr
optical-character-recognition
python
text-processing
transformers
web-service
Browse cluster: Optical Character Recognition and Document Processing

README

Chandra OCR API

An OpenAI-compatible API for document layout analysis using the Chandra OCR 2 model.

Overview

Chandra OCR 2 is a state-of-the-art document understanding model that performs layout analysis on document images. This API provides an OpenAI-compatible interface for processing document images and extracting layout information including bounding boxes, categories, and text content.

Features

  • Layout analysis for document images
  • Support for multiple layout categories (Caption, Footnote, Formula, List-item, Page-footer, Page-header, Picture, Section-header, Table, Text, Title)
  • OpenAI-compatible API endpoints
  • FastAPI-based server with async processing
  • GPU acceleration support via PyTorch

Installation

Prerequisites

  • Python 3.11 or higher
  • PyTorch with CUDA support (optional, for GPU acceleration)

Setup

  1. Clone the repository:
git clone <repository-url>
cd chandr
  1. Install dependencies:
uv sync
  1. Download the model:
# The model will be automatically downloaded on first run
# Model: datalab-to/chandra-ocr-2

Usage

Starting the Server

Run the following command to start the API server:

uv run main

The server will start on http://0.0.0.0:8000.

API Endpoints

Health Check

GET /health

Returns the health status of the API.

List Models

GET /v1/models

Returns a list of available models.

Chat Completions

POST /v1/chat/completions

Processes a document image and returns layout analysis.

Request Body:

{
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "image_url",
          "image_url": {
            "url": "data:image/png;base64,..."
          }
        }
      ]
    }
  ],
  "max_tokens": 24000
}

Response:

{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "chandra-ocr-2",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 0,
    "completion_tokens": 0,
    "total_tokens": 0
  }
}

Example Request

curl -X POST http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "image_url",
            "image_url": {
              "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
            }
          }
        ]
      }
    ],
    "max_tokens": 24000
  }'

Model Information

  • Model Name: datalab-to/chandra-ocr-2
  • Type: Image-to-Text Model
  • License: Apache 2.0

Output Format

The API returns layout analysis results in markdown format, including:

  • Bbox: Coordinates in format [x1, y1, x2, y2]
  • Categories: Caption, Footnote, Formula, List-item, Page-footer, Page-header, Picture, Section-header, Table, Text, Title
  • Text Content: Extracted text formatted according to category:
    • Formula: LaTeX format
    • Table: HTML format
    • Other categories: Markdown format

License

This project is licensed under the MIT License.

FBR65/chandr

A FastAPI-based web service that performs optical character recognition using the chandra-ocr library and integrates transformer models for enhanced text processing.

0

stars

0

commits

Python

primary language

Apr 18, 2026

updated

api
fastapi
machine-learning
nlp
ocr
optical-character-recognition
python
text-processing
transformers
web-service
Browse cluster: Optical Character Recognition and Document Processing

README

Chandra OCR API

An OpenAI-compatible API for document layout analysis using the Chandra OCR 2 model.

Overview

Chandra OCR 2 is a state-of-the-art document understanding model that performs layout analysis on document images. This API provides an OpenAI-compatible interface for processing document images and extracting layout information including bounding boxes, categories, and text content.

Features

  • Layout analysis for document images
  • Support for multiple layout categories (Caption, Footnote, Formula, List-item, Page-footer, Page-header, Picture, Section-header, Table, Text, Title)
  • OpenAI-compatible API endpoints
  • FastAPI-based server with async processing
  • GPU acceleration support via PyTorch

Installation

Prerequisites

  • Python 3.11 or higher
  • PyTorch with CUDA support (optional, for GPU acceleration)

Setup

  1. Clone the repository:
git clone <repository-url>
cd chandr
  1. Install dependencies:
uv sync
  1. Download the model:
# The model will be automatically downloaded on first run
# Model: datalab-to/chandra-ocr-2

Usage

Starting the Server

Run the following command to start the API server:

uv run main

The server will start on http://0.0.0.0:8000.

API Endpoints

Health Check

GET /health

Returns the health status of the API.

List Models

GET /v1/models

Returns a list of available models.

Chat Completions

POST /v1/chat/completions

Processes a document image and returns layout analysis.

Request Body:

{
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "image_url",
          "image_url": {
            "url": "data:image/png;base64,..."
          }
        }
      ]
    }
  ],
  "max_tokens": 24000
}

Response:

{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "chandra-ocr-2",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 0,
    "completion_tokens": 0,
    "total_tokens": 0
  }
}

Example Request

curl -X POST http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "image_url",
            "image_url": {
              "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
            }
          }
        ]
      }
    ],
    "max_tokens": 24000
  }'

Model Information

  • Model Name: datalab-to/chandra-ocr-2
  • Type: Image-to-Text Model
  • License: Apache 2.0

Output Format

The API returns layout analysis results in markdown format, including:

  • Bbox: Coordinates in format [x1, y1, x2, y2]
  • Categories: Caption, Footnote, Formula, List-item, Page-footer, Page-header, Picture, Section-header, Table, Text, Title
  • Text Content: Extracted text formatted according to category:
    • Formula: LaTeX format
    • Table: HTML format
    • Other categories: Markdown format

License

This project is licensed under the MIT License.

Languages

Python

100.0%