Spaces:
Sleeping
Sleeping
File size: 1,564 Bytes
61fd574 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | 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)
|