nlpblogs commited on
Commit
179aead
·
verified ·
1 Parent(s): 658a20b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -4
app.py CHANGED
@@ -51,8 +51,8 @@ if 'applicant_data' not in st.session_state:
51
 
52
  max_attempts = 20
53
 
54
- for i in range(1, 11): # Looping for 2 applicants
55
- st.subheader(f"Applicant Resume {i}", divider="green")
56
  applicant_key = f"applicant_{i}"
57
  upload_key = f"candidate_{i}"
58
 
@@ -83,9 +83,9 @@ for i in range(1, 11): # Looping for 2 applicants
83
  tfidf_matrix = vectorizer.fit_transform(result)
84
  cosine_sim_matrix = cosine_similarity(tfidf_matrix)
85
 
86
- st.subheader(f"Similarity Analysis for Applicant {i}")
87
  for j, similarity_score in enumerate(cosine_sim_matrix[0][1:]):
88
- with st.popover("See result"):
89
  st.write(f"Similarity between Applicant's resume and job description based on keywords: {similarity_score:.2f}")
90
  st.info(
91
  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.")
@@ -100,6 +100,63 @@ for i in range(1, 11): # Looping for 2 applicants
100
 
101
 
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
 
105
 
 
51
 
52
  max_attempts = 20
53
 
54
+ for i in range(1, 51): # Looping for 2 applicants
55
+ st.subheader(f"Applicant {i} Resume", divider="green")
56
  applicant_key = f"applicant_{i}"
57
  upload_key = f"candidate_{i}"
58
 
 
83
  tfidf_matrix = vectorizer.fit_transform(result)
84
  cosine_sim_matrix = cosine_similarity(tfidf_matrix)
85
 
86
+
87
  for j, similarity_score in enumerate(cosine_sim_matrix[0][1:]):
88
+ with st.popover(f"See Result for Applicant {i}"):
89
  st.write(f"Similarity between Applicant's resume and job description based on keywords: {similarity_score:.2f}")
90
  st.info(
91
  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.")
 
100
 
101
 
102
 
103
+ st.divider()
104
+
105
+ st.subheader("Visualise", divider="blue")
106
+ if 'upload_count' not in st.session_state:
107
+ st.session_state['upload_count'] = 0
108
+
109
+ max_attempts = 3
110
+ if st.session_state['upload_count'] < max_attempts:
111
+ uploaded_files = st.file_uploader("Upload Applicant's resume", type="pdf")
112
+ if uploaded_files:
113
+ st.session_state['upload_count'] += 1
114
+
115
+ pdf_reader = PdfReader(uploaded_files)
116
+ text_data = ""
117
+ for page in pdf_reader.pages:
118
+ text_data += page.extract_text()
119
+
120
+ data = pd.Series(text_data, name='Text')
121
+ frames = [job, data]
122
+ result = pd.concat(frames)
123
+ model = GLiNER.from_pretrained("urchade/gliner_base")
124
+ labels = ["person", "country", "organization", "role", "skills"]
125
+ entities = model.predict_entities(text_data, labels)
126
+ df = pd.DataFrame(entities)
127
+
128
+ tab1, tab2, tab3 = st.tabs(["Applicant's Profile", "Similarity"])
129
+ with tab1:
130
+ fig = px.treemap(entities, path=[px.Constant("all"), 'text', 'label'],
131
+ values='score', color='label')
132
+ fig.update_layout(margin=dict(t=50, l=25, r=25, b=25))
133
+ st.plotly_chart(fig, key="figure 1")
134
+
135
+ vectorizer = TfidfVectorizer()
136
+ tfidf_matrix = vectorizer.fit_transform(result)
137
+ tfidf_df = pd.DataFrame(tfidf_matrix.toarray(), columns=vectorizer.get_feature_names_out())
138
+ cosine_sim_matrix = cosine_similarity(tfidf_matrix)
139
+ cosine_sim_df = pd.DataFrame(cosine_sim_matrix)
140
+
141
+ with tab2:
142
+ fig = px.imshow(cosine_sim_df, text_auto=True,
143
+ labels=dict(x="Keyword similarity", y="Resumes", color="Productivity"),
144
+ x=['Resume', 'Jon Description'],
145
+ y=['Resume', 'Job Description'])
146
+ st.plotly_chart(fig, key="figure 2")
147
+
148
+
149
+
150
+
151
+ for i, similarity_score in enumerate(cosine_sim_matrix[0][1:]):
152
+ with st.popover("See result"):
153
+ st.write(f"Similarity of job description with Applicant's 1 resume based on keywords: {similarity_score:.2f}")
154
+ st.info(
155
+ "A score closer to 1 (0.80, 0.90) means higher similarity between Applicant's 1 resume and job description. A score closer to 0 (0.20, 0.30) means lower similarity between Applicant's 1 resume and job description.")
156
+ else:
157
+ st.warning(f"You have reached the maximum upload attempts ({max_attempts}).")
158
+ if 'upload_count' in st.session_state and st.session_state['upload_count'] > 0:
159
+ st.info(f"Files uploaded {st.session_state['upload_count']} time(s).")
160
 
161
 
162