File size: 1,753 Bytes
0d50de7
 
 
 
 
 
 
 
 
 
 
 
 
d34aac7
0d50de7
 
 
a92be85
0d50de7
 
 
 
 
 
 
 
 
ef93003
0d50de7
 
 
f366d31
a92be85
 
 
0d50de7
 
 
 
 
 
 
 
 
 
 
 
ef93003
0d50de7
 
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
39
40
41
42
43
44
45
46
47
48
49
50
"""
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
from transformers import DonutProcessor, VisionEncoderDecoderModel


def demo_process(input_img):
    global pretrained_model, task_prompt, task_name
    # input_img = Image.fromarray(input_img)
    output = 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.png")
image.save("cord_sample_receipt1.png")
image = Image.open("./sample_image_cord_test_receipt_00012.png")
image.save("cord_sample_receipt2.png")
image = Image.open("./000.jpg")
image.save("sroie_test1.jpg")
image = Image.open("./001.jpg")
image.save("sroie_test2.jpg")

#philschmid
#pretrained_model = DonutModel.from_pretrained("philschmid/donut-base-sroie")
model = VisionEncoderDecoderModel.from_pretrained("philschmid/donut-base-sroie")
model.eval()

demo = gr.Interface(
    fn=demo_process,
    inputs= gr.inputs.Image(type="pil"),
    outputs="json",
    title=f"Donut 🍩 demonstration for `cord-v2` task",
    description="""This model is trained with 800 Indonesian receipt images of CORD dataset. <br>
Demonstrations for other types of documents/tasks are available at https://github.com/clovaai/donut <br>
More CORD receipt images are available at https://huggingface.co/datasets/naver-clova-ix/cord-v2
More details are available at:
- Paper: https://arxiv.org/abs/2111.15664
- GitHub: https://github.com/clovaai/donut""",
    examples=[["cord_sample_receipt1.png"], ["cord_sample_receipt2.png"],["sroie_test1.jpg"],["sroie_test2.jpg"],],
    cache_examples=False,
)