laurenramroop commited on
Commit
46a124f
·
verified ·
1 Parent(s): d728f53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -18
app.py CHANGED
@@ -1,6 +1,16 @@
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,38 +18,80 @@ 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
- match_ratio = len(common_keywords) / len(job_keywords) * 100
16
- return match_ratio
17
 
18
- st.title("Enhanced Resume and Job Description Similarity Checker")
19
 
20
  job_description = st.text_area("Paste the job description here:", height=200)
21
  resume_text = st.text_area("Paste your resume here:", height=200)
22
 
23
  if st.button("Compare"):
24
  if job_description.strip() and resume_text.strip():
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
- keyword_score = keyword_match(job_description, resume_text)
 
 
 
 
 
29
 
30
- # Combine scores (weighted or simple average)
31
- overall_score = (similarity_score * 0.7) + (keyword_score * 0.3)
32
 
33
- st.write(f"**Similarity Score:** {overall_score:.2f}%")
34
 
35
- # Adjusted feedback
36
- if overall_score > 70:
37
- st.success("Great match! Your resume aligns well with the job description.")
 
 
38
  elif overall_score > 50:
39
- st.info("Good match! Your resume has relevant information, but it could be tailored a bit more.")
40
- elif overall_score > 30:
41
- st.warning("Partial match. Your resume shows some alignment, but consider emphasizing relevant skills and experiences.")
42
  else:
43
- st.error("Low match. Consider revising your resume to better reflect the job requirements.")
44
  else:
45
  st.error("Please paste both the job description and your resume to proceed.")
 
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 stop words if not already available
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
 
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
+
41
+ for key, variants in synonyms.items():
42
+ job_contains = any(term in job_desc for term in variants) or key in job_desc
43
+ resume_contains = any(term in resume for term in variants) or key in resume
44
+
45
+ if job_contains:
46
+ total_keywords += 1
47
+ if resume_contains:
48
+ match_count += 1
49
+
50
+ return (match_count / total_keywords) * 100 if total_keywords > 0 else 0
51
+
52
  def keyword_match(job_desc, resume):
53
+ job_keywords = set(re.findall(r'\b\w+\b', job_desc))
54
+ resume_keywords = set(re.findall(r'\b\w+\b', resume))
55
  common_keywords = job_keywords.intersection(resume_keywords)
56
+ return (len(common_keywords) / len(job_keywords)) * 100 if job_keywords else 0
 
57
 
58
+ st.title("Advanced Resume and Job Description Similarity Checker")
59
 
60
  job_description = st.text_area("Paste the job description here:", height=200)
61
  resume_text = st.text_area("Paste your resume here:", height=200)
62
 
63
  if st.button("Compare"):
64
  if job_description.strip() and resume_text.strip():
65
+ # Preprocess text
66
+ processed_job_desc = preprocess(job_description)
67
+ processed_resume = preprocess(resume_text)
68
+
69
+ # Calculate embeddings-based similarity
70
+ job_description_embedding = model.encode(processed_job_desc)
71
+ resume_embedding = model.encode(processed_resume)
72
  similarity_score = util.cos_sim(job_description_embedding, resume_embedding).item() * 100
73
+
74
+ # Calculate keyword-based similarity
75
+ keyword_score = keyword_match(processed_job_desc, processed_resume)
76
+
77
+ # Calculate synonym-based similarity
78
+ synonym_score = synonym_match(processed_job_desc, processed_resume)
79
 
80
+ # Combine scores (adjusting weights as needed)
81
+ overall_score = (similarity_score * 0.5) + (keyword_score * 0.3) + (synonym_score * 0.2)
82
 
83
+ st.write(f"**Overall Similarity Score:** {overall_score:.2f}%")
84
 
85
+ # Adjusted feedback based on combined score
86
+ if overall_score > 80:
87
+ st.success("Excellent match! Your resume closely aligns with the job description.")
88
+ elif overall_score > 65:
89
+ st.info("Strong match! Your resume aligns well, but a few minor tweaks could help.")
90
  elif overall_score > 50:
91
+ st.warning("Moderate match. Your resume has some relevant information, but consider emphasizing key skills.")
92
+ elif overall_score > 35:
93
+ st.error("Low match. Your resume does not align well. Consider revising to highlight key skills.")
94
  else:
95
+ st.error("Very low match. Your resume is significantly different from the job description. Major revisions may be needed.")
96
  else:
97
  st.error("Please paste both the job description and your resume to proceed.")