offer-puplayer / backend /app /services /resume_service.py
tryprogram's picture
Upload 46 files
61fd574 verified
Raw History Blame Contribute Delete
1.56 kB
import asyncio
import io
import logging
try:
import pdfplumber
PDFPLUMBER_AVAILABLE = True
except ImportError:
PDFPLUMBER_AVAILABLE = False
logger = logging.getLogger(__name__)
MOCK_RESULT = {
"name": "张三",
"school": "华南理工大学",
"major": "计算机科学与技术",
"grade": "研二",
"skills": ["Python", "Java", "SQL", "PyTorch", "Flask"],
"projects": [
"基于协同过滤的推荐系统",
"在线商城后端开发",
],
"summary": "技术栈集中在Python/Java后端开发,有推荐系统和Web开发项目经验",
}
async def parse_resume_pdf(file_bytes: bytes) -> dict:
if not PDFPLUMBER_AVAILABLE:
return dict(MOCK_RESULT)
try:
with pdfplumber.open(io.BytesIO(file_bytes)) as pdf:
text_parts = []
for page in pdf.pages:
page_text = page.extract_text()
if page_text:
text_parts.append(page_text)
full_text = "\n".join(text_parts)
if not full_text.strip():
return dict(MOCK_RESULT)
from app.agents.resume_parser import ResumeParser
parser = ResumeParser()
result = await parser.parse_resume(full_text)
if isinstance(result, dict) and "error" not in result:
return result
logger.warning("Resume parser returned error: %s", result.get("error"))
return dict(MOCK_RESULT)
except Exception as e:
logger.error("Resume parsing failed: %s", e)
return dict(MOCK_RESULT)