nlpblogs's picture
Update app.py
a1c7830 verified
raw
history blame
7.7 kB
import streamlit as st
from PyPDF2 import PdfReader
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
from gliner import GLiNER
import plotly.express as px
with st.sidebar:
st.button("DEMO APP", type="primary")
expander = st.expander("**Important notes on the AI Resume Analysis based on Keywords App**")
expander.write('''
**Supported File Formats**
This app accepts files in .pdf formats.
**How to Use**
Paste the job description first. Then, upload your resume to retrieve the results. You can upload up to 10 resumes in total.
**Usage Limits**
You can request results up to 10 times in total.
**Subscription Management**
This demo app offers a one-day subscription, expiring after 24 hours. If you are interested in building your own AI Resume Analysis based on Keywords Web App, we invite you to explore our NLP Web App Store on our website. You can select your desired features, place your order, and we will deliver your custom app within five business days. If you wish to delete your Account with us, please contact us at [email protected]
**Customization**
To change the app's background color to white or black, click the three-dot menu on the right-hand side of your app, go to Settings and then Choose app theme, colors and fonts.
**File Handling and Errors**
The app may display an error message if your file is corrupt, or has other errors.
For any errors or inquiries, please contact us at [email protected]
''')
st.subheader("Candidate Profile 1", divider="red")
txt = st.text_area("Paste the job description and then press Ctrl + Enter", key="text 1")
job = pd.Series(txt, name="Text")
if 'upload_count' not in st.session_state:
st.session_state['upload_count'] = 0
max_attempts = 3
if st.session_state['upload_count'] < max_attempts:
uploaded_files = st.file_uploader(
"Upload your resume", accept_multiple_files=True, type="pdf", key="candidate 1"
)
if uploaded_files:
st.session_state['upload_count'] += 1
for uploaded_file in uploaded_files:
pdf_reader = PdfReader(uploaded_file)
text_data = ""
for page in pdf_reader.pages:
text_data += page.extract_text()
data = pd.Series(text_data, name='Text')
frames = [job, data]
result = pd.concat(frames)
model = pipeline("ner", model="urchade/gliner_base", aggregation_strategy="simple")
labels = ["person", "country", "organization", "date", "time", "role", "skills", "year"]
entities = model(text_data, labels=labels)
df = pd.DataFrame(entities)
st.subheader("Profile of candidate 1", divider="green")
fig1 = px.treemap(entities, path=[px.Constant("all"), 'text', 'label'],
values='score', color='label')
fig1.update_layout(margin=dict(t=50, l=25, r=25, b=25))
st.plotly_chart(fig1, key = "Figure 1")
vectorizer = TfidfVectorizer()
tfidf_matrix = vectorizer.fit_transform(result)
tfidf_df = pd.DataFrame(tfidf_matrix.toarray(), columns=vectorizer.get_feature_names_out())
cosine_sim_matrix = cosine_similarity(tfidf_matrix)
cosine_sim_df = pd.DataFrame(cosine_sim_matrix)
st.subheader("Measuring similarity between keywords of candidate profile 1 and job description", divider="green")
fig2 = px.imshow(cosine_sim_df, text_auto=True,
labels=dict(x="Keyword similarity", y="Resumes", color="Productivity"),
x=['Resume 1', 'Job Description'],
y=['Resume 1', 'Job Description'])
st.plotly_chart(fig2, key = "Figure 2")
for i, similarity_score in enumerate(cosine_sim_matrix[0][1:]):
st.write(f"Similarity of job description with candidate profile 1. {i + 1}: {similarity_score:.4f}")
st.info("A score closer to 1 (0.80, 0.90) means higher similarity between candidate profile 1 and job description. A score closer to 0 (0.20, 0.30) means lower similarity between candidate profile 1 and job description.")
else:
st.warning(f"You have reached the maximum upload attempts ({max_attempts}).")
if 'upload_count' in st.session_state and st.session_state['upload_count'] > 0:
st.info(f"Files uploaded {st.session_state['upload_count']} time(s).")
st.subheader("Candidate Profile 2", divider="red")
txt = st.text_area("Paste the job description and then press Ctrl + Enter", key="text 1")
job = pd.Series(txt, name="Text")
if 'upload_count' not in st.session_state:
st.session_state['upload_count'] = 0
max_attempts = 3
if st.session_state['upload_count'] < max_attempts:
uploaded_files = st.file_uploader(
"Upload your resume", accept_multiple_files=True, type="pdf", key="candidate 1"
)
if uploaded_files:
st.session_state['upload_count'] += 1
for uploaded_file in uploaded_files:
pdf_reader = PdfReader(uploaded_file)
text_data = ""
for page in pdf_reader.pages:
text_data += page.extract_text()
data = pd.Series(text_data, name='Text')
frames = [job, data]
result = pd.concat(frames)
model = pipeline("ner", model="urchade/gliner_base", aggregation_strategy="simple")
labels = ["person", "country", "organization", "date", "time", "role", "skills", "year"]
entities = model(text_data, labels=labels)
df = pd.DataFrame(entities)
st.subheader("Profile of candidate 1", divider="green")
fig3 = px.treemap(entities, path=[px.Constant("all"), 'text', 'label'],
values='score', color='label')
fig3.update_layout(margin=dict(t=50, l=25, r=25, b=25))
st.plotly_chart(fig3, key = "Figure 3")
vectorizer = TfidfVectorizer()
tfidf_matrix = vectorizer.fit_transform(result)
tfidf_df = pd.DataFrame(tfidf_matrix.toarray(), columns=vectorizer.get_feature_names_out())
cosine_sim_matrix = cosine_similarity(tfidf_matrix)
cosine_sim_df = pd.DataFrame(cosine_sim_matrix)
st.subheader("Measuring similarity between keywords of candidate profile 1 and job description", divider="green")
fig4 = px.imshow(cosine_sim_df, text_auto=True,
labels=dict(x="Keyword similarity", y="Resumes", color="Productivity"),
x=['Resume 1', 'Job Description'],
y=['Resume 1', 'Job Description'])
st.plotly_chart(fig4, key = "Figure 4")
for i, similarity_score in enumerate(cosine_sim_matrix[0][1:]):
st.write(f"Similarity of job description with candidate profile 1. {i + 1}: {similarity_score:.4f}")
st.info("A score closer to 1 (0.80, 0.90) means higher similarity between candidate profile 1 and job description. A score closer to 0 (0.20, 0.30) means lower similarity between candidate profile 1 and job description.")
else:
st.warning(f"You have reached the maximum upload attempts ({max_attempts}).")
if 'upload_count' in st.session_state and st.session_state['upload_count'] > 0:
st.info(f"Files uploaded {st.session_state['upload_count']} time(s).")