How to use from the
Use from the
Transformers library
# Use a pipeline as a high-level helper
# Warning: Pipeline type "image-to-text" is no longer supported in transformers v5.
# You must load the model directly (see below) or downgrade to v4.x with:
# 'pip install "transformers<5.0.0'
from transformers import pipeline

pipe = pipeline("image-to-text", model="syubraj/TrOCR_Nepali")
# Load model directly
from transformers import AutoTokenizer, AutoModelForMultimodalLM

tokenizer = AutoTokenizer.from_pretrained("syubraj/TrOCR_Nepali")
model = AutoModelForMultimodalLM.from_pretrained("syubraj/TrOCR_Nepali", device_map="auto")
Quick Links

Devanagari OCR with TrOCR

This model is a Devanagari Optical Character Recognition (OCR) model based on VisionEncoderDecoder architecture, fine-tuned on Nepali/Devanagari script. The model uses the TrOCRProcessor from Hugging Face to process and generate text from images.

Model Details

  • Model: syubraj/TrOCR_Nepali
  • Processor: TrOCRProcessor combining a Vision Transformer (ViT) feature extractor and a tokenizer.

How to Use

You can use this model in Python with the following steps:

from transformers import VisionEncoderDecoderModel, TrOCRProcessor, AutoTokenizer
from PIL import Image
import torch

# Load the model and processor
tokenizer = AutoTokenizer.from_pretrained("syubraj/TrOCR_Nepali")
model = VisionEncoderDecoderModel.from_pretrained("syubraj/TrOCR_Nepali")
processor = TrOCRProcessor.from_pretrained("syubraj/TrOCR_Nepali")

# Load image
image = Image.open("path_to_image").convert("RGB")

# Preprocess image
pixel_values = processor(image, return_tensors="pt").pixel_values

# Generate text
generated_ids = model.generate(pixel_values)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]

print(generated_text)
Downloads last month
144
Safetensors
Model size
0.2B params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Space using syubraj/TrOCR_Nepali 1