Spaces:
Sleeping
Sleeping
| # %%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 |