usmanyousaf commited on
Commit
ffd40da
1 Parent(s): 09d7b43

create app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ import pdfplumber
4
+ from fuzzywuzzy import fuzz
5
+ from sklearn.metrics.pairwise import cosine_similarity
6
+ import spacy
7
+
8
+ # Load the SpaCy model
9
+ nlp = spacy.load("en_core_web_sm")
10
+
11
+ # Function to extract entities from text
12
+ def extract_entities(text):
13
+ doc = nlp(text)
14
+ entities = {ent.label_: ent.text for ent in doc.ents}
15
+ return entities
16
+
17
+ # Function to compute matching score
18
+ def compute_advanced_matching_score(cv_text, cv_entities, required_education, required_skills, required_experience):
19
+ score = 0
20
+
21
+ # Named Entity Recognition Matching for Education
22
+ education = cv_entities.get('EDU', '')
23
+ score += fuzz.token_set_ratio(education, required_education) / 100
24
+
25
+ # Fuzzy Matching for Skills
26
+ for skill in required_skills:
27
+ max_skill_match_score = max([fuzz.token_set_ratio(skill, skill_in_cv) for skill_in_cv in cv_text.split()] + [0])
28
+ score += max_skill_match_score / 100
29
+
30
+ # Vector Similarity Matching for Experience
31
+ experience_text = cv_entities.get('DATE', '')
32
+ doc1 = nlp(experience_text)
33
+ doc2 = nlp(f"{required_experience} years")
34
+ score += cosine_similarity(doc1.vector.reshape(1, -1), doc2.vector.reshape(1, -1))[0][0]
35
+
36
+ return score
37
+
38
+ # Function to process CVs and compute scores
39
+ def process_cvs(uploaded_files, required_education, required_skills, required_experience, top_cvs_count):
40
+ cv_scores = {}
41
+ for uploaded_file in uploaded_files:
42
+ file_extension = uploaded_file.name.split('.')[-1]
43
+ if file_extension in ["pdf"]:
44
+ with pdfplumber.open(uploaded_file) as pdf:
45
+ text = ''
46
+ for page in pdf.pages:
47
+ text += page.extract_text()
48
+ entities = extract_entities(text)
49
+ cv_scores[uploaded_file.name] = compute_advanced_matching_score(text, entities, required_education, required_skills, required_experience)
50
+
51
+ top_cvs = sorted(cv_scores.items(), key=lambda x: x[1], reverse=True)[:top_cvs_count]
52
+ return top_cvs
53
+
54
+ def main():
55
+ st.markdown('<style>h1{text-align:center;}</style>', unsafe_allow_html=True) # Center-align the title
56
+ st.title("Resume Filtering App")
57
+
58
+
59
+ uploaded_files = st.file_uploader("Upload Resume Files", type=["pdf"], accept_multiple_files=True)
60
+ required_education = st.text_input("Required Education")
61
+ required_skills = st.text_input("Required Skills (comma-separated)")
62
+ required_experience = st.text_input("Required Experience")
63
+ top_cvs_count = st.number_input("Number of Top Resume to Display", min_value=1, step=1, value=3)
64
+
65
+ if st.button("Match Resume"):
66
+ if uploaded_files and required_education and required_skills and required_experience:
67
+ required_skills = [skill.strip() for skill in required_skills.split(',')]
68
+ top_cvs = process_cvs(uploaded_files, required_education, required_skills, required_experience, top_cvs_count)
69
+ st.subheader("Top Matching Resume:")
70
+ for filename, score in top_cvs:
71
+ st.write(f"{filename}: {score:.2f}")
72
+
73
+ if __name__ == "__main__":
74
+ main()