Spaces:
Build error
Build error
File size: 1,280 Bytes
8c3e275 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | from __future__ import annotations
import json
import urllib.request
import base64
b64 = base64.b64encode(open(r"C:\Users\Ramakrishna\OneDrive\Desktop\pageparse\pageparse\image.png", "rb").read()).decode("utf-8")
prompts = [
"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.",
"Transcribe EXACTLY every character of text shown in this image. Do not describe or summarize. Output only the raw text.",
"What text is shown in this image? Output only the text content.",
]
for p in prompts:
payload = {
"model": "llava:7b",
"prompt": p,
"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"},
)
with urllib.request.urlopen(req, timeout=300) as resp:
res = json.loads(resp.read().decode("utf-8"))
print(f"Prompt: {p[:60]!r}...")
print(f" Response: {res.get('response', '')[:500]!r}")
print(f" Done: {res.get('done_reason')}, Eval: {res.get('eval_count')}")
print()
|