Spaces:
Sleeping
Sleeping
Download app/services/resume_service.py from abdullah090809/Job_Tracker_API: direct link, hf CLI and curl.
- Browser
- Download file 755 Bytes
-
https://huggingface.co/spaces/abdullah090809/Job_Tracker_API/resolve/main/app/services/resume_service.py
- Command line
-
hf download hf://spaces/abdullah090809/Job_Tracker_API/app/services/resume_service.py
-
curl -L -o resume_service.py https://huggingface.co/spaces/abdullah090809/Job_Tracker_API/resolve/main/app/services/resume_service.py
755 Bytes
| from pypdf import PdfReader | |
| from fastapi import HTTPException, status | |
| import io | |
| def extract_text_from_pdf(file_bytes: bytes) -> str: | |
| try: | |
| reader = PdfReader(io.BytesIO(file_bytes)) | |
| text = "" | |
| for page in reader.pages: | |
| text += page.extract_text() or "" | |
| if not text.strip(): | |
| raise HTTPException( | |
| status_code=status.HTTP_400_BAD_REQUEST, | |
| detail="Could not extract text from PDF. The file may be scanned/image-based." | |
| ) | |
| return text.strip() | |
| except HTTPException: | |
| raise | |
| except Exception: | |
| raise HTTPException( | |
| status_code=status.HTTP_400_BAD_REQUEST, | |
| detail="Invalid or corrupted PDF file" | |
| ) |