39474-vm/backend/app/services/ocr_service.py
2026-04-04 22:08:49 +05:00

16 lines
443 B
Python

import pytesseract
from PIL import Image
import io
class OCRService:
@staticmethod
def extract_text(file_bytes: bytes) -> str:
try:
image = Image.open(io.BytesIO(file_bytes))
# Require both RU and KZ, ENG fallback
text = pytesseract.image_to_string(image, lang="rus+kaz+eng")
return text
except Exception as e:
print(f"OCR Error: {e}")
return ""