from PIL import Imagefrom transformers import AutoProcessorfrom vllm import LLM, SamplingParams MODEL_ID = "ebinan92/Rukopys-OCR-4B"PROMPT = ( "Detect every text region in this Ukrainian handwritten document and " "return a JSON array of regions. Each region has bbox (x1 y1 x2 y2 in " "0..1000 normalized image coordinates), type (handwritten | printed | " "formula | table | annotation | image | graph), and text (transcription; " "empty for image/graph; LaTeX for formula; pipe-separated for table).") processor = AutoProcessor.from_pretrained(MODEL_ID)image = Image.open("document.jpg").convert("RGB")messages = [{ "role": "user", "content": [ {"type": "image", "image": image}, {"type": "text", "text": PROMPT}, ],}]prompt = processor.apply_chat_template( messages, tokenize=False, add_generation_prompt=True, enable_thinking=False) factor = processor.image_processor.patch_size * processor.image_processor.merge_sizellm = LLM( model=MODEL_ID, dtype="bfloat16", max_model_len=16384, limit_mm_per_prompt={"image": 1}, mm_processor_kwargs={ "min_pixels": 256 * factor * factor, "max_pixels": 4096 * factor * factor, },)params = SamplingParams(max_tokens=8192, temperature=0.0)outputs = llm.generate( [{"prompt": prompt, "multi_modal_data": {"image": image}}], sampling_params=params,)print(outputs[0].outputs[0].text)