thinh-researcher commited on
Commit
f0dbcbc
β€’
1 Parent(s): 7a90443
Files changed (2) hide show
  1. app.py +5 -5
  2. receipts_app.py +51 -0
app.py CHANGED
@@ -19,10 +19,10 @@ def demo_process(input_img):
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
 
27
  pretrained_model = DonutModel.from_pretrained("naver-clova-ix/donut-base-finetuned-cord-v2")
28
  # pretrained_model: DonutModel = DonutModel.from_pretrained("result", local_files_only=True)
@@ -40,7 +40,7 @@ More CORD receipt images are available at https://huggingface.co/datasets/naver-
40
  More details are available at:
41
  - Paper: https://arxiv.org/abs/2111.15664
42
  - GitHub: https://github.com/clovaai/donut""",
43
- examples=[["cord_sample_receipt1.png"], ["cord_sample_receipt2.png"]],
44
  cache_examples=False,
45
  )
46
 
 
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
 
27
  pretrained_model = DonutModel.from_pretrained("naver-clova-ix/donut-base-finetuned-cord-v2")
28
  # pretrained_model: DonutModel = DonutModel.from_pretrained("result", local_files_only=True)
 
40
  More details are available at:
41
  - Paper: https://arxiv.org/abs/2111.15664
42
  - GitHub: https://github.com/clovaai/donut""",
43
+ examples=[["sample_image_cord_test_receipt_00004.png"], ["sample_image_cord_test_receipt_00012.png"]],
44
  cache_examples=False,
45
  )
46
 
receipts_app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Donut
3
+ Copyright (c) 2022-present NAVER Corp.
4
+ MIT License
5
+
6
+ https://github.com/clovaai/donut
7
+ """
8
+ import gradio as gr
9
+ import torch
10
+ from PIL import Image
11
+
12
+ from donut import DonutModel
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
+ task_prompt = f"<s_receipts>"
22
+
23
+ # image = Image.open("./sample_image_cord_test_receipt_00004.png")
24
+ # image.save("cord_sample_receipt1.png")
25
+ # image = Image.open("./sample_image_cord_test_receipt_00012.png")
26
+ # image.save("cord_sample_receipt2.png")
27
+
28
+ device = 'cuda' if torch.cuda.is_available() else 'cpu'
29
+
30
+ pretrained_model = DonutModel.from_pretrained("naver-clova-ix/donut-base-finetuned-cord-v2")
31
+ # pretrained_model: DonutModel = DonutModel.from_pretrained("result", local_files_only=True)
32
+ pretrained_model.to(device)
33
+ pretrained_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
+
44
+ More details are available at:
45
+ - Paper: https://arxiv.org/abs/2111.15664
46
+ - GitHub: https://github.com/clovaai/donut""",
47
+ examples=[["sample_image_cord_test_receipt_00004.png"], ["sample_image_cord_test_receipt_00012.png"]],
48
+ cache_examples=False,
49
+ )
50
+
51
+ demo.launch(server_name="0.0.0.0")