Image-Text-to-Text
Transformers
Safetensors
English
qwen2_5_vl
OCR
unsloth
pdf2markdown
conversational
text-generation-inference
Instructions to use unsloth/Nanonets-OCR-s with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use unsloth/Nanonets-OCR-s with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="unsloth/Nanonets-OCR-s") 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)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("unsloth/Nanonets-OCR-s") model = AutoModelForImageTextToText.from_pretrained("unsloth/Nanonets-OCR-s") 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=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use unsloth/Nanonets-OCR-s with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "unsloth/Nanonets-OCR-s" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "unsloth/Nanonets-OCR-s", "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/unsloth/Nanonets-OCR-s
- SGLang
How to use unsloth/Nanonets-OCR-s 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 "unsloth/Nanonets-OCR-s" \ --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": "unsloth/Nanonets-OCR-s", "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 "unsloth/Nanonets-OCR-s" \ --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": "unsloth/Nanonets-OCR-s", "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" } } ] } ] }' - Unsloth Studio
How to use unsloth/Nanonets-OCR-s with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/Nanonets-OCR-s to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/Nanonets-OCR-s to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for unsloth/Nanonets-OCR-s to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="unsloth/Nanonets-OCR-s", max_seq_length=2048, ) - Docker Model Runner
How to use unsloth/Nanonets-OCR-s with Docker Model Runner:
docker model run hf.co/unsloth/Nanonets-OCR-s
Upload folder using huggingface_hub
Browse files- config.json +1 -1
- tokenizer_config.json +1 -1
config.json
CHANGED
|
@@ -103,4 +103,4 @@
|
|
| 103 |
"vision_start_token_id": 151652,
|
| 104 |
"vision_token_id": 151654,
|
| 105 |
"vocab_size": 151936
|
| 106 |
-
}
|
|
|
|
| 103 |
"vision_start_token_id": 151652,
|
| 104 |
"vision_token_id": 151654,
|
| 105 |
"vocab_size": 151936
|
| 106 |
+
}
|
tokenizer_config.json
CHANGED
|
@@ -206,5 +206,5 @@
|
|
| 206 |
"split_special_tokens": false,
|
| 207 |
"tokenizer_class": "Qwen2Tokenizer",
|
| 208 |
"unk_token": null,
|
| 209 |
-
"chat_template": "{% set image_count = namespace(value=0) %}{% set video_count = namespace(value=0) %}{% for message in messages %}{% if loop.first and message[
|
| 210 |
}
|
|
|
|
| 206 |
"split_special_tokens": false,
|
| 207 |
"tokenizer_class": "Qwen2Tokenizer",
|
| 208 |
"unk_token": null,
|
| 209 |
+
"chat_template": "{#- Copyright 2025-present the Unsloth team. All rights reserved. #}\n{#- Licensed under the Apache License, Version 2.0 (the \"License\") #}\n{%- set image_count = namespace(value=0) -%}\n{%- set video_count = namespace(value=0) -%}\n{%- set text_count = namespace(value=0) -%}\n{%- for message in messages -%}\n\t{%- if loop.first and message[\"role\"] != \"system\" -%}\n\t\t{{- \"<|im_start|>system\\nYou are a helpful assistant.<|im_end|>\\n\" -}}\n\t{%- endif -%}\n\t{{- \"<|im_start|>\" -}}\n\t{{- message[\"role\"] -}}\n\t{{- \"\\n\" -}}\n\t{%- if message[\"content\"] is string -%}\n\t\t{{- message[\"content\"] -}}\n\t\t{{- \"<|im_end|>\\n\" -}}\n\t{%- else -%}\n\t\t{#- Check if text field is present #}\n\t\t{%- set text_count.value = 0 -%}\n\t\t{%- for content in message[\"content\"] -%}\n\t\t\t{%- if content[\"type\"] == \"image\" or \"image\" in content or \"image_url\" in content -%}\n\t\t\t\t{%- set image_count.value = image_count.value + 1 -%}\n\t\t\t\t{%- if add_vision_id -%}\n\t\t\t\t\t{{- \"Picture \" -}}\n\t\t\t\t\t{{- image_count.value -}}\n\t\t\t\t\t{{- \": \" -}}\n\t\t\t\t{%- endif -%}\n\t\t\t\t{{- \"<|vision_start|><|image_pad|><|vision_end|>\" -}}\n\t\t\t{%- elif content[\"type\"] == \"video\" or \"video\" in content -%}\n\t\t\t\t{%- set video_count.value = video_count.value + 1 -%}\n\t\t\t\t{%- if add_vision_id -%}\n\t\t\t\t\t{{- \"Video \" -}}\n\t\t\t\t\t{{- video_count.value -}}\n\t\t\t\t\t{{- \": \" -}}\n\t\t\t\t{%- endif -%}\n\t\t\t\t{{- \"<|vision_start|><|video_pad|><|vision_end|>\" -}}\n\t\t\t{%- elif \"text\" in content -%}\n\t\t\t\t{{- content[\"text\"]|string -}}\n\t\t\t\t{%- if content[\"text\"]|length != 0 -%}\n\t\t\t\t\t{%- set text_count.value = text_count.value + 1 -%}\n\t\t\t\t{%- endif -%}\n\t\t\t{%- endif -%}\n\t\t{%- endfor -%}\n\t\t{#- If text field seen, add a newline #}\n\t\t{%- if text_count.value != 0 -%}\n\t\t\t{{- \"\\n\" -}}\n\t\t{%- endif -%}\n\t\t{{- \"Extract the text from the above document as if you were reading it naturally. Return the tables in html format. Return the equations in LaTeX representation. If there is an image in the document and image caption is not present, add a small description of the image inside the <img></img> tag; otherwise, add the image caption inside <img></img>. Watermarks should be wrapped in brackets. Ex: <watermark>OFFICIAL COPY</watermark>. Page numbers should be wrapped in brackets. Ex: <page_number>14</page_number> or <page_number>9/22</page_number>. Prefer using ☐ and ☑ for check boxes.\" -}}\n\t\t{{- \"<|im_end|>\\n\" -}}\n\t{%- endif -%}\n{%- endfor -%}\n{%- if add_generation_prompt -%}\n\t{{- \"<|im_start|>assistant\\n\" -}}\n{%- endif -%}\n{#- Copyright 2025-present the Unsloth team. All rights reserved. #}\n{#- Licensed under the Apache License, Version 2.0 (the \"License\") #}"
|
| 210 |
}
|