uartimcs commited on
Commit
2085731
1 Parent(s): f3a60f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import fitz # PyMuPDF
3
  from PIL import Image
4
 
5
- def pdf_to_jpg(pdf_file):
6
  # Open the PDF file
7
  document = fitz.open(pdf_file.name)
8
  # Get the first page
@@ -13,12 +13,20 @@ def pdf_to_jpg(pdf_file):
13
  image = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
14
  image_path = "first_page.jpg"
15
  image.save(image_path)
16
- return image_path
 
 
 
 
 
 
 
 
17
 
18
  interface = gr.Interface(
19
- fn=pdf_to_jpg,
20
  inputs=gr.File(label="Upload PDF"),
21
- outputs=gr.Image(label="First Page JPG")
22
  )
23
 
24
  interface.launch()
 
2
  import fitz # PyMuPDF
3
  from PIL import Image
4
 
5
+ def analysis_process(pdf_file):
6
  # Open the PDF file
7
  document = fitz.open(pdf_file.name)
8
  # Get the first page
 
13
  image = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
14
  image_path = "first_page.jpg"
15
  image.save(image_path)
16
+
17
+ output = model.inference(image=image_path, prompt=task_prompt)["predictions"][0]
18
+ return output
19
+
20
+ task_name = "SGSInvoice"
21
+ task_prompt = f"<s_{task_name}>"
22
+ model = DonutModel.from_pretrained("uartimcs/donut-invoice-extract")
23
+ model.eval()
24
+
25
 
26
  interface = gr.Interface(
27
+ fn=analysis_process,
28
  inputs=gr.File(label="Upload PDF"),
29
+ outputs="json"
30
  )
31
 
32
  interface.launch()