Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,12 @@ import gradio as gr
|
|
2 |
import argparse
|
3 |
import torch
|
4 |
from PIL import Image
|
|
|
5 |
from donut import DonutModel
|
6 |
-
|
|
|
7 |
global model, task_prompt, task_name
|
|
|
8 |
input_img = Image.fromarray(input_img)
|
9 |
output = model.inference(image=input_img, prompt=task_prompt)["predictions"][0]
|
10 |
return output
|
@@ -17,5 +20,5 @@ task_prompt = f"<s_{task_name}>"
|
|
17 |
|
18 |
model = DonutModel.from_pretrained("uartimcs/donut-invoice-extract")
|
19 |
model.eval()
|
20 |
-
demo = gr.Interface(fn=demo_process,inputs="
|
21 |
demo.launch()
|
|
|
2 |
import argparse
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
+
from pdf2image import convert_from_path
|
6 |
from donut import DonutModel
|
7 |
+
|
8 |
+
def demo_process(pdf_path):
|
9 |
global model, task_prompt, task_name
|
10 |
+
input_img = convert_from_path(pdf_path)
|
11 |
input_img = Image.fromarray(input_img)
|
12 |
output = model.inference(image=input_img, prompt=task_prompt)["predictions"][0]
|
13 |
return output
|
|
|
20 |
|
21 |
model = DonutModel.from_pretrained("uartimcs/donut-invoice-extract")
|
22 |
model.eval()
|
23 |
+
demo = gr.Interface(fn=demo_process,inputs=gr.inputs.File(label="Upload PDF"),outputs="json", title=f"Donut 🍩 demonstration for `{task_name}` task",)
|
24 |
demo.launch()
|