toshiba_2.O / app.py
neerajkalyank's picture
Update app.py
5037069 verified
raw
history blame contribute delete
836 Bytes
import subprocess
import camelot
import pandas as pd
import gradio as gr
def install_ghostscript():
subprocess.run(["apt-get", "update"])
subprocess.run(["apt-get", "install", "-y", "ghostscript"])
def extract_tables(pdf_file):
try:
tables = camelot.read_pdf(pdf_file.name, pages="all")
df = pd.concat([table.df for table in tables], ignore_index=True)
return df, "Ready"
except OSError:
install_ghostscript()
return None, "Ghostscript installed. Please retry."
## Gradio Interface
demo = gr.Interface(
fn=extract_tables,
inputs=gr.File(label="Upload PDF"),
outputs=[gr.DataFrame(label="Extracted Tables"), gr.Label(label="Status")],
title="PDF Table Extractor",
description="Extract tables from PDF files.",
)
if __name__ == "__main__":
demo.launch()