diff --git a/check_connection.py b/check_connection.py new file mode 100644 index 0000000..bc54bfb --- /dev/null +++ b/check_connection.py @@ -0,0 +1,15 @@ +import requests + +url = "http://127.0.0.1:11434/api/generate" + +payload = { + "model": "llama3.2-vision", + "prompt": "Csak ezt írd vissza: ok", + "stream": False +} + +r = requests.post(url, json=payload, timeout=60) +r.raise_for_status() + +data = r.json() +print(data["response"]) \ No newline at end of file diff --git a/images/a.jpeg b/images/a.jpeg new file mode 100644 index 0000000..939ea6c Binary files /dev/null and b/images/a.jpeg differ diff --git a/images/b.jpg b/images/b.jpg new file mode 100644 index 0000000..5b7b609 Binary files /dev/null and b/images/b.jpg differ diff --git a/main.py b/main.py index ea5aa13..8d5b3c8 100644 --- a/main.py +++ b/main.py @@ -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") \ No newline at end of file + process_folder("images", "output") \ No newline at end of file diff --git a/output/a.txt b/output/a.txt new file mode 100644 index 0000000..cae747b --- /dev/null +++ b/output/a.txt @@ -0,0 +1 @@ +The text in the image is: "Because be doing". \ No newline at end of file diff --git a/output/b.txt b/output/b.txt new file mode 100644 index 0000000..908dc19 --- /dev/null +++ b/output/b.txt @@ -0,0 +1 @@ +The text in the image is "Congratulations". \ No newline at end of file