import streamlit as st from sentence_transformers import SentenceTransformer, util import re @st.cache_resource def load_model(): return SentenceTransformer('sentence-transformers/all-mpnet-base-v2') model = load_model() def keyword_match(job_desc, resume): job_keywords = set(re.findall(r'\b\w+\b', job_desc.lower())) resume_keywords = set(re.findall(r'\b\w+\b', resume.lower())) common_keywords = job_keywords.intersection(resume_keywords) return len(common_keywords) / len(job_keywords) * 100 if job_keywords else 0 st.title("Enhanced Resume and Job Description Similarity Checker") job_description = st.text_area("Paste the job description here:", height=200) resume_text = st.text_area("Paste your resume here:", height=200) if st.button("Compare"): if job_description.strip() and resume_text.strip(): # Calculate embeddings-based similarity job_description_embedding = model.encode(job_description) resume_embedding = model.encode(resume_text) similarity_score = util.cos_sim(job_description_embedding, resume_embedding).item() * 100 # Calculate keyword-based similarity keyword_score = keyword_match(job_description, resume_text) # Combine scores (you could adjust the weights as needed) overall_score = (similarity_score * 0.6) + (keyword_score * 0.4) st.write(f"**Similarity Score:** {overall_score:.2f}%") # Adjusted grading scale based on combined score if overall_score > 80: st.success("Excellent match! Your resume closely aligns with the job description.") elif overall_score > 65: st.info("Strong match! Your resume aligns well, but a few minor tweaks could help.") elif overall_score > 50: st.warning("Moderate match. Your resume has some relevant information, but consider emphasizing relevant skills.") elif overall_score > 35: st.error("Low match. Your resume does not align well. Consider revising to highlight key skills.") else: st.error("Very low match. Your resume is significantly different from the job description. Major revisions may be needed.") else: st.error("Please paste both the job description and your resume to proceed.")