|
| 1 | +""" |
| 2 | +This module is responsible for evaluating resumes based on specified criteria. |
| 3 | +""" |
| 4 | + |
| 5 | +import json |
| 6 | +import os |
| 7 | +from openai import OpenAI |
| 8 | + |
| 9 | +# Load the OpenAI API key |
| 10 | +config_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'configs', 'config.json') |
| 11 | +with open(config_path, 'r') as file: |
| 12 | + config = json.load(file) |
| 13 | +client = OpenAI( |
| 14 | + api_key=config['CHATGPT_API_KEY'] |
| 15 | +) |
| 16 | + |
| 17 | +# Define the scoring criteria and weights |
| 18 | +SCORING_CRITERIA = { |
| 19 | + 'Relevance of Job Description': 30, |
| 20 | + 'Achievements and Impact': 25, |
| 21 | + 'Education and Certifications': 15, |
| 22 | + 'Resume Structure and Presentation': 10, |
| 23 | + 'Soft Skills': 10, |
| 24 | + 'Consistency and Chronology': 10 |
| 25 | +} |
| 26 | + |
| 27 | + |
| 28 | +def evaluate_resume(resume_text): |
| 29 | + """ |
| 30 | + Evaluate resumes by calling ChatGPT API |
| 31 | + """ |
| 32 | + try: |
| 33 | + prompt = f""" |
| 34 | + Please evaluate the following resume based on the criteria below, and structure your response according to the format provided: |
| 35 | +
|
| 36 | + Criteria: |
| 37 | + 1. Relevance of Job Description (30%) |
| 38 | + 2. Achievements and Impact (25%) |
| 39 | + 3. Education and Certifications (15%) |
| 40 | + 4. Resume Structure and Presentation (10%) |
| 41 | + 5. Soft Skills (10%) |
| 42 | + 6. Consistency and Chronology (10%) |
| 43 | +
|
| 44 | + The response should follow this format: |
| 45 | +
|
| 46 | + ### Scores for each criteria: |
| 47 | + 1. Relevance of Job Description: X/100 |
| 48 | + 2. Achievements and Impact: X/100 |
| 49 | + 3. Education and Certifications: X/100 |
| 50 | + 4. Resume Structure and Presentation: X/100 |
| 51 | + 5. Soft Skills: X/100 |
| 52 | + 6. Consistency and Chronology: X/100 |
| 53 | +
|
| 54 | + ### Weighted Total Score: Y/100 |
| 55 | +
|
| 56 | + ### Explanation for each criteria: |
| 57 | + 1. Relevance of Job Description: |
| 58 | + [Explanation of the score] |
| 59 | + 2. Achievements and Impact: |
| 60 | + [Explanation of the score] |
| 61 | + 3. Education and Certifications: |
| 62 | + [Explanation of the score] |
| 63 | + 4. Resume Structure and Presentation: |
| 64 | + [Explanation of the score] |
| 65 | + 5. Soft Skills: |
| 66 | + [Explanation of the score] |
| 67 | + 6. Consistency and Chronology: |
| 68 | + [Explanation of the score] |
| 69 | +
|
| 70 | + Resume: {resume_text} |
| 71 | + """ |
| 72 | + |
| 73 | + # Call the evaluation API |
| 74 | + response = client.chat.completions.create( |
| 75 | + model='gpt-4o-mini', |
| 76 | + messages=[{'role': 'system', 'content': 'You are a professional resume evaluator.'}, |
| 77 | + {'role': 'user', 'content': prompt}], |
| 78 | + max_tokens=500, |
| 79 | + temperature=0.7 |
| 80 | + ) |
| 81 | + |
| 82 | + evaluation = response.choices[0].message.content |
| 83 | + return evaluation |
| 84 | + |
| 85 | + except Exception as e: |
| 86 | + return f'Error evaluating resume: {str(e)}' |
| 87 | + |
| 88 | + |
| 89 | +def extract_scores_and_explanation(evaluation): |
| 90 | + """ |
| 91 | + Extracts the scores and explanations from the evaluation response. |
| 92 | + """ |
| 93 | + scores = {} |
| 94 | + explanation = '' |
| 95 | + lines = evaluation.split('\n') |
| 96 | + |
| 97 | + # 6 criteria scores |
| 98 | + scores['Relevance of Job Description'] = int(lines[1].split(':')[1].strip().replace('/100', '')) |
| 99 | + scores['Achievements and Impact'] = int(lines[2].split(':')[1].strip().replace('/100', '')) |
| 100 | + scores['Education and Certifications'] = int(lines[3].split(':')[1].strip().replace('/100', '')) |
| 101 | + scores['Resume Structure and Presentation'] = int(lines[4].split(':')[1].strip().replace('/100', '')) |
| 102 | + scores['Soft Skills'] = int(lines[5].split(':')[1].strip().replace('/100', '')) |
| 103 | + scores['Consistency and Chronology'] = int(lines[6].split(':')[1].strip().replace('/100', '')) |
| 104 | + |
| 105 | + # Weighted total score |
| 106 | + weighted_score = float(lines[8].split(':')[1].strip().replace('/100', '')) |
| 107 | + |
| 108 | + # Explanation part |
| 109 | + explanation = '\n'.join(lines[11:]) |
| 110 | + |
| 111 | + return scores, weighted_score, explanation |
0 commit comments