Download ingest/pdf_reader.py from haresh15/pdf: direct link, hf CLI and curl.
- Browser
- Download file 436 Bytes
-
https://huggingface.co/spaces/haresh15/pdf/resolve/main/ingest/pdf_reader.py
- Command line
-
hf download hf://spaces/haresh15/pdf/ingest/pdf_reader.py
-
curl -L -o pdf_reader.py https://huggingface.co/spaces/haresh15/pdf/resolve/main/ingest/pdf_reader.py
436 Bytes
| import pdfplumber | |
| def extract_text(pdf_path): | |
| chunks = [] | |
| with pdfplumber.open(pdf_path) as pdf: | |
| for page_num, page in enumerate(pdf.pages, start=1): | |
| text = page.extract_text() or "" | |
| if text.strip(): | |
| chunks.append({ | |
| "page": page_num, | |
| "type": "text", | |
| "content": text | |
| }) | |
| return chunks | |