rishabh062 commited on
Commit
3579971
β€’
1 Parent(s): 97f9f1f

back to final state

Browse files
Files changed (1) hide show
  1. app.py +8 -26
app.py CHANGED
@@ -1,6 +1,5 @@
1
- import gradio as gr
2
- import csv
3
  import re
 
4
 
5
  import torch
6
  from transformers import DonutProcessor, VisionEncoderDecoderModel
@@ -38,37 +37,20 @@ def process_document(image):
38
  sequence = sequence.replace(processor.tokenizer.eos_token, "").replace(processor.tokenizer.pad_token, "")
39
  sequence = re.sub(r"<.*?>", "", sequence, count=1).strip() # remove first task start token
40
 
41
- with open('output.csv', 'a', newline='') as file:
42
- writer = csv.writer(file)
43
- writer.writerow(["image", sequence])
44
-
45
  return processor.token2json(sequence)
46
 
47
- def download_csv():
48
- return "output.csv"
49
-
50
  description = "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."
51
  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>"
52
 
53
- inputs = gr.inputs.Image()
54
- outputs = gr.outputs.Json()
55
-
56
- examples = [["example.png"], ["example_2.png"], ["example_3.png"]]
57
-
58
- download_button = gr.outputs.Button("Download CSV")
59
-
60
- interface = gr.Interface(
61
- process_document,
62
- inputs=inputs,
63
- outputs=outputs,
64
  title="Donut 🍩 for Document Parsing and Converting the Image to Database",
65
  description=description,
66
  article=article,
67
- examples=examples,
68
  enable_queue=True,
69
- cache_examples=False,
70
- allow_download=True,
71
- download_button=download_button
72
- )
73
 
74
- interface.launch()
 
 
 
1
  import re
2
+ import gradio as gr
3
 
4
  import torch
5
  from transformers import DonutProcessor, VisionEncoderDecoderModel
 
37
  sequence = sequence.replace(processor.tokenizer.eos_token, "").replace(processor.tokenizer.pad_token, "")
38
  sequence = re.sub(r"<.*?>", "", sequence, count=1).strip() # remove first task start token
39
 
 
 
 
 
40
  return processor.token2json(sequence)
41
 
 
 
 
42
  description = "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."
43
  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>"
44
 
45
+ demo = gr.Interface(
46
+ fn=process_document,
47
+ inputs="image",
48
+ outputs="json",
 
 
 
 
 
 
 
49
  title="Donut 🍩 for Document Parsing and Converting the Image to Database",
50
  description=description,
51
  article=article,
 
52
  enable_queue=True,
53
+ examples=[["example.png"], ["example_2.png"], ["example_3.png"]],
54
+ cache_examples=False)
 
 
55
 
56
+ demo.launch()