doshan1250 commited on
Commit
e9cedb1
1 Parent(s): 2cad42e

firstcommit

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