import os
import torch
from transformers import AutoModel, AutoTokenizer
model_name = 'baidu/Unlimited-OCR'
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModel.from_pretrained(
model_name,
trust_remote_code=True,
use_safetensors=True,
torch_dtype=torch.bfloat16,
)
model = model.eval().cuda()
# ── Single image supports two configs: gundam or base ──# gundam: base_size=1024, image_size=640, crop_mode=True# base: base_size=1024, image_size=1024, crop_mode=False
model.infer(
tokenizer,
prompt='<image>document parsing.',
image_file='your_image.jpg',
output_path='your/output/dir',
base_size=1024, image_size=640, crop_mode=True,
max_length=32768,
no_repeat_ngram_size=35, ngram_window=128,
save_results=True,
)
# ── Multi page / PDF only uses base (image_size=1024) ──
model.infer_multi(
tokenizer,
prompt='<image>Multi page parsing.',
image_files=['page1.png', 'page2.png', 'page3.png'],
output_path='your/output/dir',
image_size=1024,
max_length=32768,
no_repeat_ngram_size=35, ngram_window=1024,
save_results=True,
)
# ── PDF (convert pages to images, then multi-page parsing) ──import tempfile, fitz # PyMuPDFdefpdf_to_images(pdf_path, dpi=300):
doc = fitz.open(pdf_path)
tmp_dir = tempfile.mkdtemp(prefix='pdf_ocr_')
mat = fitz.Matrix(dpi / 72, dpi / 72)
paths = []
for i, page inenumerate(doc):
out = os.path.join(tmp_dir, f'page_{i+1:04d}.png')
page.get_pixmap(matrix=mat).save(out)
paths.append(out)
doc.close()
return paths
model.infer_multi(
tokenizer,
prompt='<image>Multi page parsing.',
image_files=pdf_to_images('your_doc.pdf', dpi=300),
output_path='your/output/dir',
image_size=1024,
max_length=32768,
no_repeat_ngram_size=35, ngram_window=1024,
save_results=True,
)
SGLang
Set up the environment (uv-managed virtualenv). Install the local SGLang wheel first,
then pin
kernels==0.9.0
and install PyMuPDF for PDF-to-image conversion:
Unlimited-OCR huggingface.co is an AI model on huggingface.co that provides Unlimited-OCR's model effect (), which can be used instantly with this baidu Unlimited-OCR model. huggingface.co supports a free trial of the Unlimited-OCR model, and also provides paid use of the Unlimited-OCR. Support call Unlimited-OCR model through api, including Node.js, Python, http.
Unlimited-OCR huggingface.co is an online trial and call api platform, which integrates Unlimited-OCR's modeling effects, including api services, and provides a free online trial of Unlimited-OCR, you can try Unlimited-OCR online for free by clicking the link below.
baidu Unlimited-OCR online free url in huggingface.co:
Unlimited-OCR is an open source model from GitHub that offers a free installation service, and any user can find Unlimited-OCR on GitHub to install. At the same time, huggingface.co provides the effect of Unlimited-OCR install, users can directly use Unlimited-OCR installed effect in huggingface.co for debugging and trial. It also supports api for free installation.