Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ def process(input_pdf):
|
|
10 |
pdf = fitz.open(input_pdf)
|
11 |
first_page = pdf[0]
|
12 |
pix = first_page.get_pixmap()
|
13 |
-
image_bytes = pix.tobytes("
|
14 |
pdf.close()
|
15 |
|
16 |
temp_dir = "images"
|
@@ -22,14 +22,21 @@ def process(input_pdf):
|
|
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 |
-
|
|
|
33 |
demo.launch()
|
34 |
|
35 |
|
|
|
10 |
pdf = fitz.open(input_pdf)
|
11 |
first_page = pdf[0]
|
12 |
pix = first_page.get_pixmap()
|
13 |
+
image_bytes = pix.tobytes("png")
|
14 |
pdf.close()
|
15 |
|
16 |
temp_dir = "images"
|
|
|
22 |
f.write(image_bytes)
|
23 |
|
24 |
image_path = os.path.join(temp_dir, image_name)
|
25 |
+
|
26 |
output = model.inference(image=image_path, prompt=task_prompt)["predictions"][0]
|
27 |
+
|
28 |
+
os.remove(image_path)
|
29 |
+
os.rmdir(temp_dir)
|
30 |
+
|
31 |
return output
|
32 |
|
33 |
task_name = "SGSInvoice"
|
34 |
task_prompt = f"<s_{task_name}>"
|
35 |
+
|
36 |
model = DonutModel.from_pretrained("uartimcs/donut-invoice-extract")
|
37 |
model.eval()
|
38 |
+
|
39 |
+
demo = gr.Interface(fn=process,inputs=gr.File(label="Upload PDF File"),outputs="json", title=f"Donut 🍩 demonstration for `{task_name}` task",)
|
40 |
demo.launch()
|
41 |
|
42 |
|