Update app.py
Browse files
app.py
CHANGED
@@ -58,7 +58,7 @@ def process_document(image):
|
|
58 |
sequence = sequence.replace(processor.tokenizer.eos_token, "").replace(processor.tokenizer.pad_token, "")
|
59 |
sequence = re.sub(r"<.*?>", "", sequence, count=1).strip() # remove first task start token
|
60 |
|
61 |
-
return processor.token2json(sequence)
|
62 |
|
63 |
description = '<p>Using Donut model finetuned on Invoices for retrieval of following information:</p><ul><li><span style="color:black">DocType</span></span></li><li><span style="color:black">Currency</span></span></li><li><span style="color:black">DocumentDate</span></span></li><li><span style="color:black">GrossAmount</span></span></li><li><span style="color:black">InvoiceNumber</span></span></li><li><span style="color:black">NetAmount</span></span></li><li><span style="color:black">TaxAmount</span></span></li><li><span style="color:black">OrderNumber</span></span></li><li><span style="color:black">CreditorCountry</span></span></li></ul><p>To use it, simply upload your image and click 'submit', or click one of the examples to load them. Read more at the links below.</p><p> </p><p>(because this is running on the free cpu tier, it will take about 40 secs before you see a result)</p><p>Have fun 😎</p><p>Toon Beerten</p>'
|
64 |
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2111.15664' target='_blank'>Donut: OCR-free Document Understanding Transformer</a> | <a href='https://github.com/clovaai/donut' target='_blank'>Github Repo</a></p>"
|
@@ -79,14 +79,20 @@ with gr.Blocks(css=css) as demo:
|
|
79 |
gr.Markdown(title)
|
80 |
gr.Markdown(description)
|
81 |
|
82 |
-
|
83 |
with gr.Row().style():
|
84 |
with gr.Column(scale=1):
|
85 |
-
gr.
|
86 |
with gr.Column():
|
87 |
-
|
|
|
88 |
btn = gr.Button("Extract")
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
-
btn.click(fn=process_document, inputs=inp, outputs=
|
91 |
|
92 |
demo.launch()
|
|
|
58 |
sequence = sequence.replace(processor.tokenizer.eos_token, "").replace(processor.tokenizer.pad_token, "")
|
59 |
sequence = re.sub(r"<.*?>", "", sequence, count=1).strip() # remove first task start token
|
60 |
|
61 |
+
return processor.token2json(sequence), image
|
62 |
|
63 |
description = '<p>Using Donut model finetuned on Invoices for retrieval of following information:</p><ul><li><span style="color:black">DocType</span></span></li><li><span style="color:black">Currency</span></span></li><li><span style="color:black">DocumentDate</span></span></li><li><span style="color:black">GrossAmount</span></span></li><li><span style="color:black">InvoiceNumber</span></span></li><li><span style="color:black">NetAmount</span></span></li><li><span style="color:black">TaxAmount</span></span></li><li><span style="color:black">OrderNumber</span></span></li><li><span style="color:black">CreditorCountry</span></span></li></ul><p>To use it, simply upload your image and click 'submit', or click one of the examples to load them. Read more at the links below.</p><p> </p><p>(because this is running on the free cpu tier, it will take about 40 secs before you see a result)</p><p>Have fun 😎</p><p>Toon Beerten</p>'
|
64 |
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2111.15664' target='_blank'>Donut: OCR-free Document Understanding Transformer</a> | <a href='https://github.com/clovaai/donut' target='_blank'>Github Repo</a></p>"
|
|
|
79 |
gr.Markdown(title)
|
80 |
gr.Markdown(description)
|
81 |
|
82 |
+
|
83 |
with gr.Row().style():
|
84 |
with gr.Column(scale=1):
|
85 |
+
inp = gr.Image(label='Upload invoice here:') #.style(height=400)
|
86 |
with gr.Column():
|
87 |
+
gr.Examples([["example.jpg"], ["example_2.jpg"], ["example_3.jpg"]], inputs=[inp])
|
88 |
+
with gr.Row().style():
|
89 |
btn = gr.Button("Extract")
|
90 |
+
with gr.Row().style():
|
91 |
+
with gr.Column(scale=1):
|
92 |
+
imgout = gr.Image(label='Uploaded document:',elem_id="inp")
|
93 |
+
with gr.Column(scale=1):
|
94 |
+
jsonout = gr.JSON(label='Extracted information:')
|
95 |
|
96 |
+
btn.click(fn=process_document, inputs=inp, outputs=[jsonout,imgout])
|
97 |
|
98 |
demo.launch()
|