File size: 968 Bytes
4ace749 0afc153 4ace749 77a91d3 4ace749 77a91d3 4ace749 77a91d3 4ace749 77a91d3 0afc153 77a91d3 bb81887 0afc153 818bbf4 77a91d3 818bbf4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
"""
Donut
Copyright (c) 2022-present NAVER Corp.
MIT License
https://github.com/clovaai/donut
"""
import gradio as gr
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"<s_cord-v2>"
image = Image.open("./sample_image_cord_test_receipt_00004.jpg")
image.save("cord_sample_receipt.jpg")
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"Donut 🍩 demonstration for `cord-v2` task",
examples=[["cord_sample_receipt.jpg"]],
cache_examples=False,
)
demo.launch()
|