Match2 / app.py
Unknown92's picture
Update app.py
f756b50
import streamlit as st
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
from keyphrasetransformer import KeyPhraseTransformer
from wordcloud import WordCloud
import matplotlib.pyplot as plt
import pandas as pd
kp = KeyPhraseTransformer()
@st.cache_resource
def load_model():
model = SentenceTransformer('all-MiniLM-L6-v2')
return model
def calculate_similarity(model, text1, text2):
embedding1 = model.encode([text1])
embedding2 = model.encode([text2])
return cosine_similarity(embedding1, embedding2)[0][0]
def generate_wordcloud(text, title):
wordcloud = WordCloud(width=800, height=400, background_color='white').generate(text)
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.title(title)
st.pyplot(plt)
st.title("Resume Analysis Assistant")
model = load_model()
# Set the font size for the "Paste the Job Description" text
st.markdown("<style>#fc1{font-size: 20px !important;}</style>", unsafe_allow_html=True)
jd = st.text_area("Paste the Job Description:", height=150)
resume = st.text_area("Paste Your the Resume:", height=150)
if st.button("GET MATCH SCORE & WORD CLOUD"):
if jd and resume:
jp = kp.get_key_phrases(jd)
rp = kp.get_key_phrases(resume)
# Generate word clouds for JD and Resume
generate_wordcloud(' '.join(jp), 'Word Cloud for Job Description Keywords')
generate_wordcloud(' '.join(rp), 'Word Cloud for Resume Keywords')
score = calculate_similarity(model, jd, resume)
# st.write(f"The match score is: {score}", )
# Display the match score as a percentage
score_percentage = f"{score * 100:.0f}%"
st.write("The match score is:")
st.write(score_percentage, key='match_score')
else:
st.write("Please enter both the job description and resume.", )
if st.button("GET KEYWORDS"):
if jd and resume:
jp = kp.get_key_phrases(jd)
rp = kp.get_key_phrases(resume)
# Find missing and matching keywords
missing_keywords = set(jp) - set(rp)
matching_keywords = set(jp) & set(rp)
# Make sure all arrays have the same length
max_length = max(len(jp), len(rp), len(matching_keywords), len(missing_keywords))
jp += [''] * (max_length - len(jp))
rp += [''] * (max_length - len(rp))
matching_keywords = list(matching_keywords) + [''] * (max_length - len(matching_keywords))
missing_keywords = list(missing_keywords) + [''] * (max_length - len(missing_keywords))
# Display keywords in a table
keywords_table_data = {
'Keywords From Job Description': jp,
'Keywords From Resume': rp,
'Matching Keywords': matching_keywords,
'Missing Keywords': missing_keywords
}
st.write("Keywords Overview:")
st.table(pd.DataFrame(keywords_table_data))
else:
st.write("Please enter both the job description and resume.", )