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