File size: 2,590 Bytes
ef86076
5ef04ed
ef86076
 
 
 
 
b5b5de2
5ef04ed
 
 
 
 
ef86076
b5b5de2
 
 
ce78876
ef86076
 
 
b5b5de2
ce78876
b5b5de2
 
 
ef86076
b5b5de2
ce78876
ef86076
b5b5de2
 
 
 
ef86076
 
 
b5b5de2
 
ef86076
 
 
ce78876
 
 
 
b5b5de2
ce78876
b5b5de2
 
ce78876
 
b5b5de2
 
ce78876
 
b5b5de2
 
ce78876
 
b5b5de2
 
ce78876
ef86076
ce78876
b5b5de2
 
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
import spacy
from spacy.cli import download
import fitz  # PyMuPDF
import re
from transformers import pipeline

def load_models():
    # Try loading spaCy model; download if missing
    try:
        nlp = spacy.load("en_core_web_sm")
    except OSError:
        download("en_core_web_sm")
        nlp = spacy.load("en_core_web_sm")

    # Use a fast summarization model instead of GPT-2
    llm = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
    return nlp, llm

def parse_resume(uploaded_file, nlp):
    doc = fitz.open(stream=uploaded_file.read(), filetype="pdf")
    text = "\n".join(page.get_text() for page in doc)
    doc = nlp(text)

    name = [ent.text for ent in doc.ents if ent.label_ == "PERSON"]
    email = re.findall(r"[\w\.-]+@[\w\.-]+", text)
    skills = [token.text.lower() for token in doc if token.pos_ == "NOUN"]
    edu_keywords = ["bachelor", "master", "phd", "degree", "certification", "diploma"]
    edu = [sent.text for sent in doc.sents if any(k in sent.text.lower() for k in edu_keywords)]

    return text, {
        "name": name[0] if name else "N/A",
        "email": email[0] if email else "N/A",
        "skills": list(set(skills)),
        "education": edu,
    }

def get_recommendations(parsed):
    score = 50 + len(parsed["skills"]) % 50
    feedback = "Try adding more specific technical skills and quantifiable achievements."
    return score, feedback

def generate_career_insights(parsed, llm, suggestion_type="roadmap"):
    name = parsed.get("name", "Candidate")
    skills = ", ".join(parsed["skills"][:10]) if parsed["skills"] else "unspecified"
    education = "; ".join(parsed["education"][:3]) if parsed["education"] else "not mentioned"

    input_text_map = {
        "certifications": (
            f"Candidate has skills in: {skills}. With education: {education}. "
            "Summarize relevant certifications they can pursue."
        ),
        "degrees": (
            f"Given the education background: {education}, summarize higher education degrees "
            "that can help in career advancement."
        ),
        "roadmap": (
            f"Create a short 1-year career roadmap for someone with skills: {skills} "
            f"and education: {education}. Suggest goals."
        ),
        "counselor": (
            f"As a career advisor, suggest top 3 career moves for a person skilled in {skills} "
            f"with education in {education}."
        )
    }

    result = llm(input_text_map[suggestion_type], max_length=150, min_length=50, do_sample=False)
    return result[0]["summary_text"]