Spaces:
Sleeping
Sleeping
File size: 4,833 Bytes
1aea493 | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | import json
from config.settings import OPENAI_API_KEY, MODEL_NAME, TEMPERATURE, MAX_TOKENS
def analyze_resume_with_openai(resume_text):
"""
Analyze resume using OpenAI API
Args:
resume_text: Extracted resume text
Returns:
Dictionary with analysis results
"""
import openai
if not OPENAI_API_KEY:
# Return mock data if API key is not configured
return get_mock_analysis()
openai.api_key = OPENAI_API_KEY
prompt = f"""Analyze the following resume and provide a detailed assessment.
Return your response as a JSON object with the following structure:
{{
"summary": "Brief overview of the candidate",
"skills": {{
"technical": ["list of technical skills"],
"soft": ["list of soft skills"],
"missing": ["important missing skills in this field"]
}},
"experience": {{
"highlights": ["key achievements and experiences"],
"concerns": ["any gaps or concerns in work history"]
}},
"education": {{
"details": "education background description",
"relevant": "how relevant is the education"
}},
"career_gaps": ["any identified gaps in career progression"],
"recommendations": [
"action items to improve resume",
"skills to develop",
"areas to strengthen"
],
"overall_score": {{"rating": 0-100, "explanation": "brief explanation"}},
"job_compatibility": {{
"strengths": ["matched competencies"],
"weaknesses": ["areas that need improvement for typical jobs"]
}}
}}
Resume text:
{resume_text}
Provide ONLY valid JSON response, no additional text."""
try:
response = openai.ChatCompletion.create(
model=MODEL_NAME,
messages=[
{"role": "system", "content": "You are an expert resume analyst and HR consultant."},
{"role": "user", "content": prompt}
],
temperature=TEMPERATURE,
max_tokens=MAX_TOKENS
)
analysis_text = response.choices[0].message.content
analysis = json.loads(analysis_text)
return analysis
except json.JSONDecodeError:
# If JSON parsing fails, return mock data
return get_mock_analysis()
except Exception as e:
print(f"Error calling OpenAI API: {e}")
return get_mock_analysis()
def get_mock_analysis():
"""Return mock analysis data for demo purposes"""
return {
"summary": "Experienced professional with strong technical background and leadership skills. Shows good career progression with relevant certifications.",
"skills": {
"technical": ["Python", "JavaScript", "SQL", "Git", "Docker", "APIs"],
"soft": ["Project Management", "Team Leadership", "Communication", "Problem-solving"],
"missing": ["Cloud Architecture (AWS/Azure)", "Machine Learning", "Advanced DevOps"]
},
"experience": {
"highlights": [
"Led cross-functional team of 5+ developers",
"Implemented automated testing increasing code coverage by 40%",
"Reduced deployment time by 60% through CI/CD optimization"
],
"concerns": ["Gap of 2 months between roles in 2021"]
},
"education": {
"details": "Bachelor's degree in Computer Science with relevant coursework",
"relevant": "Highly relevant to technical roles"
},
"career_gaps": [
"Limited experience with emerging technologies",
"No mention of continuous learning or certifications in last 2 years"
],
"recommendations": [
"Add quantifiable metrics to all achievements",
"Include recent certifications or training",
"Expand cloud platform experience section",
"Consider adding GitHub profile or portfolio link",
"Highlight specific results and ROI from projects"
],
"overall_score": {
"rating": 75,
"explanation": "Strong foundational experience with room for growth in emerging technologies"
},
"job_compatibility": {
"strengths": ["Solid programming fundamentals", "Team collaboration experience"],
"weaknesses": ["Limited cloud platform experience", "No mention of recent projects"]
}
}
def format_analysis_for_display(analysis):
"""
Format analysis dictionary for better display
Args:
analysis: Dictionary with analysis results
Returns:
Formatted analysis
"""
return analysis
|