TheAllanB commited on
Commit
3db1942
·
verified ·
1 Parent(s): 01dcc4a
Files changed (1) hide show
  1. app.py +60 -44
app.py CHANGED
@@ -141,72 +141,88 @@ def create_resume_ranking_model(job_description, resume_directory):
141
  return ranked_resumes
142
 
143
 
 
 
 
 
 
 
 
144
  # Streamlit app
145
  st.title('Resume Ranking System')
146
 
147
  st.write("""
148
  This app ranks resumes based on their similarity to a given job description.
149
- Upload a directory containing resumes (PDF and DOCX formats) and enter a job description to get started.
150
  """)
151
 
152
  # Job description input
153
  job_description = st.text_area("Enter the job description:", height=200)
154
 
155
- # Resume directory input
156
- resume_directory = st.text_input("Enter the path to the resume directory:")
157
 
158
  if st.button('Rank Resumes'):
159
- if job_description and resume_directory:
160
  try:
161
- with st.spinner('Processing resumes...'):
162
- ranked_resumes = create_resume_ranking_model(job_description, resume_directory)
163
-
164
- st.success('Resumes ranked successfully!')
165
-
166
- # Display results
167
- st.write("Top 5 Ranked Resumes:")
168
- st.dataframe(ranked_resumes.head())
169
-
170
- # Create a folder with ranked resumes
171
- output_folder = "ranked_resumes"
172
- if os.path.exists(output_folder):
173
- shutil.rmtree(output_folder)
174
- os.makedirs(output_folder)
175
-
176
- for index, row in ranked_resumes.iterrows():
177
- src_file = os.path.join(resume_directory, row['filename'])
178
- dst_file = os.path.join(output_folder, f"{index+1:03d}_{row['filename']}")
179
- shutil.copy2(src_file, dst_file)
180
-
181
- # Create a zip file of the ranked resumes
182
- shutil.make_archive(output_folder, 'zip', output_folder)
183
-
184
- # Offer the zip file for download
185
- with open(f"{output_folder}.zip", "rb") as file:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  st.download_button(
187
- label="Download ranked resumes as ZIP",
188
- data=file,
189
- file_name="ranked_resumes.zip",
190
- mime="application/zip"
191
  )
192
-
193
- # Option to download full results as CSV
194
- csv = ranked_resumes.to_csv(index=False)
195
- st.download_button(
196
- label="Download full results as CSV",
197
- data=csv,
198
- file_name="ranked_resumes.csv",
199
- mime="text/csv",
200
- )
201
  except Exception as e:
202
  st.error(f"An error occurred: {str(e)}")
203
  else:
204
- st.warning("Please enter both a job description and a resume directory path.")
205
 
206
  st.write("""
207
  ### How to use this app:
208
  1. Enter the job description in the text area above.
209
- 2. Provide the full path to the directory containing the resumes.
210
  3. Click the 'Rank Resumes' button.
211
  4. View the top 5 ranked resumes in the table.
212
  5. Download the ranked resumes as a ZIP file.
 
141
  return ranked_resumes
142
 
143
 
144
+
145
+ #Streamlit App
146
+
147
+ import streamlit as st
148
+ import tempfile
149
+ import os
150
+
151
  # Streamlit app
152
  st.title('Resume Ranking System')
153
 
154
  st.write("""
155
  This app ranks resumes based on their similarity to a given job description.
156
+ Upload resume files (PDF and DOCX formats) and enter a job description to get started.
157
  """)
158
 
159
  # Job description input
160
  job_description = st.text_area("Enter the job description:", height=200)
161
 
162
+ # File uploader for resumes
163
+ uploaded_files = st.file_uploader("Upload resume files", accept_multiple_files=True, type=['pdf', 'docx'])
164
 
165
  if st.button('Rank Resumes'):
166
+ if job_description and uploaded_files:
167
  try:
168
+ # Create a temporary directory to store uploaded files
169
+ with tempfile.TemporaryDirectory() as temp_dir:
170
+ # Save uploaded files to the temporary directory
171
+ for uploaded_file in uploaded_files:
172
+ file_path = os.path.join(temp_dir, uploaded_file.name)
173
+ with open(file_path, "wb") as f:
174
+ f.write(uploaded_file.getbuffer())
175
+
176
+ # Process resumes
177
+ with st.spinner('Processing resumes...'):
178
+ ranked_resumes = create_resume_ranking_model(job_description, temp_dir)
179
+
180
+ st.success('Resumes ranked successfully!')
181
+
182
+ # Display results
183
+ st.write("Top 5 Ranked Resumes:")
184
+ st.dataframe(ranked_resumes.head())
185
+
186
+ # Create a folder with ranked resumes
187
+ output_folder = "ranked_resumes"
188
+ if os.path.exists(output_folder):
189
+ shutil.rmtree(output_folder)
190
+ os.makedirs(output_folder)
191
+
192
+ for index, row in ranked_resumes.iterrows():
193
+ src_file = os.path.join(temp_dir, row['filename'])
194
+ dst_file = os.path.join(output_folder, f"{index+1:03d}_{row['filename']}")
195
+ shutil.copy2(src_file, dst_file)
196
+
197
+ # Create a zip file of the ranked resumes
198
+ shutil.make_archive(output_folder, 'zip', output_folder)
199
+
200
+ # Offer the zip file for download
201
+ with open(f"{output_folder}.zip", "rb") as file:
202
+ st.download_button(
203
+ label="Download ranked resumes as ZIP",
204
+ data=file,
205
+ file_name="ranked_resumes.zip",
206
+ mime="application/zip"
207
+ )
208
+
209
+ # Option to download full results as CSV
210
+ csv = ranked_resumes.to_csv(index=False)
211
  st.download_button(
212
+ label="Download full results as CSV",
213
+ data=csv,
214
+ file_name="ranked_resumes.csv",
215
+ mime="text/csv",
216
  )
 
 
 
 
 
 
 
 
 
217
  except Exception as e:
218
  st.error(f"An error occurred: {str(e)}")
219
  else:
220
+ st.warning("Please enter a job description and upload at least one resume file.")
221
 
222
  st.write("""
223
  ### How to use this app:
224
  1. Enter the job description in the text area above.
225
+ 2. Upload resume files (PDF and DOCX formats) using the file uploader.
226
  3. Click the 'Rank Resumes' button.
227
  4. View the top 5 ranked resumes in the table.
228
  5. Download the ranked resumes as a ZIP file.