Instructions to use musapeker/pix2db-2b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use musapeker/pix2db-2b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="musapeker/pix2db-2b") 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("musapeker/pix2db-2b") model = AutoModelForMultimodalLM.from_pretrained("musapeker/pix2db-2b", 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 musapeker/pix2db-2b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "musapeker/pix2db-2b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "musapeker/pix2db-2b", "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/musapeker/pix2db-2b
- SGLang
How to use musapeker/pix2db-2b 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 "musapeker/pix2db-2b" \ --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": "musapeker/pix2db-2b", "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 "musapeker/pix2db-2b" \ --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": "musapeker/pix2db-2b", "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 musapeker/pix2db-2b with Docker Model Runner:
docker model run hf.co/musapeker/pix2db-2b
pix2db-2b — image → working SQLite database
A 2B vision-language model that turns a screenshot or photo of a table, form, invoice, receipt or chart
into a SQLite dump that runs: CREATE TABLE with types and keys, FOREIGN KEYs between related tables
(e.g. invoice header ↔ line items), and INSERTs for every row. Merged cells are expanded, multi-level headers
flattened, thousand separators / currency / accounting negatives normalized, dates written as ISO.
Code, repair layer and evaluation: https://github.com/m-peker/pix2db · Demo: Space · Colab
Usage
With the pix2db package (adds the verify/repair layer and a real SQLite database):
# pip install "git+https://github.com/m-peker/pix2db"
from pix2db import Pix2DB
model = Pix2DB.from_pretrained("musapeker/pix2db-2b")
db = model.extract("invoice.png")
print(db.sql)
db.query("SELECT SUM(price) FROM line_items")
db.save("invoice.sqlite")
With plain transformers (raw SQL text):
import torch
from transformers import AutoModelForImageTextToText, AutoProcessor
from pix2db.prompts import SQL_PROMPT # or copy the prompt from the repo
proc = AutoProcessor.from_pretrained("musapeker/pix2db-2b")
model = AutoModelForImageTextToText.from_pretrained("musapeker/pix2db-2b", dtype=torch.bfloat16, device_map="auto")
msgs = [{"role": "user", "content": [{"type": "image", "image": "invoice.png"}, {"type": "text", "text": SQL_PROMPT}]}]
inputs = proc.apply_chat_template(msgs, tokenize=True, add_generation_prompt=True, return_dict=True,
return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=3072, do_sample=False)
print(proc.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
The model was trained with this exact instruction (SQL_PROMPT); other prompts work less well.
LoRA adapter
The repo root holds the merged model. The LoRA adapter it was merged from is in adapter/
(280 MB) — useful if you want to keep fine-tuning on your own documents:
from peft import PeftModel
from transformers import AutoModelForImageTextToText
base = AutoModelForImageTextToText.from_pretrained("Qwen/Qwen3-VL-2B-Instruct", dtype="auto", device_map="auto")
model = PeftModel.from_pretrained(base, "musapeker/pix2db-2b", subfolder="adapter")
Repository contents
| Path | What |
|---|---|
model.safetensors, configs |
merged model (v2) |
adapter/ |
LoRA adapter (r=64) the model was merged from |
eval_runs_v2/ |
raw outputs and scores of every system on every eval set (v2) |
eval_runs/ |
the same for the earlier synthetic-only v1 |
tag v1 |
the v1 weights |
Results
| System | Synthetic test table exact |
FK recall | PubTabNet F1 | FinTabNet F1 | CORD recall | Synth. receipts recall | TabRecSet (unseen) F1 |
|---|---|---|---|---|---|---|---|
| pix2db-2b | 0.86 | 0.99 | 0.81 | 0.96 | 0.93 | 1.00 | 0.52 |
| Qwen3-VL-8B → SQL | 0.75 | 0.75 | 0.52 | 0.59 | 0.76 | 0.87 | 0.45 |
| Qwen3-VL-8B → HTML → pandas | 0.47 | 0.00 | 0.78 | 0.87 | 0.44 | 0.38 | 0.58 |
| Qwen3-VL-4B → SQL | 0.66 | 0.25 | 0.48 | 0.48 | 0.79 | 0.77 | 0.38 |
| Qwen3-VL-2B → SQL (base) | 0.53 | 0.23 | 0.30 | 0.36 | 0.59 | 0.67 | 0.31 |
All SQL systems go through the same repair layer. PubTabNet/FinTabNet/CORD numbers are on held-out splits of
datasets whose train splits were used for training; TabRecSet was never used for training (see the GitHub
README; the gap there is mainly reading accuracy on photographed text). Evaluation outputs: eval_runs_v2/ in this repo.
Training
Qwen3-VL-2B-Instruct + LoRA (r=64, α=128, language model only, vision tower frozen), merged.
1 epoch over ~36.6k examples (pix2db-data):
14k synthetic Spider renders (6 difficulty levels incl. documents with foreign keys, scans, charts),
3k synthetic receipts, 10k PubTabNet, 8k FinTabNet, 795 CORD receipts (×2). lr 1e-4 cosine, effective batch 16,
~6 h on one A40. The previous synthetic-only version is tagged v1.
Limitations
No handwriting; long tables (> ~30 rows) and dense financial statements are under-represented; charts without value labels are approximate; table/column names are chosen by the model.
License
Apache-2.0. Training data derived from Spider (CC BY-SA 4.0), PubTabNet & FinTabNet (CDLA-Permissive-1.0), CORD (CC BY 4.0).
- Downloads last month
- 2
Model tree for musapeker/pix2db-2b
Base model
Qwen/Qwen3-VL-2B-Instruct