Update app.py
Browse files
app.py
CHANGED
|
@@ -5,14 +5,39 @@ from sentence_transformers import SentenceTransformer, util
|
|
| 5 |
from gtts import gTTS
|
| 6 |
import tempfile
|
| 7 |
|
| 8 |
-
# Load model
|
| 9 |
model = SentenceTransformer("all-MiniLM-L6-v2")
|
| 10 |
|
|
|
|
| 11 |
top_skills = [
|
| 12 |
-
|
| 13 |
-
"Machine Learning", "
|
| 14 |
-
|
| 15 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
]
|
| 17 |
|
| 18 |
def extract_text_from_pdf(pdf_file):
|
|
@@ -26,14 +51,10 @@ def extract_text_from_docx(docx_file):
|
|
| 26 |
doc = docx.Document(docx_file)
|
| 27 |
return "\n".join([p.text for p in doc.paragraphs])
|
| 28 |
|
| 29 |
-
def
|
| 30 |
-
summary = "This resume highlights skills in " + ", ".join(list(set(analyze_resume(text)[0].split(", ")))) + "."
|
| 31 |
-
return summary
|
| 32 |
-
|
| 33 |
-
def analyze_resume(text):
|
| 34 |
sentences = [s.strip() for s in text.split(".") if len(s.strip()) > 5]
|
| 35 |
if not sentences:
|
| 36 |
-
return
|
| 37 |
|
| 38 |
sentence_embeddings = model.encode(sentences, convert_to_tensor=True)
|
| 39 |
skill_embeddings = model.encode(top_skills, convert_to_tensor=True)
|
|
@@ -46,24 +67,26 @@ def analyze_resume(text):
|
|
| 46 |
if score > 0.4:
|
| 47 |
found_skills.append(skill)
|
| 48 |
|
| 49 |
-
job_titles = []
|
| 50 |
-
if "Python" in found_skills and "Data Analysis" in found_skills:
|
| 51 |
-
job_titles.append("Data Analyst")
|
| 52 |
-
if "JavaScript" in found_skills and "React" in found_skills:
|
| 53 |
-
job_titles.append("Frontend Developer")
|
| 54 |
-
if "Project Management" in found_skills:
|
| 55 |
-
job_titles.append("Project Manager")
|
| 56 |
-
if "Machine Learning" in found_skills:
|
| 57 |
-
job_titles.append("ML Engineer")
|
| 58 |
-
if not job_titles:
|
| 59 |
-
job_titles.append("General Tech Roles")
|
| 60 |
-
|
| 61 |
missing_skills = [s for s in top_skills if s not in found_skills]
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
def score_resume(found_skills):
|
| 66 |
-
score = int(len(found_skills
|
| 67 |
return min(score, 100)
|
| 68 |
|
| 69 |
def save_report(text, skills, jobs, missing, summary, score):
|
|
@@ -111,14 +134,17 @@ def process_resume(file_obj):
|
|
| 111 |
else:
|
| 112 |
return "Unsupported file format", "", "", "", "", "", None, None
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
# Build the UI
|
| 124 |
with gr.Blocks(theme="soft") as demo:
|
|
|
|
| 5 |
from gtts import gTTS
|
| 6 |
import tempfile
|
| 7 |
|
| 8 |
+
# Load the model
|
| 9 |
model = SentenceTransformer("all-MiniLM-L6-v2")
|
| 10 |
|
| 11 |
+
# Define a multi-domain skill set
|
| 12 |
top_skills = [
|
| 13 |
+
# Tech
|
| 14 |
+
"Python", "JavaScript", "SQL", "Machine Learning", "AWS", "Docker", "React",
|
| 15 |
+
# Marketing
|
| 16 |
+
"SEO", "Content Creation", "Brand Management", "Google Analytics", "Social Media Marketing",
|
| 17 |
+
# Finance
|
| 18 |
+
"Financial Analysis", "Accounting", "Risk Management",
|
| 19 |
+
# Healthcare
|
| 20 |
+
"Patient Care", "Diagnosis", "Treatment Planning",
|
| 21 |
+
# Education
|
| 22 |
+
"Lesson Planning", "Curriculum Design", "Classroom Management",
|
| 23 |
+
# Soft Skills
|
| 24 |
+
"Communication", "Leadership", "Teamwork", "Problem Solving", "Critical Thinking"
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
# Job mapping
|
| 28 |
+
job_roles = [
|
| 29 |
+
("Data Analyst", {"Python", "SQL", "Data Analysis"}),
|
| 30 |
+
("Frontend Developer", {"JavaScript", "React"}),
|
| 31 |
+
("Backend Developer", {"Python", "Docker", "AWS"}),
|
| 32 |
+
("Machine Learning Engineer", {"Machine Learning", "Python"}),
|
| 33 |
+
("Marketing Manager", {"SEO", "Content Creation", "Brand Management"}),
|
| 34 |
+
("Digital Marketer", {"Google Analytics", "Social Media Marketing", "Content Creation"}),
|
| 35 |
+
("Financial Analyst", {"Financial Analysis", "Accounting"}),
|
| 36 |
+
("Risk Manager", {"Risk Management", "Accounting"}),
|
| 37 |
+
("Nurse", {"Patient Care", "Diagnosis"}),
|
| 38 |
+
("Healthcare Administrator", {"Treatment Planning", "Leadership"}),
|
| 39 |
+
("Teacher", {"Lesson Planning", "Classroom Management"}),
|
| 40 |
+
("Project Manager", {"Leadership", "Project Management"})
|
| 41 |
]
|
| 42 |
|
| 43 |
def extract_text_from_pdf(pdf_file):
|
|
|
|
| 51 |
doc = docx.Document(docx_file)
|
| 52 |
return "\n".join([p.text for p in doc.paragraphs])
|
| 53 |
|
| 54 |
+
def detect_skills(text):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
sentences = [s.strip() for s in text.split(".") if len(s.strip()) > 5]
|
| 56 |
if not sentences:
|
| 57 |
+
return [], []
|
| 58 |
|
| 59 |
sentence_embeddings = model.encode(sentences, convert_to_tensor=True)
|
| 60 |
skill_embeddings = model.encode(top_skills, convert_to_tensor=True)
|
|
|
|
| 67 |
if score > 0.4:
|
| 68 |
found_skills.append(skill)
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
missing_skills = [s for s in top_skills if s not in found_skills]
|
| 71 |
+
return found_skills, missing_skills
|
| 72 |
+
|
| 73 |
+
def suggest_jobs(found_skills):
|
| 74 |
+
matched_jobs = []
|
| 75 |
+
skill_set = set(found_skills)
|
| 76 |
+
for title, required_skills in job_roles:
|
| 77 |
+
if required_skills.issubset(skill_set):
|
| 78 |
+
matched_jobs.append(title)
|
| 79 |
+
if not matched_jobs:
|
| 80 |
+
matched_jobs.append("General Roles")
|
| 81 |
+
return matched_jobs
|
| 82 |
+
|
| 83 |
+
def summarize_resume(found_skills):
|
| 84 |
+
if not found_skills:
|
| 85 |
+
return "No clear skills detected in resume."
|
| 86 |
+
return "This resume highlights skills in " + ", ".join(found_skills) + "."
|
| 87 |
|
| 88 |
def score_resume(found_skills):
|
| 89 |
+
score = int(len(found_skills) / len(top_skills) * 100)
|
| 90 |
return min(score, 100)
|
| 91 |
|
| 92 |
def save_report(text, skills, jobs, missing, summary, score):
|
|
|
|
| 134 |
else:
|
| 135 |
return "Unsupported file format", "", "", "", "", "", None, None
|
| 136 |
|
| 137 |
+
found_skills, missing_skills = detect_skills(resume_text)
|
| 138 |
+
job_titles = suggest_jobs(found_skills)
|
| 139 |
+
summary = summarize_resume(found_skills)
|
| 140 |
+
skills_str = ", ".join(found_skills)
|
| 141 |
+
jobs_str = ", ".join(job_titles)
|
| 142 |
+
missing_str = ", ".join(missing_skills[:5])
|
| 143 |
+
score = score_resume(found_skills)
|
| 144 |
+
report_path = save_report(resume_text, skills_str, jobs_str, missing_str, summary, score)
|
| 145 |
+
audio_path = text_to_speech(jobs_str)
|
| 146 |
+
|
| 147 |
+
return resume_text, summary, skills_str, jobs_str, missing_str, f"{score}/100", report_path, audio_path
|
| 148 |
|
| 149 |
# Build the UI
|
| 150 |
with gr.Blocks(theme="soft") as demo:
|