from transformers import AutoModelForImageTextToText, AutoProcessorfrom PIL import Image model = AutoModelForImageTextToText.from_pretrained( "nanash66/typhoon-ocr1.5-2b-NVFP4", dtype="auto", device_map="auto",)processor = AutoProcessor.from_pretrained("nanash66/typhoon-ocr1.5-2b-NVFP4") # Load imageimg = Image.open("image.png") # IMPORTANT: The model was trained at a fixed image dimension of 1800px.# Resize the image before inference.def resize_if_needed(img, max_size=1800): if max(img.size) > max_size: scale = max_size / max(img.size) img = img.resize((int(img.width * scale), int(img.height * scale))) return img img = resize_if_needed(img, 1800) messages = [ { "role": "user", "content": [ {"type": "image", "image": img}, {"type": "text", "text": prompt}, ], }] # Preparation for inferenceinputs = processor.apply_chat_template( messages, tokenize=True, add_generation_prompt=True, return_dict=True, return_tensors="pt",).to(model.device) # Inferencegenerated_ids = model.generate(**inputs, max_new_tokens=10000)generated_ids_trimmed = [ out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]output_text = processor.batch_decode( generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False,)print(output_text[0])