Instructions to use artifex-software/pymupdf-chart with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use artifex-software/pymupdf-chart with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="artifex-software/pymupdf-chart") 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("artifex-software/pymupdf-chart") model = AutoModelForMultimodalLM.from_pretrained("artifex-software/pymupdf-chart", 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 artifex-software/pymupdf-chart with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "artifex-software/pymupdf-chart" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "artifex-software/pymupdf-chart", "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/artifex-software/pymupdf-chart
- SGLang
How to use artifex-software/pymupdf-chart 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 "artifex-software/pymupdf-chart" \ --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": "artifex-software/pymupdf-chart", "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 "artifex-software/pymupdf-chart" \ --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": "artifex-software/pymupdf-chart", "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 artifex-software/pymupdf-chart with Docker Model Runner:
docker model run hf.co/artifex-software/pymupdf-chart
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