sav7669 commited on
Commit
0d50de7
1 Parent(s): 8d51bd5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Donut
3
+ Copyright (c) 2022-present NAVER Corp.
4
+ MIT License
5
+ https://github.com/clovaai/donut
6
+ """
7
+ import gradio as gr
8
+ import torch
9
+ from PIL import Image
10
+
11
+ from donut import DonutModel
12
+ from transformers import DonutProcessor, VisionEncoderDecoderModel
13
+
14
+ def demo_process(input_img):
15
+ global pretrained_model, task_prompt, task_name
16
+ # input_img = Image.fromarray(input_img)
17
+ output = pretrained_model.inference(image=input_img, prompt=task_prompt)["predictions"][0]
18
+ return output
19
+
20
+ task_prompt = f"<s_cord-v2>"
21
+
22
+ image = Image.open("./sample_image_cord_test_receipt_00004.png")
23
+ image.save("cord_sample_receipt1.png")
24
+ image = Image.open("./sample_image_cord_test_receipt_00012.png")
25
+ image.save("cord_sample_receipt2.png")
26
+ image = Image.open("./000.jpg")
27
+ image.save("csroie_test1.jpg")
28
+ image = Image.open("./001.jpg")
29
+ image.save("sroie_test2.jpg")
30
+
31
+ pretrained_model = DonutModel.from_pretrained("sav7669/donut-base-sroie")
32
+ model = VisionEncoderDecoderModel.from_pretrained("sav7669/donut-base-sroie")
33
+ model.eval()
34
+
35
+ demo = gr.Interface(
36
+ fn=demo_process,
37
+ inputs= gr.inputs.Image(type="pil"),
38
+ outputs="json",
39
+ title=f"Donut 🍩 demonstration for `cord-v2` task",
40
+ description="""This model is trained with 800 Indonesian receipt images of CORD dataset. <br>
41
+ Demonstrations for other types of documents/tasks are available at https://github.com/clovaai/donut <br>
42
+ More CORD receipt images are available at https://huggingface.co/datasets/naver-clova-ix/cord-v2
43
+ More details are available at:
44
+ - Paper: https://arxiv.org/abs/2111.15664
45
+ - GitHub: https://github.com/clovaai/donut""",
46
+ examples=[["cord_sample_receipt1.png"], ["cord_sample_receipt2.png"]],
47
+ cache_examples=False,
48
+ )