Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
|
|
3 |
import argparse
|
4 |
import torch
|
5 |
from PIL import Image
|
@@ -9,8 +10,12 @@ from donut import DonutModel
|
|
9 |
|
10 |
def demo_process(doc):
|
11 |
global model, task_prompt, task_name
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
14 |
return output
|
15 |
|
16 |
parser = argparse.ArgumentParser()
|
@@ -22,5 +27,5 @@ task_prompt = f"<s_{task_name}>"
|
|
22 |
|
23 |
# model = DonutModel.from_pretrained("uartimcs/donut-invoice-extract")
|
24 |
# model.eval()
|
25 |
-
demo = gr.Interface(fn=demo_process,inputs=gr.File(label="Upload PDF"),outputs="
|
26 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
+
import shutil
|
4 |
import argparse
|
5 |
import torch
|
6 |
from PIL import Image
|
|
|
10 |
|
11 |
def demo_process(doc):
|
12 |
global model, task_prompt, task_name
|
13 |
+
file_name = os.path.basename(doc)
|
14 |
+
new_file_location = os.path.join(os.getcwd(),file_name)
|
15 |
+
|
16 |
+
shutil.copyfile(doc, new_file_location)
|
17 |
+
img = convert_from_path(new_file_location)[0]
|
18 |
+
output = model.inference(image=img, prompt=task_prompt)["predictions"][0]
|
19 |
return output
|
20 |
|
21 |
parser = argparse.ArgumentParser()
|
|
|
27 |
|
28 |
# model = DonutModel.from_pretrained("uartimcs/donut-invoice-extract")
|
29 |
# model.eval()
|
30 |
+
demo = gr.Interface(fn=demo_process,inputs=gr.File(label="Upload PDF"),outputs="json", title=f"Donut 🍩 demonstration for `{task_name}` task",)
|
31 |
demo.launch()
|