Spaces:
Sleeping
Sleeping
Download backend/services/pdf_parser.py from Gini-Eddie/ATS-Intelligence-System: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/Gini-Eddie/ATS-Intelligence-System/resolve/main/backend/services/pdf_parser.py
- Command line
-
hf download hf://spaces/Gini-Eddie/ATS-Intelligence-System/backend/services/pdf_parser.py
-
curl -L -o pdf_parser.py https://huggingface.co/spaces/Gini-Eddie/ATS-Intelligence-System/resolve/main/backend/services/pdf_parser.py
1.18 kB
| import pdfplumber | |
| import io | |
| def extract_text_with_links(file_bytes: bytes) -> str: | |
| """ | |
| Extracts text and explicitly recovers embedded URLs from the PDF structure. | |
| """ | |
| full_content = [] | |
| try: | |
| with pdfplumber.open(io.BytesIO(file_bytes)) as pdf: | |
| for page in pdf.pages: | |
| # 1. Get the standard text | |
| page_text = page.extract_text() or "" | |
| # 2. Extract Hyperlinks (Annotations) | |
| links = page.hyperlinks | |
| link_descriptions = [] | |
| if links: | |
| for link in links: | |
| # Extract the destination URL | |
| uri = link.get('uri') | |
| if uri: | |
| link_descriptions.append(f"[Link Found: {uri}]") | |
| # 3. Combine text and found links for the AI to process | |
| combined_page = page_text + "\n" + "\n".join(link_descriptions) | |
| full_content.append(combined_page) | |
| return "\n--- Page Boundary ---\n".join(full_content) | |
| except Exception as e: | |
| raise ValueError(f"Failed to recover links from PDF: {str(e)}") |