uartimcs commited on
Commit
8df8cf7
·
verified ·
1 Parent(s): 3edfc6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -26
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 demo_process(doc):
11
- global model, task_prompt, task_name
12
- file_name = os.path.basename(doc)
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
- model = DonutModel.from_pretrained("uartimcs/donut-invoice-extract")
28
- model.eval()
29
- demo = gr.Interface(fn=demo_process,inputs=gr.File(label="Upload PDF"),outputs="json", title=f"Donut 🍩 demonstration for `{task_name}` task",)
30
- demo.launch()
 
 
 
 
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()