File size: 1,511 Bytes
e9cedb1
 
 
 
 
 
 
 
 
 
 
f5ffb8d
 
 
 
ff35d52
c08ce43
ff35d52
c08ce43
f5ffb8d
 
 
 
 
 
e9cedb1
 
 
 
f4476a2
e9cedb1
afdb77b
 
 
 
 
 
 
 
f5ffb8d
e9cedb1
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import gradio as gr
import torch
from PIL import Image

from donut import DonutModel

def demo_process(input_img):
    global pretrained_model, task_prompt, task_name
    # input_img = Image.fromarray(input_img)
    output = pretrained_model.inference(image=input_img, prompt=task_prompt)["predictions"][0]
    return output
task_name = "preparedFinetuneData"
# task_name = "cord-v2"
task_prompt = f"<s_{task_name}>"

image = Image.open("sample_receipt1.png")
image.save("sample_receipt1.png")
image = Image.open("sample_receipt2.png")
image.save("sample_receipt2.png")

PATH = 'epochs30_base_on_donut_base/'
# pretrained_model = DonutModel.from_pretrained(PATH, local_files_only=True)
# pretrained_model = DonutModel.from_pretrained("doshan1250/p9OcrAiV1", revision="main")
pretrained_model = DonutModel.from_pretrained("doshan1250/p9OcrAiV1")
# pretrained_model = DonutModel.from_pretrained("naver-clova-ix/donut-base-finetuned-cord-v2")
pretrained_model.eval()

demo = gr.Interface(
    fn=demo_process,
    inputs= gr.Image(type="pil"),
    outputs="json",
    title=f"Goodarc p9 Donut for `{task_name}` task, epochs30",
    description="""Goodarc p9 使用 100 個英文收據訓練. <br> 訓練格式
    {
        "company": "SYARIKAT PERNIAGAAN GIN KEE",
        "date": "02/12/2017",
        "address": "NO 290, JALAN AIR PANAS. SETAPAK. 53200, KUALA LUMPUR.",
        "total": "7.42"
    }""",
    examples=[["sample_receipt1.png"], ["sample_receipt2.png"]],
    cache_examples=False,
)

demo.launch()