Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
-
import os
|
3 |
-
import shutil
|
4 |
-
import argparse
|
5 |
-
import torch
|
6 |
-
from PIL import Image
|
7 |
from pdf2image import convert_from_path
|
8 |
-
from donut import DonutModel
|
9 |
|
10 |
-
def
|
11 |
-
|
12 |
-
|
13 |
-
new_file_location = os.path.join(os.getcwd(),file_name)
|
14 |
-
|
15 |
-
shutil.copyfile(doc, new_file_location)
|
16 |
-
img = convert_from_path(new_file_location)[0]
|
17 |
-
output = model.inference(image=img, prompt=task_prompt)["predictions"][0]
|
18 |
-
return output
|
19 |
-
|
20 |
-
parser = argparse.ArgumentParser()
|
21 |
-
parser.add_argument("--task", type=str, default="SGSInvoice")
|
22 |
-
parser.add_argument("--pretrained_path", type=str, default="uartimcs/donut-invoice-extract")
|
23 |
-
args, left_argv = parser.parse_known_args()
|
24 |
-
task_name = args.task
|
25 |
-
task_prompt = f"<s_{task_name}>"
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
2 |
from pdf2image import convert_from_path
|
|
|
3 |
|
4 |
+
def pdf_to_jpg(pdf_path):
|
5 |
+
images = convert_from_path(pdf_path.name, first_page=1, last_page=1)
|
6 |
+
return images[0].save("first_page.jpg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
interface = gr.Interface(
|
9 |
+
fn=pdf_to_jpg,
|
10 |
+
inputs=gr.inputs.File(label="Upload PDF"),
|
11 |
+
outputs="image"
|
12 |
+
)
|
13 |
+
|
14 |
+
interface.launch()
|