RPA.DocumentAI.Nanonets
Get all available models related to the API key.
return: | object containing available models |
---|
Robot Framework example:
${models}= Get All Models
FOR ${model} IN @{models}
Log To Console Model ID: ${model}[model_id]
Log To Console Model Type: ${model}[model_type]
END
Python example:
models = nanolib.get_all_models()
for model in models:
print(f"model id: {model['model_id']}")
print(f"model type: {model['model_type']}")
Helper keyword to get found fields from a prediction result.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
prediction | Dict[Hashable, str | int | float | bool | list | dict | None], List[str | int | float | bool | list | dict | None], str, int, float, bool, list, dict, None | null | prediction result dictionary |
For example. see Predict File keyword
param prediction: | |
---|---|
prediction result dictionary | |
return: | list of found fields |
Helper keyword to get found tables from a prediction result.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
prediction | Dict[Hashable, str | int | float | bool | list | dict | None], List[str | int | float | bool | list | dict | None], str, int, float, bool, list, dict, None | null | prediction result dictionary |
For another example. see Predict File keyword
param prediction: | |
---|---|
prediction result dictionary | |
return: | list of found tables |
Robot Framework example:
# It is possible to create `RPA.Tables` compatible tables from the result
${tables}= Get Tables From Prediction Result ${result}
FOR ${table} IN @{tables}
${rpatable}= Create Table ${table}[rows]
FOR ${row} IN @{rpatable}
Log To Console ${row}
END
END
Python example:
# It is possible to create `RPA.Tables` compatible tables from the result
tables = nanolib.get_tables_from_prediction_result(result)
for table in tables:
rpatable = Tables().create_table(table["rows"])
for row in rpatable:
print(row)
OCR fulltext a given file. Returns words and full text.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
filename | str | null | name of the file |
filepath | str | null | path of the file |
Filename and filepath needs to be given separately.
param filename: | name of the file |
---|---|
param filepath: | path of the file |
return: | the result in a list format |
Robot Framework example:
${results}= OCR Fulltext
... invoice.pdf
... ${CURDIR}${/}invoice.pdf
FOR ${result} IN @{results}
Log To Console Filename: ${result}[filename]
FOR ${pagenum} ${page} IN ENUMERATE @{result.pagedata} start=1
Log To Console Page ${pagenum} raw Text: ${page}[raw_text]
END
END
Python example:
results = nanolib.ocr_fulltext("IMG_8277.jpeg", "./IMG_8277.jpeg")
for result in results:
print(f"FILENAME: {result['filename']}")
for page in result["page_data"]:
print(f"Page {page['page']+1}: {page['raw_text']}")
Get prediction result for a file by a given model id.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
filepath | str | null | filepath to the file |
model_id | str | null | id of the Nanonets model to categorize a file |
param filepath: | filepath to the file |
---|---|
param model_id: | id of the Nanonets model to categorize a file |
return: | the result in a list format |
Robot Framework example:
${result}= Predict File ./document.pdf ${MODEL_ID}
${fields}= Get Fields From Prediction Result ${result}
FOR ${field} IN @{fields}
Log To Console Label:${field}[label] Text:${field}[ocr_text]
END
${tables}= Get Tables From Prediction Result ${result}
FOR ${table} IN @{tables}
FOR ${rows} IN ${table}[rows]
FOR ${row} IN @{rows}
${cells}= Evaluate [cell['text'] for cell in $row]
Log To Console ROW:${{" | ".join($cells)}}
END
END
END
Python example:
result = nanolib.predict_file("./docu.pdf", secrets["receipts-model-id"])
fields = nanolib.get_fields_from_prediction_result(result)
for field in fields:
print(f"Label: {field['label']} Text: {field['ocr_text']}")
tables = nanolib.get_tables_from_prediction_result(result)
for table in tables:
for row in table["rows"]:
cells = [cell["text"] for cell in row]
print(f"ROW: {' | '.join(cells)}")
Set Nanonets request headers with key related to API.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
apikey | str | null | key related to the API |
param apikey: | key related to the API |
---|
Robot Framework example:
${secrets}= Get Secret nanonets-auth
Set Authorization ${secrets}[apikey]
Python example:
secrets = Vault().get_secret("nanonets-auth")
nanolib = Nanonets()
nanolib.set_authorization(secrets["apikey"])