Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,85 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
return
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import PyPDF2
|
3 |
+
import re
|
4 |
+
|
5 |
+
# Function to extract text from a PDF
|
6 |
+
def extract_text_from_pdf(uploaded_file):
|
7 |
+
pdf_reader = PyPDF2.PdfReader(uploaded_file)
|
8 |
+
text = " ".join([page.extract_text() for page in pdf_reader.pages if page.extract_text()])
|
9 |
+
return text
|
10 |
+
|
11 |
+
# Function to extract skills from text (reference resumes and user resumes)
|
12 |
+
def extract_skills_from_text(text):
|
13 |
+
# A simple way to extract skills based on words in the resume.
|
14 |
+
# This can be more advanced by integrating NER (Named Entity Recognition) or using predefined skill lists.
|
15 |
+
skills = re.findall(r'\b[A-Za-z]+\b', text.lower()) # Extract words
|
16 |
+
skills = set(skills) # Remove duplicates
|
17 |
+
return skills
|
18 |
+
|
19 |
+
# Function to evaluate user's resume based on job description
|
20 |
+
def evaluate_resume(candidate_text, job_description_text):
|
21 |
+
# Extract skills dynamically from job description
|
22 |
+
job_description_skills = extract_skills_from_text(job_description_text)
|
23 |
+
|
24 |
+
# Extract skills from candidate's resume
|
25 |
+
candidate_skills = extract_skills_from_text(candidate_text)
|
26 |
+
|
27 |
+
# Calculate matching skills
|
28 |
+
matching_skills = job_description_skills.intersection(candidate_skills)
|
29 |
+
missing_skills = job_description_skills.difference(candidate_skills)
|
30 |
+
|
31 |
+
# Calculate improvement skills (skills present in the JD but not in candidate's resume)
|
32 |
+
improvement_skills = job_description_skills.difference(matching_skills)
|
33 |
+
|
34 |
+
# Calculate matching percentage (based on skills)
|
35 |
+
matching_percentage = (len(matching_skills) / len(job_description_skills)) * 100 if len(job_description_skills) > 0 else 0
|
36 |
+
|
37 |
+
result = {
|
38 |
+
"matching_skills": list(matching_skills),
|
39 |
+
"missing_skills": list(missing_skills),
|
40 |
+
"improvement_skills": list(improvement_skills),
|
41 |
+
"matching_percentage": round(matching_percentage, 2)
|
42 |
+
}
|
43 |
+
|
44 |
+
return result
|
45 |
+
|
46 |
+
# Streamlit UI
|
47 |
+
st.title("π Resume Screening with Job Description Matching")
|
48 |
+
st.write("Upload a candidate's resume and provide a job description to check the matching percentage based on skills.")
|
49 |
+
|
50 |
+
# Upload job description
|
51 |
+
st.subheader("Upload Job Description")
|
52 |
+
job_description_file = st.file_uploader("Upload Job Description (PDF)", type=["pdf"])
|
53 |
+
|
54 |
+
# Upload candidate resume
|
55 |
+
st.subheader("Upload Candidate Resume")
|
56 |
+
uploaded_file = st.file_uploader("Upload Candidate Resume (PDF)", type=["pdf"])
|
57 |
+
|
58 |
+
if uploaded_file and job_description_file:
|
59 |
+
st.write("π **Processing resume and job description...**")
|
60 |
+
|
61 |
+
# Extract text from candidate resume
|
62 |
+
candidate_text = extract_text_from_pdf(uploaded_file)
|
63 |
+
|
64 |
+
# Extract text from job description
|
65 |
+
job_description_text = extract_text_from_pdf(job_description_file)
|
66 |
+
|
67 |
+
# Evaluate resume based on job description
|
68 |
+
evaluation = evaluate_resume(candidate_text, job_description_text)
|
69 |
+
|
70 |
+
# Display results
|
71 |
+
st.subheader("π Evaluation Result:")
|
72 |
+
st.write(f"**π’ Matching Percentage:** {evaluation['matching_percentage']}%")
|
73 |
+
# st.write(f"**β
Matching Skills:** {', '.join(evaluation['matching_skills']) or 'None'}")
|
74 |
+
# st.write(f"**β Missing Skills:** {', '.join(evaluation['missing_skills']) or 'None'}")
|
75 |
+
st.write(f"**π‘ Improvement Skills (Required but Missing):** {', '.join(evaluation['improvement_skills']) or 'None'}")
|
76 |
+
|
77 |
+
|
78 |
+
if evaluation["matching_percentage"] > 70:
|
79 |
+
st.success("β
Resume is a strong match for the job description!")
|
80 |
+
elif evaluation["matching_percentage"] > 40:
|
81 |
+
st.warning("β οΈ Resume is a partial match for the job description.")
|
82 |
+
else:
|
83 |
+
st.error("β Resume does not match well with the job description.")
|
84 |
+
else:
|
85 |
+
st.write("Please upload both the job description and candidate resume.")
|