!pip install transformers from transformers import TrOCRProcessor, VisionEncoderDecoderModel from PIL import Image import requests url = 'https://fki.tic.heia-fr.ch/static/img/a01-122-02-00.jpg' processor = TrOCRProcessor.from_pretrained('JerryWu/trocr-printed-model') model = VisionEncoderDecoderModel.from_pretrained('JerryWu/trocr-printed-model') pixel_values = processor(images=image, return_tensors="pt").pixel_values image = Image.open(requests.get(url, stream=True).raw).convert("RGB") generated_ids = model.generate(pixel_values) generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0] print(generated_text)