""" Donut Copyright (c) 2022-present NAVER Corp. MIT License https://github.com/clovaai/donut """ import gradio as gr import os import logging import torch from PIL import Image from donut import DonutModel def demo_process(input_img): global pretrained_model, task_prompt, task_name # input_img = Image.fromarray(input_img) output = pretrained_model.inference(image=input_img, prompt=task_prompt)["predictions"][0] return output task_prompt = f"" pretrained_model = DonutModel.from_pretrained("naver-clova-ix/donut-base-finetuned-cord-v2") pretrained_model.encoder.to(torch.bfloat16) pretrained_model.eval() demo = gr.Interface( fn=demo_process, inputs= gr.inputs.Image(type="pil"), outputs="json", title=f"Demo for `cord-v2` task", description=f"Description for `cord-v2` task", cache_examples=False, ) demo.launch()