import torchfrom PIL import Imagefrom transformers import AutoModelForImageTextToText, AutoProcessor model_id = "flintglass/PrismParse-2B"processor = AutoProcessor.from_pretrained(model_id)model = AutoModelForImageTextToText.from_pretrained( model_id, torch_dtype=torch.bfloat16, device_map="auto") image = Image.open("receipt.jpg").convert("RGB")prompt = ( "Extract all structured fields from this receipt image as a single valid JSON object " "(with keys such as menu, sub_total, total). Output ONLY valid JSON with no markdown or extra text.") messages = [{"role": "user", "content": [{"type": "image", "image": image}, {"type": "text", "text": prompt}]}]inputs = processor.apply_chat_template( messages, tokenize=True, add_generation_prompt=True, return_dict=True, return_tensors="pt", enable_thinking=False).to(model.device) out = model.generate(**inputs, max_new_tokens=1024, do_sample=False)print(processor.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))