Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,26 +9,28 @@ import torch
|
|
9 |
from PIL import Image
|
10 |
|
11 |
from donut import DonutModel
|
12 |
-
from transformers import DonutProcessor, VisionEncoderDecoderModel
|
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 =
|
19 |
return output
|
20 |
|
21 |
task_prompt = f"<s_cord-v2>"
|
22 |
|
23 |
image = Image.open("./cord_sample_receipt1.png")
|
24 |
image.save("cord_sample_receipt1.png")
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
image = Image.open("./000.jpg")
|
26 |
-
image.save("
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
model = VisionEncoderDecoderModel.from_pretrained("philschmid/donut-base-sroie")
|
31 |
-
model.eval()
|
32 |
|
33 |
demo = gr.Interface(
|
34 |
fn=demo_process,
|
@@ -41,6 +43,8 @@ More CORD receipt images are available at https://huggingface.co/datasets/naver-
|
|
41 |
More details are available at:
|
42 |
- Paper: https://arxiv.org/abs/2111.15664
|
43 |
- GitHub: https://github.com/clovaai/donut""",
|
44 |
-
examples=[["cord_sample_receipt1.png"],["
|
45 |
cache_examples=False,
|
46 |
-
)
|
|
|
|
|
|
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("./cord_sample_receipt1.png")
|
22 |
image.save("cord_sample_receipt1.png")
|
23 |
+
image = Image.open("./cord_sample_receipt2.png")
|
24 |
+
image.save("cord_sample_receipt2.png")
|
25 |
+
image = Image.open("./receipt_00015.png")
|
26 |
+
image.save("sroie_receipt_00015.png")
|
27 |
+
image = Image.open("./receipt_00049.png")
|
28 |
+
image.save("sroie_receipt_00049.png")
|
29 |
image = Image.open("./000.jpg")
|
30 |
+
image.save("sroie_receipt_00048.jpg")
|
31 |
|
32 |
+
pretrained_model = DonutModel.from_pretrained("naver-clova-ix/donut-base-finetuned-cord-v2")
|
33 |
+
pretrained_model.eval()
|
|
|
|
|
34 |
|
35 |
demo = gr.Interface(
|
36 |
fn=demo_process,
|
|
|
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 |
+
)
|
49 |
+
|
50 |
+
demo.launch()
|