PyMuPDF Chart 0.1.0

PyMuPDF Chart reads a chart image and writes its data as a table. It is intended for use with PyMuPDF, where charts found in a PDF page are converted to tables.

It is a vision-language model fine-tuned from PaddleOCR-VL. It takes one chart image at a time.

Requirements

  • A CUDA GPU. CPU inference is not supported. Inference uses about 2 GB of GPU memory.
  • Python 3.12 with a CUDA build of PyTorch and torchvision.
  • Transformers 5.13 or later.

Tested on Linux x86-64 with PyTorch 2.12.1 (CUDA 13.0) and 2.15.0 (CUDA 13.2), and Transformers 5.23.0.

Chart image to table

from PIL import Image
import torch
from transformers import AutoModelForImageTextToText, AutoProcessor

repo_id = "artifex-software/pymupdf-chart"
processor = AutoProcessor.from_pretrained(repo_id)
model = AutoModelForImageTextToText.from_pretrained(
    repo_id, dtype=torch.bfloat16
).to("cuda").eval()

image = Image.open("chart.png").convert("RGB")
messages = [{"role": "user", "content": [
    {"type": "image", "image": image},
    {"type": "text", "text": "Chart Recognition:"},
]}]
inputs = processor.apply_chat_template(
    messages, add_generation_prompt=True, tokenize=True,
    return_dict=True, return_tensors="pt",
).to(model.device)
with torch.inference_mode():
    output = model.generate(**inputs, max_new_tokens=2048, do_sample=False)
print(processor.decode(
    output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True
).strip())

The model prints one line per table row, with cells separated by | and the header row first, for example

Category | Revenue
Q1 | 12
Q2 | 27
Q3 | 18
Q4 | 35

Wrap each line in | and add a | --- | --- | row after the header to get a Markdown table.

Limitations

  • Labels, values, units and series can be wrong. Values that are not printed on the chart are estimates read from the axes.
  • Figures with several chart panels, legends or axes outside the image, and very long tables are harder. Output is cut at 2048 new tokens.
  • An image that is not a chart can still produce a table.
  • Compare results with the source chart before relying on them.

License

The models in this repository are licensed under the Apache License 2.0. See LICENSE.

The chart-to-table model is a fine-tuned version of PaddleOCR-VL (Copyright (c) 2025 PaddlePaddle Authors, Apache License 2.0). Its weights were changed by fine-tuning and its configuration files were converted to the native Transformers format.

PyMuPDF is licensed separately, under the GNU AGPL v3.0 or a commercial license from Artifex.

Downloads last month
15
Safetensors
Model size
0.9B params
Tensor type
BF16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support