to-be commited on
Commit
4159b3a
1 Parent(s): da1eb56

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
13
+ def demo_process(input_img):
14
+ global pretrained_model, task_prompt, task_name
15
+ # input_img = Image.fromarray(input_img)
16
+ output = pretrained_model.inference(image=input_img, prompt=task_prompt)["predictions"][0]
17
+ return output
18
+
19
+ task_prompt = f"<s_cord-v2>"
20
+
21
+ image = Image.open("./sample_image_cord_test_receipt_00004.png")
22
+ image.save("cord_sample_receipt1.png")
23
+ image = Image.open("./sample_image_cord_test_receipt_00012.png")
24
+ image.save("cord_sample_receipt2.png")
25
+
26
+ pretrained_model = DonutModel.from_pretrained("to-be/ID_cards_v1")
27
+ pretrained_model.eval()
28
+
29
+ demo = gr.Interface(
30
+ fn=demo_process,
31
+ inputs= gr.inputs.Image(type="pil"),
32
+ outputs="json",
33
+ title=f"Donut 🍩 demonstration for `cord-v2` task",
34
+ description="""This model is trained with 800 Indonesian receipt images of CORD dataset. <br>
35
+ Demonstrations for other types of documents/tasks are available at https://github.com/clovaai/donut <br>
36
+ More CORD receipt images are available at https://huggingface.co/datasets/naver-clova-ix/cord-v2
37
+ More details are available at:
38
+ - Paper: https://arxiv.org/abs/2111.15664
39
+ - GitHub: https://github.com/clovaai/donut""",
40
+ examples=[["cord_sample_receipt1.png"], ["cord_sample_receipt2.png"]],
41
+ cache_examples=False,
42
+ )
43
+
44
+ demo.launch()