import subprocess import camelot import pandas as pd import gradio as gr try: camelot.__version__ except ImportError: subprocess.run(["apt-get", "update"]) subprocess.run(["apt-get", "install", "-y", "ghostscript"]) def extract_tables(pdf_file): tables = camelot.read_pdf(pdf_file.name, pages="all") df = pd.concat([table.df for table in tables], ignore_index=True) df.to_excel("output.xlsx", index=False) return "output.xlsx" interface = gr.Interface( fn=extract_tables, inputs=gr.File(label="Upload PDF"), outputs=gr.File(label="Download Excel"), title="PDF Table Extractor", description="Extract tables from PDF and output as Excel file.", ) if __name__ == "__main__": interface.launch()