Input and results

This commit is contained in:
2026-05-16 16:20:12 +02:00
parent 27783e7efb
commit b24657e7bf
6 changed files with 26 additions and 5 deletions

14
main.py
View File

@ -2,7 +2,7 @@ from pathlib import Path
import base64
import requests
OLLAMA_URL = "http://localhost:11434/api/chat"
OLLAMA_URL = "http://127.0.0.1:11434/api/chat"
MODEL = "llama3.2-vision"
IMAGE_EXTS = {".png", ".jpg", ".jpeg", ".webp", ".bmp", ".gif"}
@ -28,18 +28,22 @@ def ocr_image(path: Path) -> str:
}
]
}
r = requests.post(OLLAMA_URL, json=payload, timeout=300)
r = requests.post(OLLAMA_URL, json=payload, timeout=900000)
r.raise_for_status()
data = r.json()
print(data)
return data.get("message", {}).get("content", "").strip()
def process_folder(folder: str):
def process_folder(folder: str, result : str):
folder_path = Path(folder)
result_path = Path(result)
for img in folder_path.iterdir():
if img.is_file() and img.suffix.lower() in IMAGE_EXTS:
print(f"Processing: {img.name}")
text = ocr_image(img)
img.with_suffix(".txt").write_text(text, encoding="utf-8")
out_file = result_path / f"{img.stem}.txt"
out_file.write_text(text, encoding="utf-8")
if __name__ == "__main__":
process_folder("kepek")
process_folder("images", "output")