Image-Text-to-Text
Transformers
Joblib
Safetensors
English
qwen3_5
ocr
pdf
markdown
document-parsing
tables
charts
parsebench
conversational
Eval Results
Instructions to use llamaindex/OCRia-1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use llamaindex/OCRia-1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="llamaindex/OCRia-1") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("llamaindex/OCRia-1") model = AutoModelForMultimodalLM.from_pretrained("llamaindex/OCRia-1", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use llamaindex/OCRia-1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "llamaindex/OCRia-1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "llamaindex/OCRia-1", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/llamaindex/OCRia-1
- SGLang
How to use llamaindex/OCRia-1 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "llamaindex/OCRia-1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "llamaindex/OCRia-1", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "llamaindex/OCRia-1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "llamaindex/OCRia-1", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use llamaindex/OCRia-1 with Docker Model Runner:
docker model run hf.co/llamaindex/OCRia-1
File size: 3,949 Bytes
2b133ff | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | # Copyright (c) 2026 LlamaIndex, Inc. All rights reserved.
# Licensed under the OCRia-1 Model and Code License (LICENSE at the root of this repository).
# This is not open-source software: see the license for permitted uses.
"""Transcribe one page with OCRia-1 and draw its layout boxes (experimental).
pip install "transformers==5.22.2" accelerate torchvision timm scipy pypdfium2 huggingface_hub
python examples/boxes.py doc.pdf --page 0 # a PDF page: exact word positions from its text layer
python examples/boxes.py page.png # an image: word positions from the model's attention
python examples/boxes.py page.png --attention-only # no layout detector (less accurate)
Writes <name>.boxes.png and <name>.boxes.json next to the input. Needs a CUDA GPU for OCRia-1; the Heron layout
detector (docling-project/docling-layout-heron, Apache-2.0) is downloaded from its own repository on first use. Run it
from a download of this repository (huggingface-cli download llamaindex/OCRia-1 --local-dir OCRia-1); the weights come
from the Hub (or a local copy: OCRIA_MODEL=/path/to/OCRia-1).
"""
import argparse
import json
import os
import sys
import time
from pathlib import Path
from PIL import Image, ImageDraw
sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) # the repository root holds ocria_grounding/
from ocria_grounding import MODEL, ground_layout, load, load_detector, load_fast_layout, render_pdf_page, transcribe # noqa: E402
COLORS = {"Section-header": "#d62728", "Title": "#d62728", "Text": "#1f77b4", "List-item": "#2ca02c",
"Table": "#ff7f0e", "Picture": "#9467bd", "Caption": "#8c564b", "Footnote": "#8c564b",
"Page-header": "#7f7f7f", "Page-footer": "#7f7f7f"}
def main() -> None:
ap = argparse.ArgumentParser()
ap.add_argument("path", help="a PDF or a page image")
ap.add_argument("--page", type=int, default=0, help="PDF page index (0-based)")
ap.add_argument("--attention-only", action="store_true", help="skip the layout detector")
ap.add_argument("--layout", choices=["accurate-layout", "fast-layout"], default="accurate-layout")
args = ap.parse_args()
if args.path.lower().endswith(".pdf"):
image, words = render_pdf_page(args.path, args.page, dpi=300)
else:
image, words = Image.open(args.path).convert("RGB"), None
g = load(os.environ.get("OCRIA_MODEL", MODEL))
fast = load_fast_layout() if args.layout == "fast-layout" else None
det = None if args.attention_only or fast is not None else load_detector()
t0 = time.perf_counter()
answer = transcribe(g, image)
t1 = time.perf_counter()
page = ground_layout(g, image, answer, detector=det, words=words if fast is None else None,
method=args.layout, fast_backend=fast)
t2 = time.perf_counter()
out = image.copy()
draw = ImageDraw.Draw(out)
width = max(2, image.width // 500)
pad = width + 2 # draw outside the box so the outline never covers the first or last letter
for it in page["items"]:
color = COLORS.get(it["type"], "#17becf")
x0, y0, x1, y1 = it["box"]
draw.rectangle([x0 - pad, y0 - pad, x1 + pad, y1 + pad], outline=color, width=width)
tw, th = draw.textbbox((0, 0), it["type"])[2:] # the type label sits above the box, on a white tab
ty = max(0, y0 - pad - th - 2)
draw.rectangle([x0 - pad, ty, x0 - pad + tw + 4, ty + th + 2], fill="white")
draw.text((x0 - pad + 2, ty), it["type"], fill=color)
stem = Path(args.path).with_suffix("")
if args.path.lower().endswith(".pdf"):
stem = Path(f"{stem}.p{args.page}")
out.save(f"{stem}.boxes.png")
Path(f"{stem}.boxes.json").write_text(json.dumps({"answer": answer, **page}, indent=1))
print(f"{len(page['items'])} items -> {stem}.boxes.png (transcription {t1 - t0:.1f} s, boxes {t2 - t1:.1f} s)")
if __name__ == "__main__":
main()
|