# baidu/unlimited-ocr architecture

> Architecture diagram of the GitHub repository baidu/unlimited-ocr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/baidu/unlimited-ocr
- Repository: https://github.com/baidu/unlimited-ocr
- Video tour (about a minute): https://gitdiagram.com/baidu/unlimited-ocr/video

## Overview

This repository provides a practical Unlimited OCR 2 inference and output-conversion workflow, rather than the OCR model implementation itself. Users submit ordered page images through the SGLang client, receive raw OCR output, and can convert that output to Markdown. The README also documents native Transformers inference and the model’s multi-page and ultra-long-document capabilities. The graph reflects the sampled client and converter; model internals and the unsampled portions of conversion are not mapped in detail.

Main entry points: [`infer.py`](https://github.com/baidu/unlimited-ocr/blob/main/infer.py) (Document inference), [`utils/process_unlimitedOCR2.py`](https://github.com/baidu/unlimited-ocr/blob/main/utils/process_unlimitedOCR2.py) (OCR conversion), [`README.md`](https://github.com/baidu/unlimited-ocr/blob/main/README.md) (Transformers inference)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Inference workflow"]
  node_client["Document inference<br/>[infer.py]"]
  node_raw["Raw OCR text"]
end

subgraph group_serving["Model serving"]
  node_sglang["SGLang server"]
  node_transformers["Transformers inference<br/>[README.md]"]
end

subgraph group_conversion["Output conversion"]
  node_converter["OCR conversion"]
  node_markdown["Markdown output"]
end

node_user(("OCR user"))
node_pages["Page images"]

node_user -->|"runs"| node_client
node_pages -->|"reads pages"| node_client
node_client -->|"posts request"| node_sglang
node_sglang -->|"returns OCR"| node_client
node_client -->|"writes text"| node_raw
node_user -->|"loads model"| node_transformers
node_raw -->|"converts"| node_converter
node_converter -->|"renders"| node_markdown

click node_client "https://github.com/baidu/unlimited-ocr/blob/main/infer.py"
click node_transformers "https://github.com/baidu/unlimited-ocr/blob/main/README.md"
click node_converter "https://github.com/baidu/unlimited-ocr/blob/main/utils/process_unlimitedOCR2.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client,node_raw,node_user toneBlue
class node_sglang,node_transformers toneAmber
class node_converter,node_markdown toneMint
class node_pages toneIndigo
```

## Components

### Inference workflow

- [Document inference](https://github.com/baidu/unlimited-ocr/blob/main/infer.py): `infer.py`
- **Raw OCR text**

### Model serving

- **SGLang server**
- [Transformers inference](https://github.com/baidu/unlimited-ocr/blob/main/README.md): `README.md`

### Output conversion

- [OCR conversion](https://github.com/baidu/unlimited-ocr/blob/main/utils/process_unlimitedOCR2.py): `utils/process_unlimitedOCR2.py`
- **Markdown output**

### Other components

- **OCR user**
- **Page images**

## Connections

- OCR user → Document inference: runs (evidence: `infer.py`)
- Page images → Document inference: reads pages (evidence: `infer.py`)
- Document inference → SGLang server: posts request (evidence: `infer.py`)
- SGLang server → Document inference: returns OCR (evidence: `infer.py`)
- Document inference → Raw OCR text: writes text (evidence: `infer.py`)
- OCR user → Transformers inference: loads model (evidence: `README.md`)
- Raw OCR text → OCR conversion: converts (evidence: `utils/process_unlimitedOCR2.py`)
- OCR conversion → Markdown output: renders (evidence: `utils/process_unlimitedOCR2.py`)
