File size: 1,448 Bytes
c9e6420
6bd383d
 
3c0821a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6bd383d
3c0821a
 
 
 
632f752
3c0821a
 
 
c9e6420
 
3c0821a
632f752
 
 
c9e6420
1e06a50
3c0821a
1e06a50
c9e6420
3c0821a
 
 
 
c9e6420
3c0821a
c9e6420
3c0821a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gradio as gr
import subprocess


def nougat_ocr(file_name):
  # CLI Command to run
  cli_command = [
      'nougat',
      '--out', '/output',
      'pdf', f'{file_name}',
      '--checkpoint', '/nougat'
  ]

  # Run the command and get .mmd file in an output folder
  subprocess.run(cli_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
  return


def predict(pdf_file):
  print(f"temporary file - {pdf_file.name}")
  pdf_name = pdf_file.name.split('/')[-1].split('.')[0]
  print(f"pdf file name - {pdf_name}")
    
  #! Get prediction for a PDF using nougat
  nougat_ocr(pdf_file.name)
  
  # Open the multimarkdown (.mmd) file for reading
  with open(f'/output/{pdf_name}.mmd', 'r') as file:
      content = file.read() 
      
  return content


with gr.Blocks() as demo:
  gr.HTML("<h1>Nougat: Neural Optical Understanding for Academic Documents<h1>")
  gr.HTML("<h3>Lukas Blecher et al. <a href='https://arxiv.org/pdf/2308.13418.pdf' target='_blank'>Paper</a>, <a href='https://facebookresearch.github.io/nougat/'>Project</a></h3>")
  
  with gr.Row():
    pdf_file = gr.File(label='Upload a PDF', scale=1)
    mkd = gr.Markdown('<h2><center><i>OR</i></center></h2>',scale=1)
    pdf_link = gr.Textbox(placeholder='Enter an arxiv link here', label='Provide a link', scale=1)

  btn = gr.Button()
  parsed_output = gr.Markdown()
  
  btn.click(predict, pdf_file, parsed_output )

demo.queue()
demo.launch(debug=True)