Download app.py from Jamesb040/img2table: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/spaces/Jamesb040/img2table/resolve/main/app.py
- Command line
-
hf download hf://spaces/Jamesb040/img2table/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Jamesb040/img2table/resolve/main/app.py
1 kB
| 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() |