OCR de imagenes con Mistral: ImageProcessor (png/jpg/webp/gif/bmp/tiff), modelo mistral-ocr-latest y recuperacion de fuentes unknown
This commit is contained in:
@@ -36,6 +36,17 @@ class MistralClient:
|
||||
files_url = f"{base_url}/files"
|
||||
batch_url = f"{base_url}/batch/jobs"
|
||||
|
||||
_IMAGE_MIME_BY_EXT = {
|
||||
".png": "image/png",
|
||||
".jpg": "image/jpeg",
|
||||
".jpeg": "image/jpeg",
|
||||
".webp": "image/webp",
|
||||
".gif": "image/gif",
|
||||
".bmp": "image/bmp",
|
||||
".tif": "image/tiff",
|
||||
".tiff": "image/tiff",
|
||||
}
|
||||
|
||||
def __init__(self) -> None:
|
||||
self._api_key = settings.mistral_api_key
|
||||
self._model = settings.mistral_ocr_model
|
||||
@@ -285,4 +296,5 @@ class MistralClient:
|
||||
|
||||
def _image_data_url(self, image_path: Path) -> str:
|
||||
encoded = base64.b64encode(image_path.read_bytes()).decode("ascii")
|
||||
return f"data:image/jpeg;base64,{encoded}"
|
||||
mime = self._IMAGE_MIME_BY_EXT.get(image_path.suffix.lower(), "image/jpeg")
|
||||
return f"data:{mime};base64,{encoded}"
|
||||
|
||||
Reference in New Issue
Block a user