Files
julius_baer_onboarding/utils/parsers/passport_parser.py

22 lines
632 B
Python
Raw Permalink Normal View History

2025-04-13 08:03:45 +02:00
import os
from mistralai import Mistral
api_key = "XEOc110BYE4PMj8FQBauxxGZTitRTs2w"
client = Mistral(api_key=api_key)
2025-04-12 10:51:07 +02:00
2025-04-13 08:03:45 +02:00
def process_passport(passport_b64: str) -> str:
mistral_image_url = f"data:image/png;base64,{passport_b64}"
2025-04-12 20:31:20 +02:00
2025-04-13 08:03:45 +02:00
ocr_response = client.ocr.process(
model="mistral-ocr-latest",
document={
"type": "image_url",
"image_url": mistral_image_url
2025-04-12 22:29:54 +02:00
}
2025-04-13 08:03:45 +02:00
)
# Extraire le markdown de toutes les pages
markdown_text = "\n\n".join(page.markdown for page in ocr_response.pages)
return markdown_text # Tu peux aussi retourner juste le chemin si tu préfères