laurenramroop commited on
Commit
e8552a6
·
verified ·
1 Parent(s): 1ae1b13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -72
app.py CHANGED
@@ -1,16 +1,6 @@
1
  import streamlit as st
2
  from sentence_transformers import SentenceTransformer, util
3
  import re
4
- import nltk
5
- from nltk.corpus import stopwords
6
- from nltk.tokenize import word_tokenize
7
-
8
- # Download NLTK data files
9
- nltk.download("stopwords")
10
- nltk.download("punkt")
11
-
12
- # Load English stop words
13
- stop_words = set(stopwords.words("english"))
14
 
15
  @st.cache_resource
16
  def load_model():
@@ -18,87 +8,39 @@ def load_model():
18
 
19
  model = load_model()
20
 
21
- # Synonym dictionary for common terms
22
- synonyms = {
23
- "data analysis": {"data analytics", "data analyst"},
24
- "machine learning": {"ml", "artificial intelligence", "ai"},
25
- "programming": {"coding", "development", "software engineering"},
26
- "statistical analysis": {"statistics", "statistical modeling"},
27
- "visualization": {"data viz", "tableau", "visualizing data"}
28
- }
29
-
30
- def preprocess(text):
31
- # Tokenize, remove stop words, and normalize text
32
- words = word_tokenize(text.lower())
33
- filtered_words = [word for word in words if word.isalnum() and word not in stop_words]
34
- normalized_text = " ".join(filtered_words)
35
- return normalized_text
36
-
37
- def synonym_match(job_desc, resume):
38
- match_count = 0
39
- total_keywords = 0
40
- matched_keywords = set()
41
- missing_keywords = set()
42
-
43
- for key, variants in synonyms.items():
44
- job_contains = any(term in job_desc for term in variants) or key in job_desc
45
- resume_contains = any(term in resume for term in variants) or key in resume
46
-
47
- if job_contains:
48
- total_keywords += 1
49
- if resume_contains:
50
- match_count += 1
51
- matched_keywords.add(key)
52
- else:
53
- missing_keywords.add(key)
54
-
55
- return (match_count / total_keywords) * 100 if total_keywords > 0 else 0, list(matched_keywords)[:5], list(missing_keywords)[:5]
56
-
57
  def keyword_match(job_desc, resume):
58
- job_keywords = set(re.findall(r'\b\w+\b', job_desc))
59
- resume_keywords = set(re.findall(r'\b\w+\b', resume))
60
  common_keywords = job_keywords.intersection(resume_keywords)
61
- return (len(common_keywords) / len(job_keywords)) * 100 if job_keywords else 0, list(common_keywords)[:5]
62
 
63
- st.title("Resume and Job Description Similarity Checker")
64
 
65
- job_description = st.text_area("Paste any job description here:", height=200)
66
  resume_text = st.text_area("Paste your resume here:", height=200)
67
 
68
  if st.button("Compare"):
69
  if job_description.strip() and resume_text.strip():
70
- # Preprocess text
71
- processed_job_desc = preprocess(job_description)
72
- processed_resume = preprocess(resume_text)
73
-
74
  # Calculate embeddings-based similarity
75
- job_description_embedding = model.encode(processed_job_desc)
76
- resume_embedding = model.encode(processed_resume)
77
  similarity_score = util.cos_sim(job_description_embedding, resume_embedding).item() * 100
78
 
79
- # Calculate keyword-based similarity and matched keywords
80
- keyword_score, matched_keywords = keyword_match(processed_job_desc, processed_resume)
81
-
82
- # Calculate synonym-based similarity and missing skills
83
- synonym_score, synonym_matches, synonym_misses = synonym_match(processed_job_desc, processed_resume)
84
 
85
- # Combine scores (adjusting weights as needed)
86
- overall_score = (similarity_score * 0.5) + (keyword_score * 0.3) + (synonym_score * 0.2)
87
 
88
- # Display the overall similarity score
89
- st.write(f"**Overall Similarity Score:** {overall_score:.2f}%")
90
 
91
- # Display matched keywords and missing skills
92
- st.write("**Matched Keywords:**", ", ".join(matched_keywords + synonym_matches)[:5])
93
- st.write("**Missing Skills to Consider Adding:**", ", ".join(synonym_misses)[:5])
94
-
95
- # Adjusted feedback based on combined score
96
  if overall_score > 80:
97
  st.success("Excellent match! Your resume closely aligns with the job description.")
98
  elif overall_score > 65:
99
  st.info("Strong match! Your resume aligns well, but a few minor tweaks could help.")
100
  elif overall_score > 50:
101
- st.warning("Moderate match. Your resume has some relevant information, but consider emphasizing key skills.")
102
  elif overall_score > 35:
103
  st.error("Low match. Your resume does not align well. Consider revising to highlight key skills.")
104
  else:
 
1
  import streamlit as st
2
  from sentence_transformers import SentenceTransformer, util
3
  import re
 
 
 
 
 
 
 
 
 
 
4
 
5
  @st.cache_resource
6
  def load_model():
 
8
 
9
  model = load_model()
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  def keyword_match(job_desc, resume):
12
+ job_keywords = set(re.findall(r'\b\w+\b', job_desc.lower()))
13
+ resume_keywords = set(re.findall(r'\b\w+\b', resume.lower()))
14
  common_keywords = job_keywords.intersection(resume_keywords)
15
+ return len(common_keywords) / len(job_keywords) * 100 if job_keywords else 0
16
 
17
+ st.title("Enhanced Resume and Job Description Similarity Checker")
18
 
19
+ job_description = st.text_area("Paste the job description here:", height=200)
20
  resume_text = st.text_area("Paste your resume here:", height=200)
21
 
22
  if st.button("Compare"):
23
  if job_description.strip() and resume_text.strip():
 
 
 
 
24
  # Calculate embeddings-based similarity
25
+ job_description_embedding = model.encode(job_description)
26
+ resume_embedding = model.encode(resume_text)
27
  similarity_score = util.cos_sim(job_description_embedding, resume_embedding).item() * 100
28
 
29
+ # Calculate keyword-based similarity
30
+ keyword_score = keyword_match(job_description, resume_text)
 
 
 
31
 
32
+ # Combine scores (you could adjust the weights as needed)
33
+ overall_score = (similarity_score * 0.6) + (keyword_score * 0.4)
34
 
35
+ st.write(f"**Similarity Score:** {overall_score:.2f}%")
 
36
 
37
+ # Adjusted grading scale based on combined score
 
 
 
 
38
  if overall_score > 80:
39
  st.success("Excellent match! Your resume closely aligns with the job description.")
40
  elif overall_score > 65:
41
  st.info("Strong match! Your resume aligns well, but a few minor tweaks could help.")
42
  elif overall_score > 50:
43
+ st.warning("Moderate match. Your resume has some relevant information, but consider emphasizing relevant skills.")
44
  elif overall_score > 35:
45
  st.error("Low match. Your resume does not align well. Consider revising to highlight key skills.")
46
  else: