Spaces:
Sleeping
Sleeping
Create utils.py
Browse files
utils.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spacy
|
| 2 |
+
import fitz # PyMuPDF
|
| 3 |
+
import re
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
def load_models():
|
| 7 |
+
nlp = spacy.load("en_core_web_sm")
|
| 8 |
+
llm = pipeline("text-generation", model="openai-community/gpt2")
|
| 9 |
+
return nlp, llm
|
| 10 |
+
|
| 11 |
+
def parse_resume(uploaded_file, nlp):
|
| 12 |
+
doc = fitz.open(stream=uploaded_file.read(), filetype="pdf")
|
| 13 |
+
text = "\n".join(page.get_text() for page in doc)
|
| 14 |
+
doc = nlp(text)
|
| 15 |
+
name = [ent.text for ent in doc.ents if ent.label_ == "PERSON"]
|
| 16 |
+
email = re.findall(r"[\w\.-]+@[\w\.-]+", text)
|
| 17 |
+
skills = [token.text.lower() for token in doc if token.pos_ == "NOUN"]
|
| 18 |
+
edu_keywords = ["bachelor", "master", "phd", "degree", "certification", "diploma"]
|
| 19 |
+
edu = [sent.text for sent in doc.sents if any(k in sent.text.lower() for k in edu_keywords)]
|
| 20 |
+
return text, {
|
| 21 |
+
"name": name[0] if name else "N/A",
|
| 22 |
+
"email": email[0] if email else "N/A",
|
| 23 |
+
"skills": list(set(skills)),
|
| 24 |
+
"education": edu,
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
def get_recommendations(parsed):
|
| 28 |
+
score = 50 + len(parsed["skills"]) % 50
|
| 29 |
+
feedback = "Try adding more specific technical skills and quantifiable achievements."
|
| 30 |
+
return score, feedback
|
| 31 |
+
|
| 32 |
+
def generate_career_insights(parsed, llm, suggestion_type="roadmap"):
|
| 33 |
+
prompt_map = {
|
| 34 |
+
"certifications": f"Suggest relevant certifications for someone with skills: {parsed['skills']} and education: {parsed['education']}",
|
| 35 |
+
"degrees": f"Suggest higher education paths based on: {parsed['education']}",
|
| 36 |
+
"roadmap": f"Create a 1-year career roadmap for someone with these skills: {parsed['skills']} and education: {parsed['education']}",
|
| 37 |
+
"counselor": f"Act like a career counselor. Give personalized advice to this candidate: Skills={parsed['skills']} Education={parsed['education']}"
|
| 38 |
+
}
|
| 39 |
+
res = llm(prompt_map[suggestion_type], max_length=512, do_sample=True, temperature=0.7)
|
| 40 |
+
return res[0]['generated_text']
|