File size: 822 Bytes
9894cf3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279ee92
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import gradio as gr
import argparse
import torch
from PIL import Image
from donut import DonutModel
def demo_process(input_img):
    global model, task_prompt, task_name
    input_img = Image.fromarray(input_img)
    output = model.inference(image=input_img, prompt=task_prompt)["predictions"][0]
    return output
parser = argparse.ArgumentParser()
parser.add_argument("--task", type=str, default="Booking")
parser.add_argument("--pretrained_path", type=str, default="uartimcs/donut-booking-extract")
args, left_argv = parser.parse_known_args()
task_name = args.task
task_prompt = f"<s_{task_name}>"
model = DonutModel.from_pretrained("uartimcs/donut-booking-extract")
model.eval()
demo = gr.Interface(fn=demo_process,inputs="image",outputs="json", title=f"Donut 🍩 demonstration for `{task_name}` task",)
demo.launch()