Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import zipfile
|
|
5 |
from donut import DonutModel
|
6 |
|
7 |
def process(input_pdf):
|
|
|
8 |
# Conversion of PDF to JPG images
|
9 |
pdf = fitz.open(input_pdf)
|
10 |
first_page = pdf[0]
|
@@ -16,19 +17,19 @@ def process(input_pdf):
|
|
16 |
basename = os.path.basename(input_pdf).split('.')[0]
|
17 |
image_name = basename + "jpg"
|
18 |
os.makedirs(temp_dir, exist_ok=True)
|
|
|
19 |
with open(os.path.join(temp_dir, image_name), "wb") as f:
|
20 |
f.write(image_bytes)
|
21 |
|
22 |
image_path = os.path.join(temp_dir, image_name)
|
23 |
output = model.inference(image=image_path, prompt=task_prompt)["predictions"][0]
|
24 |
-
|
25 |
return output
|
26 |
|
27 |
task_name = "SGSInvoice"
|
28 |
task_prompt = f"<s_{task_name}>"
|
29 |
model = DonutModel.from_pretrained("uartimcs/donut-invoice-extract")
|
30 |
model.eval()
|
31 |
-
demo = gr.Interface(fn=process,inputs=gr.File(
|
32 |
demo.launch()
|
33 |
|
34 |
|
|
|
5 |
from donut import DonutModel
|
6 |
|
7 |
def process(input_pdf):
|
8 |
+
|
9 |
# Conversion of PDF to JPG images
|
10 |
pdf = fitz.open(input_pdf)
|
11 |
first_page = pdf[0]
|
|
|
17 |
basename = os.path.basename(input_pdf).split('.')[0]
|
18 |
image_name = basename + "jpg"
|
19 |
os.makedirs(temp_dir, exist_ok=True)
|
20 |
+
|
21 |
with open(os.path.join(temp_dir, image_name), "wb") as f:
|
22 |
f.write(image_bytes)
|
23 |
|
24 |
image_path = os.path.join(temp_dir, image_name)
|
25 |
output = model.inference(image=image_path, prompt=task_prompt)["predictions"][0]
|
|
|
26 |
return output
|
27 |
|
28 |
task_name = "SGSInvoice"
|
29 |
task_prompt = f"<s_{task_name}>"
|
30 |
model = DonutModel.from_pretrained("uartimcs/donut-invoice-extract")
|
31 |
model.eval()
|
32 |
+
demo = gr.Interface(fn=process,inputs=gr.File(label="Upload PDF File"),outputs=gr.File(label="Download Output"),, title=f"Donut 🍩 demonstration for `{task_name}` task",)
|
33 |
demo.launch()
|
34 |
|
35 |
|