Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,7 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
| 17 |
model.to(device)
|
| 18 |
|
| 19 |
def process_document(image):
|
|
|
|
| 20 |
#can't save uploaded file locally, but needs to be converted from nparray to PIL
|
| 21 |
im1 = Image.fromarray(image)
|
| 22 |
|
|
@@ -57,7 +58,8 @@ def process_document(image):
|
|
| 57 |
sequence = processor.batch_decode(outputs.sequences)[0]
|
| 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 |
title = '<table align="center" border="0" cellpadding="1" cellspacing="1" style="width:100pc"><tbody><tr><td style="text-align:center"><img alt="" src="https://huggingface.co/spaces/to-be/invoice_document_headers_extraction_with_donut/resolve/main/circling_small.gif" style="float:right; height:50px; width:50px" /></td><td style="text-align:center"><h1> Welcome</h1></td><td style="text-align:center"><img alt="" src="https://huggingface.co/spaces/to-be/invoice_document_headers_extraction_with_donut/resolve/main/circling2_small.gif" style="float:left; height:50px; width:50px" /></td></tr></tbody></table>'
|
|
@@ -88,7 +90,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 88 |
gr.Examples([["example.jpg"], ["example_2.jpg"], ["example_3.jpg"]], inputs=[inp],label='Or use one of these examples:')
|
| 89 |
with gr.Row().style(equal_height=True,height=200,rounded=False):
|
| 90 |
with gr.Column(scale=1):
|
| 91 |
-
img2 = gr.Image("drinking.gif",label=' ').style(rounded=True)
|
| 92 |
with gr.Column(scale=2):
|
| 93 |
btn = gr.Button("↓ Extract ↓")
|
| 94 |
with gr.Column(scale=1):
|
|
|
|
| 17 |
model.to(device)
|
| 18 |
|
| 19 |
def process_document(image):
|
| 20 |
+
img2.update(visible=True)
|
| 21 |
#can't save uploaded file locally, but needs to be converted from nparray to PIL
|
| 22 |
im1 = Image.fromarray(image)
|
| 23 |
|
|
|
|
| 58 |
sequence = processor.batch_decode(outputs.sequences)[0]
|
| 59 |
sequence = sequence.replace(processor.tokenizer.eos_token, "").replace(processor.tokenizer.pad_token, "")
|
| 60 |
sequence = re.sub(r"<.*?>", "", sequence, count=1).strip() # remove first task start token
|
| 61 |
+
|
| 62 |
+
img2.update(visible=False)
|
| 63 |
return processor.token2json(sequence), image
|
| 64 |
|
| 65 |
title = '<table align="center" border="0" cellpadding="1" cellspacing="1" style="width:100pc"><tbody><tr><td style="text-align:center"><img alt="" src="https://huggingface.co/spaces/to-be/invoice_document_headers_extraction_with_donut/resolve/main/circling_small.gif" style="float:right; height:50px; width:50px" /></td><td style="text-align:center"><h1> Welcome</h1></td><td style="text-align:center"><img alt="" src="https://huggingface.co/spaces/to-be/invoice_document_headers_extraction_with_donut/resolve/main/circling2_small.gif" style="float:left; height:50px; width:50px" /></td></tr></tbody></table>'
|
|
|
|
| 90 |
gr.Examples([["example.jpg"], ["example_2.jpg"], ["example_3.jpg"]], inputs=[inp],label='Or use one of these examples:')
|
| 91 |
with gr.Row().style(equal_height=True,height=200,rounded=False):
|
| 92 |
with gr.Column(scale=1):
|
| 93 |
+
img2 = gr.Image("drinking.gif",label=' ',visible=False).style(rounded=True)
|
| 94 |
with gr.Column(scale=2):
|
| 95 |
btn = gr.Button("↓ Extract ↓")
|
| 96 |
with gr.Column(scale=1):
|