Instructions to use Yesianrohn/YesOCR-0.8B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Yesianrohn/YesOCR-0.8B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Yesianrohn/YesOCR-0.8B") 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("Yesianrohn/YesOCR-0.8B") model = AutoModelForMultimodalLM.from_pretrained("Yesianrohn/YesOCR-0.8B", 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 Yesianrohn/YesOCR-0.8B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Yesianrohn/YesOCR-0.8B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Yesianrohn/YesOCR-0.8B", "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/Yesianrohn/YesOCR-0.8B
- SGLang
How to use Yesianrohn/YesOCR-0.8B 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 "Yesianrohn/YesOCR-0.8B" \ --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": "Yesianrohn/YesOCR-0.8B", "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 "Yesianrohn/YesOCR-0.8B" \ --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": "Yesianrohn/YesOCR-0.8B", "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 Yesianrohn/YesOCR-0.8B with Docker Model Runner:
docker model run hf.co/Yesianrohn/YesOCR-0.8B
YesOCR-0.8B
English | ไธญๆ
General ChineseโEnglish Bilingual OCR.
YesOCR-0.8B turns text in Chinese, English, and mixed-language images into editable plain text. Use it to transcribe document pages, screenshots, receipts, signs, and other everyday images. It aims to follow reading order and preserve the original text and line breaks.
The model is fine-tuned from Qwen3.5-0.8B, primarily using the OCR-Data dataset.
Try it
Use Python 3.10 or newer. A GPU is recommended for faster recognition; CPU inference is also supported.
Download the model, install its dependencies, and recognize the included example image:
python -m pip install huggingface_hub
hf download Yesianrohn/YesOCR-0.8B --local-dir ./YesOCR-0.8B
cd YesOCR-0.8B
python -m pip install -r requirements.txt
python inference.py --model . --image example.png --output result.txt
The recognized text is printed in the terminal and saved to result.txt:
YesOCR demo
Order: A1024
Total: 128.50
Recognize your own images
Replace your-image.png with the path to your image:
python inference.py --model . --image your-image.png --output result.txt
The same command works for Chinese, English, and mixed-language images. There is no need to select a language. The result is a transcription of the original text.
The script automatically uses a GPU when one is available. Add --device cpu to run on CPU.
Once the model and dependencies are downloaded, --model . lets you use the local files offline.
Use with Transformers
You can also load Yesianrohn/YesOCR-0.8B directly in Python.
The example below uses a CUDA GPU with BF16 support. Replace example.png with your image path;
keep the provided OCR prompt for both Chinese and English images.
Show the complete Python example
import torch
from PIL import Image, ImageOps, PngImagePlugin
from transformers import AutoModelForImageTextToText, AutoProcessor
MODEL_ID = "Yesianrohn/YesOCR-0.8B"
# Allow PNGs with large compressed color profiles.
PngImagePlugin.MAX_TEXT_CHUNK = 64 * 1024 * 1024
PngImagePlugin.MAX_TEXT_MEMORY = 256 * 1024 * 1024
processor = AutoProcessor.from_pretrained(MODEL_ID)
model = AutoModelForImageTextToText.from_pretrained(
MODEL_ID,
dtype=torch.bfloat16,
attn_implementation="sdpa",
).to("cuda").eval()
with Image.open("example.png") as source:
image = ImageOps.exif_transpose(source).convert("RGB")
prompt = (
"่ฏทๆ้
่ฏป้กบๅบ่ฝฌๅฝๅพ็ไธญ็ๅ
จ้จๅฏ่พจ่ฎคๆๅญ๏ผไฟ็ๅๆๅๆข่ก๏ผๆๆฌๅไน้ด็ฉบไธ่กใ"
"ไป
่พๅบ่ฝฌๅฝ็ปๆใ"
)
messages = [{
"role": "user",
"content": [
{"type": "image", "image": image},
{"type": "text", "text": "\n" + prompt},
],
}]
text = processor.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
enable_thinking=False,
)
inputs = processor(text=[text], images=[image], return_tensors="pt").to(model.device)
with torch.inference_mode():
output_ids = model.generate(
**inputs,
max_new_tokens=4096,
do_sample=False,
num_beams=1,
use_cache=True,
)
# Decode only the newly generated tokens.
new_tokens = output_ids[:, inputs["input_ids"].shape[1]:]
result = processor.batch_decode(new_tokens, skip_special_tokens=True)[0].strip()
image.close()
print(result)
For CPU inference, replace dtype=torch.bfloat16 with dtype=torch.float32
and .to("cuda") with .to("cpu").
Tips
- Use clear images with readable text. For dense or long pages, try cropping the page into sections in reading order.
- If a long transcription stops early, add
--max-new-tokens 8192. - If GPU memory is insufficient, try
--max-pixels 1000000. - Output is plain text. Complex tables, columns, and page layouts may need manual formatting.
License and credits
Published by Yesianrohn under the Apache License 2.0. Thanks to the Qwen team for the base model. See NOTICE for attribution.
- Downloads last month
- 4
