Resume-Parser / app /services /resume_parser.py
SyedAzlanzar
@refactor : update resume parsing and PDF generation logic; improve error handling and file upload process
a704218
raw
history blame contribute delete
717 Bytes
import os
import requests
import io
import pdfplumber
def extract_resume_text(file_url: str) -> str:
HF_TOKEN = os.getenv("HF_TOKEN")
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
try:
response = requests.get(file_url, headers=headers, timeout=30)
response.raise_for_status()
pdf_bytes = io.BytesIO(response.content)
text = ""
with pdfplumber.open(pdf_bytes) as pdf:
for page in pdf.pages:
page_text = page.extract_text()
if page_text:
text += page_text + "\n"
return text.strip()
except Exception as e:
raise RuntimeError(f"Failed to extract text from resume: {str(e)}")