Spaces:
Runtime error
Runtime error
Download src/pdf_utils.py from ResumeScreening/resume-screening-rag: direct link, hf CLI and curl.
- Browser
- Download file 493 Bytes
-
https://huggingface.co/spaces/ResumeScreening/resume-screening-rag/resolve/main/src/pdf_utils.py
- Command line
-
hf download hf://spaces/ResumeScreening/resume-screening-rag/src/pdf_utils.py
-
curl -L -o pdf_utils.py https://huggingface.co/spaces/ResumeScreening/resume-screening-rag/resolve/main/src/pdf_utils.py
493 Bytes
| from __future__ import annotations | |
| import fitz # PyMuPDF | |
| def extract_pdf_text_by_page(pdf_bytes: bytes) -> list[dict]: | |
| """ | |
| Returns: [{"page": 1, "text": "..."},...] | |
| """ | |
| doc = fitz.open(stream=pdf_bytes, filetype="pdf") | |
| pages = [] | |
| for i in range(len(doc)): | |
| page = doc[i] | |
| text = page.get_text("text") or "" | |
| text = " ".join(text.split()) # normalize whitespace | |
| pages.append({"page": i + 1, "text": text}) | |
| doc.close() | |
| return pages |