-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
277 lines (237 loc) · 11.6 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
import streamlit as st
import pandas as pd
import authentication
import utils
import zipfile
import os
os.makedirs("job_descriptions", exist_ok=True)
os.makedirs("resumes_uploaded", exist_ok=True)
def login():
st.title("Login")
with st.form("Form1"):
username = st.text_input("Username", placeholder="Enter Your Sacha Username")
password = st.text_input("Password", type="password", placeholder="Enter Your Password")
if st.form_submit_button("Login"):
if authentication.authenticate(username, password):
session_id = authentication.create_session(username)
st.session_state['session_id'] = session_id
st.session_state['username'] = username
st.session_state['page'] = "home"
else:
st.error("Invalid username or password.")
def logout():
session_id = st.session_state.get("session_id", None)
if session_id:
authentication.logout(session_id)
st.session_state['page'] = "login"
st.session_state.clear()
st.success("You are successfully logged out.")
def show_logs():
session_id = st.session_state.get("session_id", None)
if session_id is None:
st.error("Unauthorized access. Please login.")
st.session_state['page'] = 'login'
st.stop()
st.subheader("Activity Logs")
st.sidebar.markdown(f"""
<div style='
border: 2px solid yellow;
padding: 10px;
border-radius: 5px;
user-select:none;
margin-bottom: 10px;
text-align: center;
font-weight: bold;
color: black;
background-color: #f0f0f0;
'>
👤 Hello, {st.session_state['username']}
</div>
""", unsafe_allow_html=True)
logs_df = pd.read_csv("updated_logs.csv")
st.write(logs_df)
def home():
session_id = st.session_state.get("session_id", None)
if session_id is None:
st.error("Unauthorized access. Please login.")
st.session_state['page'] = 'login'
st.stop()
if session_id not in authentication.active_sessions:
st.error("Session expired or invalid. Please login again.")
st.session_state['page'] = 'login'
st.stop()
st.sidebar.markdown(f"""
<div style='
border: 2px solid yellow;
padding: 10px;
border-radius: 5px;
user-select:none;
margin-bottom: 10px;
text-align: center;
font-weight: bold;
color: black;
background-color: #f0f0f0;
'>
👤 Hello, {st.session_state['username']}
</div>
""", unsafe_allow_html=True)
col3, col4 = st.columns(2)
with col3:
option_job = st.radio("Select Job Description:", ('Upload File','Select Previous'))
with col4:
option = st.radio("Upload resumes as:", ('Individual Files', 'Zip File'))
col1, col2 = st.columns(2)
job_description_file = None
job_description_key = None
job_description = None
job_description_filename = None
job_descriptions_df = pd.read_csv("job_descriptions.csv")
keys = job_descriptions_df['Key'].unique()
with col1:
if option_job == 'Upload File':
job_description_file = st.file_uploader("Upload Job Description", type=['pdf', 'txt', 'docx'])
job_description_key = st.text_input("Enter a key for the job description")
else:
job_key = st.selectbox("Select a key:", keys)
if job_key:
job_description_key = job_key
job_description_filename = job_descriptions_df.loc[job_descriptions_df['Key'] == job_key, 'Filename'].iloc[0]
file_extension = job_description_filename.split('.')[-1].lower()
if file_extension == 'txt':
with open(job_description_filename, "r", encoding="utf-8", errors="ignore") as f:
job_description = f.read()
elif file_extension == 'pdf':
with open(job_description_filename, "rb") as f:
job_description = utils.read_pdf_text(f)
elif file_extension == 'docx':
job_description = utils.read_docx_text(job_description_filename)
with col2:
if option == 'Individual Files':
uploaded_files = st.file_uploader("Upload Resumes", type=['pdf', 'txt', 'docx'], accept_multiple_files=True)
else:
uploaded_zip = st.file_uploader("Upload Resumes Zip", type=['zip'])
if job_description_file and job_description_key:
job_desc_filename = f"job_descriptions/{job_description_key}_{job_description_file.name}"
with open(job_desc_filename, "wb") as f:
f.write(job_description_file.getvalue())
if job_description_file.type == "text/plain":
job_description = job_description_file.getvalue().decode("utf-8")
elif job_description_file.type == "application/pdf":
job_description = utils.read_pdf_text(job_description_file)
elif job_description_file.type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
job_description = utils.read_docx_text(job_description_file)
if not os.path.isfile("job_descriptions.csv"):
job_descriptions_df = pd.DataFrame(columns=["Key", "Filename"])
else:
job_descriptions_df = pd.read_csv("job_descriptions.csv")
new_entry = pd.DataFrame([[job_description_key, job_desc_filename]], columns=["Key", "Filename"])
job_descriptions_df = pd.concat([job_descriptions_df, new_entry], ignore_index=True)
job_descriptions_df.to_csv("job_descriptions.csv", index=False)
resumes = {}
if option == 'Individual Files' and uploaded_files:
for uploaded_file in uploaded_files:
resume_filename = f"resumes_uploaded/{uploaded_file.name}"
with open(resume_filename, "wb") as f:
f.write(uploaded_file.getvalue())
resume_text = ""
if uploaded_file.type == "text/plain":
resume_text = uploaded_file.getvalue().decode("utf-8")
elif uploaded_file.type == "application/pdf":
resume_text = utils.read_pdf_text(uploaded_file)
elif uploaded_file.type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
resume_text = utils.read_docx_text(uploaded_file)
resumes[resume_filename] = resume_text
elif option == 'Zip File' and uploaded_zip:
with zipfile.ZipFile(uploaded_zip, 'r') as zip_ref:
zip_ref.extractall("resumes_uploaded")
for root, dirs, files in os.walk("resumes_uploaded"):
for file_name in files:
file_path = os.path.join(root, file_name)
resume_text = ""
if file_name.endswith(".txt"):
with open(file_path, "r", encoding="utf-8") as file:
resume_text = file.read()
elif file_name.endswith(".pdf"):
with open(file_path, "rb") as file:
resume_text = utils.read_pdf_text(file)
elif file_name.endswith(".docx"):
resume_text = utils.read_docx_text(file_path)
resumes[file_path] = resume_text
if job_description and resumes:
threshold_percentage = st.number_input("Minimum Matching Percentage to Consider", min_value=0, max_value=100, value=50)
if st.button("Match", key="match_button"):
with st.spinner('Matching Resumes...'):
nlp_percentages = utils.custom_matching_percentage(job_description, list(resumes.values()))
feedback = utils.generate_feedback(job_description, resumes)
results_consider = []
results_ignore = []
for name, nlp_percentage in zip(resumes.keys(), nlp_percentages):
consideration = "Consider" if nlp_percentage >= threshold_percentage else "Ignore"
if consideration == "Consider":
results_consider.append({
"Resume Name": name,
"Matching Percentage": nlp_percentage,
"Consideration": consideration,
"Feedback": feedback[name]
})
else:
results_ignore.append({
"Resume Name": name,
"Matching Percentage": nlp_percentage,
"Consideration": consideration,
"Feedback": feedback[name]
})
df_consider = pd.DataFrame(results_consider)
df_ignore = pd.DataFrame(results_ignore)
def highlight_row(row):
color = 'color: red' if row.Consideration == 'Ignore' else 'color: yellow'
return [color] * len(row)
styled_df_consider = df_consider.style.apply(highlight_row, axis=1)
styled_df_ignore = df_ignore.style.apply(highlight_row, axis=1)
st.subheader("Consider")
st.write(styled_df_consider)
csv_consider = df_consider.to_csv(index=False)
st.download_button(label="Download Consider Table", data=csv_consider, file_name="consider.csv", mime="text/csv", key="consider_button")
st.subheader("Ignore")
st.write(styled_df_ignore)
csv_ignore = df_ignore.to_csv(index=False)
st.download_button(label="Download Ignore Table", data=csv_ignore, file_name="ignore.csv", mime="text/csv", key="ignore_button")
def settings():
st.header("Settings")
with st.form(key='settings_form'):
name = st.text_input("Name")
email = st.text_input("Email")
password = st.text_input("Password", type='password')
role = st.selectbox("Role", ["Select Role","HR", "Admin"])
submit_button = st.form_submit_button(label='Submit')
if submit_button:
# Handle the form submission
st.success(f"Settings updated for {name}. Role: {role}")
def main():
st.set_page_config(page_title="Analyzer", page_icon=":mag:", layout="wide")
st.markdown("<h1 style='color: yellow; text-align: center; border: 2px solid yellow; padding: 10px; user-select:none;'>+++ SACHA </h1>", unsafe_allow_html=True)
st.markdown("<h3 style='text-align: center; user-select:none'>🔍 || RESUME ANALYZER ||</h3>", unsafe_allow_html=True)
# Initialize page if not present in session state
if 'page' not in st.session_state:
st.session_state['page'] = 'login'
# Display corresponding page based on selected option
if st.session_state['page'] == "login":
login()
elif st.session_state['page'] == "home":
home()
elif st.session_state['page'] == "logs":
show_logs()
elif st.session_state['page'] == "settings":
settings()
# Sidebar navigation
selected_option = st.sidebar.selectbox("Menu", ["Select Option", "Home", "Logs", "Logout","Settings"])
if selected_option == "Home":
st.session_state['page'] = 'home'
elif selected_option == "Logs":
st.session_state['page'] = 'logs'
elif selected_option == "Logout":
logout()
elif selected_option == "Settings":
st.session_state['page'] = 'settings'
if __name__ == "__main__":
main()