uartimcs commited on
Commit
5579dac
·
verified ·
1 Parent(s): bb230bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -1,14 +1,20 @@
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.File(label="Upload PDF"),
11
- outputs="image"
12
- )
13
 
14
- interface.launch()
 
 
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()