neerajkalyank commited on
Commit
8f0b178
1 Parent(s): b87add3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -3,17 +3,18 @@ import camelot
3
  import pandas as pd
4
  import gradio as gr
5
 
6
- # Install Ghostscript if missing
7
- try:
8
- camelot.__version__
9
- except ImportError:
10
  subprocess.run(["apt-get", "update"])
11
  subprocess.run(["apt-get", "install", "-y", "ghostscript"])
12
 
13
  def extract_tables(pdf_file):
14
- tables = camelot.read_pdf(pdf_file.name, pages="all")
15
- df = pd.concat([table.df for table in tables], ignore_index=True)
16
- return df
 
 
 
 
17
 
18
  demo = gr.Interface(
19
  fn=extract_tables,
 
3
  import pandas as pd
4
  import gradio as gr
5
 
6
+ def install_ghostscript():
 
 
 
7
  subprocess.run(["apt-get", "update"])
8
  subprocess.run(["apt-get", "install", "-y", "ghostscript"])
9
 
10
  def extract_tables(pdf_file):
11
+ try:
12
+ tables = camelot.read_pdf(pdf_file.name, pages="all")
13
+ df = pd.concat([table.df for table in tables], ignore_index=True)
14
+ return df
15
+ except OSError:
16
+ install_ghostscript()
17
+ return "Ghostscript installed. Please retry."
18
 
19
  demo = gr.Interface(
20
  fn=extract_tables,