thinh-researcher commited on
Commit
ee0e82a
β€’
1 Parent(s): f0dbcbc
Files changed (2) hide show
  1. app.py +16 -10
  2. receipts_app.py +2 -8
app.py CHANGED
@@ -11,26 +11,29 @@ 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
 
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)
 
 
 
 
29
  pretrained_model.eval()
30
 
31
  demo = gr.Interface(
32
  fn=demo_process,
33
- inputs= gr.inputs.Image(type="pil"),
34
  outputs="json",
35
  title=f"Donut 🍩 demonstration for `cord-v2` task",
36
  description="""This model is trained with 800 Indonesian receipt images of CORD dataset. <br>
@@ -40,7 +43,10 @@ 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=[["sample_image_cord_test_receipt_00004.png"], ["sample_image_cord_test_receipt_00012.png"]],
 
 
 
44
  cache_examples=False,
45
  )
46
 
 
11
 
12
  from donut import DonutModel
13
 
14
+
15
  def demo_process(input_img):
16
  global pretrained_model, task_prompt, task_name
17
  # input_img = Image.fromarray(input_img)
18
+ output = pretrained_model.inference(image=input_img, prompt=task_prompt)[
19
+ "predictions"
20
+ ][0]
21
  return output
22
 
 
23
 
24
+ task_prompt = f"<s_cord-v2>"
 
 
 
25
 
26
+ pretrained_model = DonutModel.from_pretrained(
27
+ "naver-clova-ix/donut-base-finetuned-cord-v2"
28
+ )
29
+ # pretrained_model: DonutModel = DonutModel.from_pretrained(
30
+ # "result", local_files_only=True
31
+ # )
32
  pretrained_model.eval()
33
 
34
  demo = gr.Interface(
35
  fn=demo_process,
36
+ inputs=gr.inputs.Image(type="pil"),
37
  outputs="json",
38
  title=f"Donut 🍩 demonstration for `cord-v2` task",
39
  description="""This model is trained with 800 Indonesian receipt images of CORD dataset. <br>
 
43
  More details are available at:
44
  - Paper: https://arxiv.org/abs/2111.15664
45
  - GitHub: https://github.com/clovaai/donut""",
46
+ examples=[
47
+ ["sample_image_cord_test_receipt_00004.png"],
48
+ ["sample_image_cord_test_receipt_00012.png"],
49
+ ],
50
  cache_examples=False,
51
  )
52
 
receipts_app.py CHANGED
@@ -20,15 +20,9 @@ def demo_process(input_img):
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
 
 
20
  # task_prompt = f"<s_cord-v2>"
21
  task_prompt = f"<s_receipts>"
22
 
23
+ device = 'cpu' # 'cuda' if torch.cuda.is_available() else 'cpu'
 
 
 
24
 
25
+ pretrained_model: DonutModel = DonutModel.from_pretrained("result", local_files_only=True)
 
 
 
26
  pretrained_model.to(device)
27
  pretrained_model.eval()
28