add pyinfra_compat.py

This commit is contained in:
Isaac Riley 2022-06-20 13:48:16 +02:00
parent b66a7f15e1
commit 268329a57f

View File

@ -13,20 +13,21 @@ task_dict = {
}
def analyze_byteslist(img_bytes_list, task="table"):
def analyze_bytes(img_bytes, page_num, task="table"):
analysis_function = task_dict[task]
page = open_img_from_bytes(img_bytes)
cells = list(map(lambda x: x.json_xywh(), analysis_function(page)))
page_dict = {
"page": page_num,
"pageWidth": page.shape[1],
"pageHeight": page.shape[0],
"cells": cells
}
return page_dict
def analyze_bytes_list(img_bytes_list, task="table"):
result = []
for i, img_bytes in enumerate(img_bytes_list):
page = open_img_from_bytes(img_bytes)
cells = list(map(lambda x: x.json_xywh(), analysis_function(page)))
page_dict = {
"page": i,
"pageWidth": page.shape[1],
"pageHeight": page.shape[0],
"cells": cells
}
result.append(page_dict)
result.append(analyze_bytes(img_bytes, i, task=task))
return result