Download ingest/table_extractor.py from haresh15/pdf: direct link, hf CLI and curl.
- Browser
- Download file 643 Bytes
-
https://huggingface.co/spaces/haresh15/pdf/resolve/main/ingest/table_extractor.py
- Command line
-
hf download hf://spaces/haresh15/pdf/ingest/table_extractor.py
-
curl -L -o table_extractor.py https://huggingface.co/spaces/haresh15/pdf/resolve/main/ingest/table_extractor.py
643 Bytes
| import pdfplumber | |
| def extract_tables(pdf_path): | |
| table_chunks = [] | |
| with pdfplumber.open(pdf_path) as pdf: | |
| for page_num, page in enumerate(pdf.pages, start=1): | |
| tables = page.extract_tables() | |
| for table in tables: | |
| rows = [" | ".join(row) for row in table if row] | |
| table_text = "\n".join(rows) | |
| if table_text.strip(): | |
| table_chunks.append({ | |
| "page": page_num, | |
| "type": "table", | |
| "content": table_text | |
| }) | |
| return table_chunks | |