Input and results
This commit is contained in:
15
check_connection.py
Normal file
15
check_connection.py
Normal file
@ -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"])
|
||||||
BIN
images/a.jpeg
Normal file
BIN
images/a.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
BIN
images/b.jpg
Normal file
BIN
images/b.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.0 KiB |
14
main.py
14
main.py
@ -2,7 +2,7 @@ from pathlib import Path
|
|||||||
import base64
|
import base64
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
OLLAMA_URL = "http://localhost:11434/api/chat"
|
OLLAMA_URL = "http://127.0.0.1:11434/api/chat"
|
||||||
MODEL = "llama3.2-vision"
|
MODEL = "llama3.2-vision"
|
||||||
IMAGE_EXTS = {".png", ".jpg", ".jpeg", ".webp", ".bmp", ".gif"}
|
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()
|
r.raise_for_status()
|
||||||
data = r.json()
|
data = r.json()
|
||||||
|
print(data)
|
||||||
return data.get("message", {}).get("content", "").strip()
|
return data.get("message", {}).get("content", "").strip()
|
||||||
|
|
||||||
def process_folder(folder: str):
|
def process_folder(folder: str, result : str):
|
||||||
folder_path = Path(folder)
|
folder_path = Path(folder)
|
||||||
|
result_path = Path(result)
|
||||||
for img in folder_path.iterdir():
|
for img in folder_path.iterdir():
|
||||||
if img.is_file() and img.suffix.lower() in IMAGE_EXTS:
|
if img.is_file() and img.suffix.lower() in IMAGE_EXTS:
|
||||||
print(f"Processing: {img.name}")
|
print(f"Processing: {img.name}")
|
||||||
text = ocr_image(img)
|
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__":
|
if __name__ == "__main__":
|
||||||
process_folder("kepek")
|
process_folder("images", "output")
|
||||||
1
output/a.txt
Normal file
1
output/a.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
The text in the image is: "Because be doing".
|
||||||
1
output/b.txt
Normal file
1
output/b.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
The text in the image is "Congratulations".
|
||||||
Reference in New Issue
Block a user