nlpblogs commited on
Commit
9f7e85b
·
verified ·
1 Parent(s): bdb2967

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -73
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  import streamlit as st
3
  from PyPDF2 import PdfReader
4
  import pandas as pd
@@ -50,12 +49,12 @@ job = pd.Series(txt, name="Text")
50
  st.subheader("Candidate Profile 1", divider = "red")
51
 
52
 
53
- if 'upload_count_cand1' not in st.session_state:
54
- st.session_state['upload_count_cand1'] = 0
55
 
56
- max_attempts_cand1 = 1
57
 
58
- if st.session_state['upload_count_cand1'] < max_attempts_cand1:
59
  uploaded_files = st.file_uploader(
60
  "Upload your resume", accept_multiple_files=True, type="pdf", key="candidate 1"
61
  )
@@ -84,7 +83,7 @@ for uploaded_file in uploaded_files:
84
  fig = px.treemap(entities, path=[px.Constant("all"), 'text', 'label'],
85
  values='score', color='label')
86
  fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
87
- st.plotly_chart(fig, key = "tv")
88
 
89
 
90
 
@@ -102,7 +101,7 @@ for uploaded_file in uploaded_files:
102
  fig = px.imshow(cosine_sim_df, text_auto=True, labels=dict(x="Keyword similarity", y="Resumes", color="Productivity"),
103
  x=['Resume 1', 'Jon Description'],
104
  y=['Resume 1', 'Job Description'])
105
- st.plotly_chart(fig, key = "bar")
106
 
107
 
108
 
@@ -111,81 +110,17 @@ for uploaded_file in uploaded_files:
111
  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.")
112
 
113
  else:
114
- st.warning(f"You have reached the maximum URL attempts ({max_attempts_cand1}).")
115
  if 'upload_count' in st.session_state and st.session_state['upload_count'] > 0:
116
- st.info(f"Files uploaded {st.session_state['upload_count_cand1']} time(s).")
117
-
118
-
119
-
120
 
121
 
122
- st.subheader ("Candidate Profile 2", divider = "green")
123
 
124
 
125
 
126
- if 'upload_count_cand2' not in st.session_state:
127
- st.session_state['upload_count_cand2'] = 0
128
-
129
- max_attempts_cand2 = 3
130
-
131
- if st.session_state['upload_count_cand2'] < max_attempts_cand2:
132
- uploaded_files = st.file_uploader(
133
- "Upload your resume in .pdf format", accept_multiple_files=True, type="pdf", key="candidate 2"
134
- )
135
-
136
- if uploaded_files:
137
- st.session_state['upload_count'] += 1
138
- for uploaded_file in uploaded_files:
139
- pdf_reader = PdfReader(uploaded_file)
140
- text_data = ""
141
- for page in pdf_reader.pages:
142
- text_data += page.extract_text()
143
- data = pd.Series(text_data, name = 'Text')
144
-
145
-
146
- frames = [job, data]
147
- result = pd.concat(frames)
148
-
149
 
150
- model = GLiNER.from_pretrained("urchade/gliner_base")
151
- labels = ["person", "country","organization", "date", "time", "role", "skills", "year"]
152
- entities = model.predict_entities(text_data, labels)
153
- df = pd.DataFrame(entities)
154
 
155
 
156
-
157
- fig = px.treemap(entities, path=[px.Constant("all"), 'text', 'label'],
158
- values='score', color='label')
159
- fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
160
- st.plotly_chart(fig, key = "iris")
161
-
162
-
163
-
164
-
165
- vectorizer = TfidfVectorizer()
166
- tfidf_matrix = vectorizer.fit_transform(result)
167
- tfidf_df = pd.DataFrame(tfidf_matrix.toarray(), columns=vectorizer.get_feature_names_out())
168
-
169
- cosine_sim_matrix = cosine_similarity(tfidf_matrix)
170
- cosine_sim_df = pd.DataFrame(cosine_sim_matrix)
171
-
172
-
173
-
174
-
175
- fig = px.imshow(cosine_sim_df, text_auto=True, labels=dict(x="Keyword similarity", y="Resumes", color="Productivity"),
176
- x=['Resume 2', 'Jon Description'],
177
- y=['Resume 2', 'Job Description'])
178
- st.plotly_chart(fig, key = "radio")
179
-
180
-
181
-
182
- for i, similarity_score in enumerate(cosine_sim_matrix[0][1:]):
183
- st.write(f"Similarity with Candidate Profile. A score closer to 1 means higher similarity. {i + 1}: {similarity_score:.4f}")
184
-
185
- else:
186
- st.warning(f"You have reached the maximum URL attempts ({max_attempts_cand2}).")
187
- if 'upload_count' in st.session_state and st.session_state['upload_count'] > 0:
188
- st.info(f"Files uploaded {st.session_state['upload_count_cand2']} time(s).")
189
 
190
  # fix else: warning
191
  # fix, keys
 
 
1
  import streamlit as st
2
  from PyPDF2 import PdfReader
3
  import pandas as pd
 
49
  st.subheader("Candidate Profile 1", divider = "red")
50
 
51
 
52
+ if 'upload_count' not in st.session_state:
53
+ st.session_state['upload_count'] = 0
54
 
55
+ max_attempts = 3
56
 
57
+ if st.session_state['upload_count'] < max_attempts:
58
  uploaded_files = st.file_uploader(
59
  "Upload your resume", accept_multiple_files=True, type="pdf", key="candidate 1"
60
  )
 
83
  fig = px.treemap(entities, path=[px.Constant("all"), 'text', 'label'],
84
  values='score', color='label')
85
  fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
86
+ st.plotly_chart(fig, key = "figure 1")
87
 
88
 
89
 
 
101
  fig = px.imshow(cosine_sim_df, text_auto=True, labels=dict(x="Keyword similarity", y="Resumes", color="Productivity"),
102
  x=['Resume 1', 'Jon Description'],
103
  y=['Resume 1', 'Job Description'])
104
+ st.plotly_chart(fig, key = "figure 2")
105
 
106
 
107
 
 
110
  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.")
111
 
112
  else:
113
+ st.warning(f"You have reached the maximum URL attempts ({max_attempts}).")
114
  if 'upload_count' in st.session_state and st.session_state['upload_count'] > 0:
115
+ st.info(f"Files uploaded {st.session_state['upload_count']} time(s).")
 
 
 
116
 
117
 
 
118
 
119
 
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
 
 
 
 
122
 
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
 
125
  # fix else: warning
126
  # fix, keys