Instructions to use tungedng2710/cogniocr with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use tungedng2710/cogniocr with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("unsloth/Qwen3.5-0.8B") model = PeftModel.from_pretrained(base_model, "tungedng2710/cogniocr") - Transformers
How to use tungedng2710/cogniocr with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="tungedng2710/cogniocr") 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 AutoModel model = AutoModel.from_pretrained("tungedng2710/cogniocr", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tungedng2710/cogniocr with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tungedng2710/cogniocr" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tungedng2710/cogniocr", "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/tungedng2710/cogniocr
- SGLang
How to use tungedng2710/cogniocr 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 "tungedng2710/cogniocr" \ --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": "tungedng2710/cogniocr", "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 "tungedng2710/cogniocr" \ --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": "tungedng2710/cogniocr", "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 tungedng2710/cogniocr 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 tungedng2710/cogniocr 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 tungedng2710/cogniocr to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for tungedng2710/cogniocr to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="tungedng2710/cogniocr", max_seq_length=2048, ) - Docker Model Runner
How to use tungedng2710/cogniocr with Docker Model Runner:
docker model run hf.co/tungedng2710/cogniocr
CogniOCR LoRA
This repository contains a LoRA adapter fine-tuned for OCR from the base model
unsloth/Qwen3.5-0.8B.
The adapter was trained with Unsloth and TRL on Vietnamese handwriting OCR data. It expects an image prompt and returns the visible text, preserving line breaks when possible.
Load With Unsloth
from unsloth import FastVisionModel
model, tokenizer = FastVisionModel.from_pretrained(
model_name="tungedng2710/cogniocr",
max_seq_length=2048,
load_in_4bit=False,
load_in_16bit=True,
)
Training
- Base model:
unsloth/Qwen3.5-0.8B - Adapter type: LoRA
- LoRA rank: 16
- LoRA alpha: 16
- LoRA dropout: 0
- Fine-tuned layers: vision layers, language layers, attention modules, and MLP modules
Framework Versions
- PEFT 0.18.1
- TRL 0.24.0
- Transformers 5.7.0
- PyTorch 2.9.0
- Datasets 4.3.0
- Tokenizers 0.22.2
Example Usage
from pathlib import Path
from predict import (
OCR_PROMPT,
build_inputs,
decode_new_tokens,
load_image,
)
SCRIPT_DIR = Path(__file__).resolve().parent
MODEL_ID = "tungedng2710/cogniocr"
IMAGE_PATH = SCRIPT_DIR / "test1.png"
MAX_SEQ_LENGTH = 2048
MAX_NEW_TOKENS = 512
def main():
try:
import torch
from unsloth import FastVisionModel, is_bfloat16_supported
except ImportError as exc:
raise SystemExit(
"Missing dependency: unsloth/torch. Install the VLM dependencies first:\n"
" pip install --upgrade --force-reinstall --no-cache-dir unsloth "
"unsloth_zoo\n"
" pip install -U torch pillow torchvision"
) from exc
image = load_image(IMAGE_PATH)
dtype = torch.bfloat16 if is_bfloat16_supported() else torch.float16
print(f"Loading model: {MODEL_ID}")
model, tokenizer = FastVisionModel.from_pretrained(
model_name=MODEL_ID,
max_seq_length=MAX_SEQ_LENGTH,
dtype=dtype,
load_in_4bit=False,
load_in_16bit=True,
)
FastVisionModel.for_inference(model)
device = next(model.parameters()).device
inputs = build_inputs(tokenizer, image, OCR_PROMPT, device)
prompt_token_count = inputs["input_ids"].shape[-1]
with torch.inference_mode():
outputs = model.generate(
**inputs,
max_new_tokens=MAX_NEW_TOKENS,
use_cache=True,
do_sample=False,
)
text = decode_new_tokens(tokenizer, outputs, prompt_token_count)
print("\nOCR result:")
print(text)
if __name__ == "__main__":
main()
- Downloads last month
- 34