from __future__ import annotations import json import urllib.request import base64 import sys b64 = base64.b64encode(open(r"C:\Users\Ramakrishna\OneDrive\Desktop\pageparse\pageparse\image.png", "rb").read()).decode("utf-8") prompt = "Read all text in this image. Return ONLY the exact text you see, preserving all words, punctuation and line breaks. Do NOT add any explanation or commentary." payload = { "model": "llava:7b", "prompt": prompt, "images": [b64], "stream": False, "options": {"temperature": 0.0}, } data = json.dumps(payload).encode("utf-8") req = urllib.request.Request( "http://localhost:11434/api/generate", data=data, headers={"Content-Type": "application/json"}, ) sys.stderr.write("Sending request to llava:7b...\n") with urllib.request.urlopen(req, timeout=600) as resp: res = json.loads(resp.read().decode("utf-8")) sys.stderr.write("Done.\n") resp_text = res.get("response", "") print(resp_text) print(f"\n--- Stats: done={res.get('done_reason')}, eval_count={res.get('eval_count')}, duration_ns={res.get('total_duration')}", file=sys.stderr)