Spaces:
Build error
Build error
| 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") | |
| prompts = [ | |
| "What does this image say?", | |
| "Describe this image", | |
| "Extract all text from this image", | |
| "Read the text in this screenshot", | |
| "Transcribe the text", | |
| ] | |
| for p in prompts: | |
| payload = { | |
| "model": "moondream", | |
| "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!r}") | |
| print(f" Response: {res.get('response', '')[:200]!r}") | |
| print(f" Done: {res.get('done_reason')}, Eval: {res.get('eval_count')}") | |
| print() | |