import gradio as gr from img2table.document import Image from img2table.ocr import EasyOCR import pandas as pd # Initialize the OCR engine (this will download models on first run) ocr = EasyOCR(lang=["en"]) def extract_table(input_img): # 1. Load the image from the path provided by Gradio doc = Image(input_img) # 2. Extract tables using EasyOCR as the text reader # 'borderless_tables=True' helps if the PDF/Image has no lines extracted_tables = doc.extract_tables(ocr=ocr, borderless_tables=True) if not extracted_tables: return "No tables detected." # 3. Convert the first detected table to a Pandas DataFrame df = extracted_tables[0].df return df # Build a simple UI interface = gr.Interface( fn=extract_table, inputs=gr.Image(type="filepath"), outputs=gr.Dataframe(), title="img2table Explorer", description="Upload a scanned image or screenshot of a table to convert it to a digital grid." ) interface.launch()