PyMuPDF Chart
extract tables from charts
2 min read
A vision-language model based on PaddleOCR-VL that takes a chart image and converts its data into a text table. The tool is designed to work alongside the PyMuPDF library for automated PDF document processing. The model requires an NVIDIA GPU with CUDA support and about 2 GB of VRAM for inference. It is a useful tool for developers and analysts who need to automate the digitization of charts from reports and documents.
Key features
- Accurate data recognition from charts and output in a delimited row format
- Construction of table rows with cells separated by a vertical bar
- Based on the PaddleOCR-VL architecture adapted for the Hugging Face Transformers format
- Apache License 2.0 for free use
What you can do
- Integrate the model into a PDF processing pipeline using PyMuPDF
- Automatically convert charts from financial and analytical reports into Markdown table format
- Extract number series and headers from chart images
Example
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())Read more
DetailsHardware requirements: CUDA GPU, about 2 GB VRAM (CPU not supported).
Dependencies: Python 3.12, PyTorch, torchvision, Transformers 5.13 or newer.
Limitations: labels, values, and units may contain errors; long tables or complex multi-panel charts may be truncated at the 2048 token limit.










Comments