Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PyPDF2 import PdfReader
|
3 |
+
import pandas as pd
|
4 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
5 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
6 |
+
from gliner import GLiNER
|
7 |
+
import plotly.express as px
|
8 |
+
import time
|
9 |
+
from sentence_transformers import SentenceTransformer
|
10 |
+
|
11 |
+
model = SentenceTransformer("all-mpnet-base-v2")
|
12 |
+
|
13 |
+
|
14 |
+
st.title("AI Resume Analysis based on Keywords App")
|
15 |
+
st.divider()
|
16 |
+
|
17 |
+
job = pd.Series(st.text_area("Paste the job description and then press Ctrl + Enter", key="job_desc"), name="Text")
|
18 |
+
|
19 |
+
if 'applicant_data' not in st.session_state:
|
20 |
+
st.session_state['applicant_data'] = {}
|
21 |
+
|
22 |
+
max_attempts = 1
|
23 |
+
|
24 |
+
for i in range(1, 51): # Looping for 2 applicants
|
25 |
+
st.subheader(f"Applicant {i} Resume", divider="green")
|
26 |
+
applicant_key = f"applicant_{i}"
|
27 |
+
upload_key = f"candidate_{i}"
|
28 |
+
|
29 |
+
if applicant_key not in st.session_state['applicant_data']:
|
30 |
+
st.session_state['applicant_data'][applicant_key] = {'upload_count': 0, 'uploaded_file': None, 'analysis_done': False}
|
31 |
+
|
32 |
+
if st.session_state['applicant_data'][applicant_key]['upload_count'] < max_attempts:
|
33 |
+
uploaded_file = st.file_uploader(f"Upload Applicant's {i} resume", type="pdf", key=upload_key)
|
34 |
+
|
35 |
+
if uploaded_file:
|
36 |
+
st.session_state['applicant_data'][applicant_key]['uploaded_file'] = uploaded_file
|
37 |
+
st.session_state['applicant_data'][applicant_key]['upload_count'] += 1
|
38 |
+
st.session_state['applicant_data'][applicant_key]['analysis_done'] = False # Reset analysis flag
|
39 |
+
|
40 |
+
if st.session_state['applicant_data'][applicant_key]['uploaded_file'] and not st.session_state['applicant_data'][applicant_key]['analysis_done']:
|
41 |
+
pdf_reader = PdfReader(st.session_state['applicant_data'][applicant_key]['uploaded_file'])
|
42 |
+
text_data = ""
|
43 |
+
for page in pdf_reader.pages:
|
44 |
+
text_data += page.extract_text()
|
45 |
+
|
46 |
+
with st.expander(f"See Applicant's {i} resume"):
|
47 |
+
st.write(text_data)
|
48 |
+
|
49 |
+
data = pd.Series(text_data, name='Text')
|
50 |
+
result = pd.concat([job, data])
|
51 |
+
|
52 |
+
|
53 |
+
embeddings = model.encode([result])
|
54 |
+
similarities = model.similarity(embeddings, embeddings)
|
55 |
+
|
56 |
+
|
57 |
+
|
58 |
+
for j, similarity_score in enumerate(similarities[0][1:]):
|
59 |
+
with st.popover(f"See Result for Applicant {i}"):
|
60 |
+
st.write(f"Similarity between Applicant's resume and job description based on keywords: {similarity_score:.2f}")
|
61 |
+
st.info(
|
62 |
+
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.")
|
63 |
+
st.session_state['applicant_data'][applicant_key]['analysis_done'] = True
|
64 |
+
|
65 |
+
else:
|
66 |
+
st.warning(f"Maximum upload attempts has been reached ({max_attempts}).")
|
67 |
+
if st.session_state['applicant_data'][applicant_key]['upload_count'] > 0:
|
68 |
+
st.info(f"Files uploaded for Applicant {i}: {st.session_state['applicant_data'][applicant_key]['upload_count']} time(s).")
|
69 |
+
|
70 |
+
|
71 |
+
|