Views
No views yet
1from transformers import AutoProcessor, AutoModelForImageTextToText
2from peft import PeftModel
3import torch
4from PIL import Image
5
6processor = AutoProcessor.from_pretrained("Qwen/Qwen3.5-4B", trust_remote_code=True)
7model = AutoModelForImageTextToText.from_pretrained(
8 "Qwen/Qwen3.5-4B", torch_dtype=torch.bfloat16, device_map="auto", trust_remote_code=True
9)
10model = PeftModel.from_pretrained(model, "Pritosh/odia-ocr-rft-v1")
11
12image = Image.open("odia_page.jpg")
13messages = [
14 {"role": "system", "content": [{"type": "text", "text": "You are an OCR engine specialized in Odia (ଓଡ଼ିଆ) script. Output the exact Odia text visible in the image. Do not add any explanation or translation."}]},
15 {"role": "user", "content": [{"type": "image", "image": image}, {"type": "text", "text": "Extract all Odia text from this image."}]},
16]
17text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)
18inputs = processor(text=[text], images=[image], return_tensors="pt").to(model.device)
19output = model.generate(**inputs, max_new_tokens=512)
20result = processor.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
21print(result)