Working with the Mistral OCR and Mistral Doc query
Learn how to use the Mistral OCR and Mistral Doc query in Taskmonk.
Mistral OCR
Mistral OCR is a processor that uses Optical Character Recognition (OCR) to extract raw text from scanned documents or images. It is the first step in processing image-based files by converting visual data (like printed or handwritten text) into machine-readable text, enabling further analysis or data extraction.
Mistral OCR Configuration in input fields.
Mistral OCR output field configuration.
Mistral configuration in advanced settings.
Category: Document AI – Indicates the type of automation used
Select input field containing image path: ImageURL – Points to the field that contains the URL/path of the image to be processed.
Select the document type: Image/PDF - Specifies the format
Select a field to store OCR text: annotation - Field where the OCR output (recognized text) will be stored.
Custom code can be written to render the recognized text dynamically in the designated output fields. The below snippet of code needs to be added into On Load code under Advanced Settings → Custom Code
Sample custom code:
const text = inputValues["annotation"];
const PanNumber = (text.match(/\b[A-Z]{5}[0-9]{4}[A-Z]\b/) || [])[0] || "";
const DOB = (text.match(/\b\d{2}[\/\-\.]\d{2}[\/\-\.]\d{4}\b/) || [])[0] || "";
let Name = "";
const lines = text.split(/\n|#+|\*\*/).map(l => l.trim()).filter(Boolean);
const start = lines.findIndex(l => /income tax department/i.test(l));
if (start !== -1) {
for (let i = start + 1; i < lines.length; i++) {
const l = lines[i];
if (/^[A-Z][A-Z\s\.]*[A-Z]$/.test(l) && !/GOVT|PERMANENT|ACCOUNT/i.test(l)) {
Name = l;
break;
}
}
}
this.changeFormValue("Name", Name);
this.changeFormValue("PanNumber", PanNumber);
this.changeFormValue("DOB", DOB);
Task Page
Task page for PDF
Mistral Document Query
Mistral Document Query enables users to extract information from scanned or unstructured documents using AI-powered natural language understanding, all through a simple prompt.
Mistral Document Query Configuration in input fields.
Mistral Document Query Configuration in output fields.
Mistral Document Query configuration in advanced settings.
Category: Document AI – Indicates the type of automation used
Select input field containing image path: Image – Points to the field that contains the URL/path of the image to be processed.
Select the document type: Image/PDF - Specifies the document format/type.
Enter the prompt to extract information from the document: Extract Name, DOB from the image-Prompt to extract required text from the document.
Select a field to store OCR text: Input Text- Field where the recognized text will be stored.
Custom code is used to render the recognized text dynamically into the designated output fields.
Sample custom code:
let text = inputValues["Input Text"];
const cleanValue = (value) => value.replace(/\*/g, '').trim();
const lines = text.split('\n').map(line => line.trim());
let fullname = 'Not Found';
let dob = 'Not Found';
for (let i = 0; i < lines.length; i++) {
if (/Primary Name:/i.test(lines[i])) {
fullname= cleanValue(lines[i].split(':')[1]);
}
if (/Date of Birth \(DOB\)/i.test(lines[i]) && i + 1 < lines.length) {
dob = cleanValue(lines[i + 1].replace(/^-/, '').trim());
}
}
this.changeFormValue("Name", fullname);
this.changeFormValue("DOB", dob);
Task page.
Task page for PDF.
© 2020 Taskmonk Technology Pvt. Ltd. All Rights Reserved .