Update app.py
Browse files
app.py
CHANGED
@@ -112,7 +112,75 @@ if 'upload_count' in st.session_state and st.session_state['upload_count'] > 0:
|
|
112 |
|
113 |
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
|
118 |
|
|
|
112 |
|
113 |
|
114 |
|
115 |
+
st.subheader ("Candidate Profile 1", divider = "green")
|
116 |
+
|
117 |
+
txt = st.text_area("Paste the job description and then press Ctrl + Enter", key = "text 1")
|
118 |
+
job = pd.Series(txt, name="Text")
|
119 |
+
|
120 |
+
|
121 |
+
if 'upload_count' not in st.session_state:
|
122 |
+
st.session_state['upload_count'] = 0
|
123 |
+
|
124 |
+
max_attempts = 3
|
125 |
+
|
126 |
+
if st.session_state['upload_count'] < max_attempts:
|
127 |
+
uploaded_files = st.file_uploader(
|
128 |
+
"Upload your resume", accept_multiple_files=True, type="pdf", key="candidate 1"
|
129 |
+
)
|
130 |
+
|
131 |
+
if uploaded_files:
|
132 |
+
st.session_state['upload_count'] += 1
|
133 |
+
for uploaded_file in uploaded_files:
|
134 |
+
pdf_reader = PdfReader(uploaded_file)
|
135 |
+
text_data = ""
|
136 |
+
for page in pdf_reader.pages:
|
137 |
+
text_data += page.extract_text()
|
138 |
+
data = pd.Series(text_data, name = 'Text')
|
139 |
+
|
140 |
+
|
141 |
+
frames = [job, data]
|
142 |
+
result = pd.concat(frames)
|
143 |
+
|
144 |
|
145 |
+
model = GLiNER.from_pretrained("urchade/gliner_base")
|
146 |
+
labels = ["person", "country","organization", "date", "time", "role", "skills", "year"]
|
147 |
+
entities = model.predict_entities(text_data, labels)
|
148 |
+
df = pd.DataFrame(entities)
|
149 |
+
|
150 |
+
|
151 |
+
st.subheader("Profile of candidate 1")
|
152 |
+
fig3 = px.treemap(entities, path=[px.Constant("all"), 'text', 'label'],
|
153 |
+
values='score', color='label')
|
154 |
+
fig3.update_layout(margin = dict(t=50, l=25, r=25, b=25))
|
155 |
+
st.plotly_chart(fig3, key = "figure 3")
|
156 |
+
|
157 |
+
|
158 |
+
|
159 |
+
vectorizer = TfidfVectorizer()
|
160 |
+
tfidf_matrix = vectorizer.fit_transform(result)
|
161 |
+
tfidf_df = pd.DataFrame(tfidf_matrix.toarray(), columns=vectorizer.get_feature_names_out())
|
162 |
+
|
163 |
+
cosine_sim_matrix = cosine_similarity(tfidf_matrix)
|
164 |
+
cosine_sim_df = pd.DataFrame(cosine_sim_matrix)
|
165 |
+
|
166 |
+
|
167 |
+
|
168 |
+
st.subheader("Measuring similarity between keywords of candidate profile 1 and job description")
|
169 |
+
fig4 = px.imshow(cosine_sim_df, text_auto=True, labels=dict(x="Keyword similarity", y="Resumes", color="Productivity"),
|
170 |
+
x=['Resume 1', 'Jon Description'],
|
171 |
+
y=['Resume 1', 'Job Description'])
|
172 |
+
st.plotly_chart(fig4, key = "figure 4")
|
173 |
+
|
174 |
+
|
175 |
+
for i, similarity_score in enumerate(cosine_sim_matrix[0][1:]):
|
176 |
+
st.write(f"Similarity of job description with candidate profile 1. {i + 1}: {similarity_score:.4f}")
|
177 |
+
st.write("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.")
|
178 |
+
|
179 |
+
else:
|
180 |
+
st.warning(f"You have reached the maximum URL attempts ({max_attempts}).")
|
181 |
+
|
182 |
+
if 'upload_count' in st.session_state and st.session_state['upload_count'] > 0:
|
183 |
+
st.info(f"Files uploaded {st.session_state['upload_count']} time(s).")
|
184 |
|
185 |
|
186 |
|