from transformers import TrOCRProcessor, AutoTokenizer, ViTFeatureExtractor, VisionEncoderDecoderModel

encode = 'rushai-dev/THAI-TrOCR'
decode = "xlm-roberta-base"

tokenizer = AutoTokenizer.from_pretrained(decode)
feature_extractor = ViTFeatureExtractor.from_pretrained(encode)
processor = TrOCRProcessor(feature_extractor=feature_extractor, tokenizer=tokenizer)
model = VisionEncoderDecoderModel.from_pretrained(encode)
from PIL import Image
image = Image.open("xxxxxxx.png").convert("RGB")
image
pixel_values = processor(image, return_tensors="pt").pixel_values
generated_ids = model.generate(pixel_values)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
generated_text