Spaces:
Sleeping
Sleeping
File size: 1,144 Bytes
1595f22 | 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 | # %%writefile core/resume_parser.py
import os
import json
from openai import OpenAI
from utils.prompts import RESUME_PARSE_PROMPT
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def parse_resume(resume_text, filename):
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are an expert HR resume analyst specializing in extracting structured information from resumes with high accuracy."},
{"role": "user", "content": RESUME_PARSE_PROMPT.format(resume_text=resume_text)}
],
temperature=0.2
)
content = response.choices[0].message.content
try:
start = content.find("{")
end = content.rfind("}") + 1
json_str = content[start:end]
data = json.loads(json_str)
except Exception:
data = {
"name": "",
"skills": [],
"education": [],
"work_experience": [],
"total_years_experience": 0,
"summary": ""
}
data["candidate_id"] = filename
return data |