Image-Text-to-Text
Transformers
Safetensors
Portuguese
mistral3
text-generation
ocr
htr
handwritten-text-recognition
handwriting
error-preserving
document-understanding
portuguese
pt-br
essays
education
bressay
lightonocr
vllm
conversational
Eval Results (legacy)
Instructions to use tardellirs/Escriba-OCR-1B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tardellirs/Escriba-OCR-1B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="tardellirs/Escriba-OCR-1B") 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, AutoModelForSeq2SeqLM processor = AutoProcessor.from_pretrained("tardellirs/Escriba-OCR-1B") model = AutoModelForSeq2SeqLM.from_pretrained("tardellirs/Escriba-OCR-1B", 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 tardellirs/Escriba-OCR-1B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tardellirs/Escriba-OCR-1B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tardellirs/Escriba-OCR-1B", "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/tardellirs/Escriba-OCR-1B
- SGLang
How to use tardellirs/Escriba-OCR-1B 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 "tardellirs/Escriba-OCR-1B" \ --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": "tardellirs/Escriba-OCR-1B", "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 "tardellirs/Escriba-OCR-1B" \ --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": "tardellirs/Escriba-OCR-1B", "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 tardellirs/Escriba-OCR-1B with Docker Model Runner:
docker model run hf.co/tardellirs/Escriba-OCR-1B
Download inference_example.py from tardellirs/Escriba-OCR-1B: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/tardellirs/Escriba-OCR-1B/resolve/main/inference_example.py
- Command line
-
hf download hf://tardellirs/Escriba-OCR-1B/inference_example.py
-
curl -L -o inference_example.py https://huggingface.co/tardellirs/Escriba-OCR-1B/resolve/main/inference_example.py
1.44 kB
| """Escriba-OCR-1B: transcribe a handwritten essay page (diplomatic transcription). | |
| Recommended: vLLM (loads the checkpoint as-is). | |
| pip install "vllm>=0.34" pillow | |
| python inference_example.py page.png | |
| IMPORTANT: upscale the page so its longer side is 1200 px. The processor only downscales, | |
| and small scans (~550 px, like BRESSAY) give the model too few visual tokens. | |
| """ | |
| import base64 | |
| import io | |
| import sys | |
| from PIL import Image | |
| from vllm import LLM, SamplingParams | |
| MODEL = "tardellirs/Escriba-OCR-1B" | |
| LONG_SIDE = 1200 | |
| def to_data_url(path: str) -> str: | |
| im = Image.open(path).convert("RGB") | |
| f = LONG_SIDE / max(im.size) | |
| im = im.resize((round(im.width * f), round(im.height * f)), Image.LANCZOS) | |
| buf = io.BytesIO() | |
| im.save(buf, format="PNG") | |
| return "data:image/png;base64," + base64.b64encode(buf.getvalue()).decode() | |
| def main() -> None: | |
| llm = LLM(model=MODEL, max_model_len=8192, limit_mm_per_prompt={"image": 1}) | |
| params = SamplingParams(temperature=0.0, repetition_penalty=1.05, max_tokens=2048) | |
| # Empty prompt = transcription mode (image only), exactly as in training. | |
| messages = [[{"role": "user", "content": [{"type": "image_url", "image_url": {"url": to_data_url(p)}}]}] | |
| for p in sys.argv[1:]] | |
| for path, out in zip(sys.argv[1:], llm.chat(messages, params)): | |
| print(f"===== {path}\n{out.outputs[0].text}\n") | |
| if __name__ == "__main__": | |
| main() | |