in demo_app/demo_app.py [0:0]
def form_ext_w_conf_upload(file: str):
if file is None:
gr.Warning(
"Please select or upload a PDF/image file, then click 'Process File'."
)
return ("", "", None, {})
# Get response from the API
mime_type = mimetypes.guess_type(file)[0]
with open(file, "rb") as f:
data = f.read()
headers = {"Content-Type": mime_type}
(
status_code,
client_side_time_taken,
response_content,
) = send_request(
route="form_extraction_with_confidence",
data=data,
headers=headers,
force_json_content_type=True, # JSON gradio block requires this
)
# Extract the image with bounding boxes from the result
if isinstance(response_content, dict) and response_content.get(
"result_img_with_bboxes"
):
result_img = gr.Image(
value=Image.open(
BytesIO(
base64.b64decode(response_content.pop("result_img_with_bboxes"))
)
),
height=600,
width=750,
visible=True,
)
else:
result_img = gr.Image(value=None, visible=False)
return (
status_code,
client_side_time_taken,
result_img,
response_content,
)