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 import time 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 the resume of each applicant to retrieve the results. **Usage Limits** For each applicant you can upload their resume and request results once (1 request per applicant's resume). At the bottom of the app, you can also upload an applicant's resume once (1 request) to visualize their profile as a treemap chart as well as the results in a matrix heatmap. If you hover over the interactive graphs, an icon will appear to download them. **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 info@nlpblogs.com **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 info@nlpblogs.com ''') st.title("AI Resume Analysis based on Keywords App") st.divider() job = pd.Series(st.text_area("Paste the job description and then press Ctrl + Enter", key="job_desc"), name="Text") if 'applicant_data' not in st.session_state: st.session_state['applicant_data'] = {} max_attempts = 1 for i in range(1, 51): # Looping for 2 applicants st.subheader(f"Applicant {i} Resume", divider="green") applicant_key = f"applicant_{i}" upload_key = f"candidate_{i}" if applicant_key not in st.session_state['applicant_data']: st.session_state['applicant_data'][applicant_key] = {'upload_count': 0, 'uploaded_file': None, 'analysis_done': False} if st.session_state['applicant_data'][applicant_key]['upload_count'] < max_attempts: uploaded_file = st.file_uploader(f"Upload Applicant's {i} resume", type="pdf", key=upload_key) if uploaded_file: st.session_state['applicant_data'][applicant_key]['uploaded_file'] = uploaded_file st.session_state['applicant_data'][applicant_key]['upload_count'] += 1 st.session_state['applicant_data'][applicant_key]['analysis_done'] = False # Reset analysis flag if st.session_state['applicant_data'][applicant_key]['uploaded_file'] and not st.session_state['applicant_data'][applicant_key]['analysis_done']: pdf_reader = PdfReader(st.session_state['applicant_data'][applicant_key]['uploaded_file']) text_data = "" for page in pdf_reader.pages: text_data += page.extract_text() with st.expander(f"See Applicant's {i} resume"): st.write(text_data) data = pd.Series(text_data, name='Text') result = pd.concat([job, data]) vectorizer = TfidfVectorizer(stop_words = 'english') tfidf_matrix = vectorizer.fit_transform(result) cosine_sim_matrix = cosine_similarity(tfidf_matrix) for j, similarity_score in enumerate(cosine_sim_matrix[0][1:]): with st.popover(f"See Result for Applicant {i}"): st.write(f"Similarity between Applicant's resume and job description based on keywords: {similarity_score:.2f}") st.info( f"A score closer to 1 (0.80, 0.90) means higher similarity between Applicant's {i} resume and job description. A score closer to 0 (0.20, 0.30) means lower similarity between Applicant's {i} resume and job description.") st.session_state['applicant_data'][applicant_key]['analysis_done'] = True else: st.warning(f"Maximum upload attempts has been reached ({max_attempts}).") if st.session_state['applicant_data'][applicant_key]['upload_count'] > 0: st.info(f"Files uploaded for Applicant {i}: {st.session_state['applicant_data'][applicant_key]['upload_count']} time(s).") st.divider() st.subheader("Visualise", divider="blue") if 'upload_count' not in st.session_state: st.session_state['upload_count'] = 0 max_attempts = 1 if st.session_state['upload_count'] < max_attempts: uploaded_files = st.file_uploader("Upload Applicant's resume", type="pdf", key="applicant 1") if uploaded_files: st.session_state['upload_count'] += 1 with st.spinner("Wait for it...", show_time=True): time.sleep(2) pdf_reader = PdfReader(uploaded_files) 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 = GLiNER.from_pretrained("urchade/gliner_base") labels = ["person", "country", "organization", "role", "skills"] entities = model.predict_entities(text_data, labels) df = pd.DataFrame(entities) st.subheader("Applicant's Profile", divider = "orange") fig = px.treemap(entities, path=[px.Constant("all"), 'text', 'label'], values='score', color='label') fig.update_layout(margin=dict(t=50, l=25, r=25, b=25)) st.plotly_chart(fig, key="figure 1") vectorizer = TfidfVectorizer(stop_words = 'english') 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("Similarity between Applicant's Profile and Job Description", divider = "orange") fig = px.imshow(cosine_sim_df, text_auto=True, labels=dict(x="Keyword similarity", y="Resumes", color="Productivity"), x=['Resume', 'Jon Description'], y=['Resume', 'Job Description']) st.plotly_chart(fig, key="figure 2") else: st.warning(f"Maximum upload attempts has been reached ({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).")