Spaces:
Configuration error
Configuration error
Pradyumn Tendulkar commited on
Commit ·
339cbdb
1
Parent(s): 11bdd1d
added multiple resume feature
Browse files
app.py
CHANGED
|
@@ -277,48 +277,47 @@ def extract_top_keywords(text: str, top_n: int = 15) -> str:
|
|
| 277 |
# --------------------------
|
| 278 |
# Main Gradio app logic
|
| 279 |
# --------------------------
|
| 280 |
-
def
|
| 281 |
-
if
|
| 282 |
-
return 0.0, "Please upload
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
return 0.0, f"### An Error Occurred\n`{e}`", "", "", "", "", "", "", ""
|
| 322 |
|
| 323 |
|
| 324 |
# --------------------------
|
|
@@ -339,8 +338,8 @@ def build_ui():
|
|
| 339 |
|
| 340 |
with gr.Row():
|
| 341 |
with gr.Column(scale=2):
|
| 342 |
-
file_in = gr.File(label="Upload
|
| 343 |
-
|
| 344 |
job_desc = gr.Textbox(lines=10, label="Job Description",
|
| 345 |
placeholder="Paste the full job description here...")
|
| 346 |
mode = gr.Radio(choices=["sbert", "bert"], value="sbert", label="Analysis Mode",
|
|
@@ -371,11 +370,10 @@ def build_ui():
|
|
| 371 |
jd_keywords_out = gr.Textbox(label="Top Job Description Keywords")
|
| 372 |
|
| 373 |
run_btn.click(
|
| 374 |
-
|
| 375 |
inputs=[file_in, job_desc, mode],
|
| 376 |
outputs=[score_slider, score_text, missing_out, suggestions_out, job_suggestions_out, projects_out,
|
| 377 |
-
|
| 378 |
-
jd_keywords_out],
|
| 379 |
show_progress='full'
|
| 380 |
)
|
| 381 |
|
|
|
|
| 277 |
# --------------------------
|
| 278 |
# Main Gradio app logic
|
| 279 |
# --------------------------
|
| 280 |
+
def analyze_resumes(files, job_description: str, mode: str):
|
| 281 |
+
if not files or not job_description.strip():
|
| 282 |
+
return 0.0, "Please upload resumes and paste a job description.", "", "", "", "", "", "", "", ""
|
| 283 |
+
|
| 284 |
+
results = []
|
| 285 |
+
for file in files:
|
| 286 |
+
try:
|
| 287 |
+
resume_text, fname = extract_text_from_fileobj(file)
|
| 288 |
+
if resume_text.strip().startswith("[Error"):
|
| 289 |
+
continue # Skip errored files
|
| 290 |
+
cleaned_resume = preprocess_text(resume_text)
|
| 291 |
+
cleaned_job = preprocess_text(job_description)
|
| 292 |
+
sim_pct = calculate_similarity(cleaned_resume, cleaned_job, mode=mode)
|
| 293 |
+
results.append((sim_pct, resume_text, fname))
|
| 294 |
+
except Exception:
|
| 295 |
+
continue # Skip if any error
|
| 296 |
+
|
| 297 |
+
if not results:
|
| 298 |
+
return 0.0, "No valid resumes were provided.", "", "", "", "", "", "", "", ""
|
| 299 |
+
|
| 300 |
+
# Select the best matching resume
|
| 301 |
+
best = max(results, key=lambda x: x[0]) # highest similarity
|
| 302 |
+
sim_pct, resume_text, fname = best
|
| 303 |
+
|
| 304 |
+
missing_dict, suggestions_text = analyze_resume_keywords(resume_text, job_description)
|
| 305 |
+
missing_formatted = format_missing_keywords(missing_dict)
|
| 306 |
+
job_suggestions = suggest_jobs(resume_text)
|
| 307 |
+
projects_section = extract_projects_section(resume_text)
|
| 308 |
+
project_fit_verdict = analyze_projects_fit(projects_section, job_description, mode)
|
| 309 |
+
resume_keywords_text = extract_top_keywords(preprocess_text(resume_text))
|
| 310 |
+
jd_keywords_text = extract_top_keywords(preprocess_text(job_description))
|
| 311 |
+
|
| 312 |
+
verdict = f"<h3 style='color:green;'>✅ Best Match: {fname} ({sim_pct:.2f}%)</h3>" if sim_pct >= 80 else \
|
| 313 |
+
f"<h3 style='color:limegreen;'>👍 Best Match: {fname} ({sim_pct:.2f}%)</h3>" if sim_pct >= 60 else \
|
| 314 |
+
f"<h3 style='color:orange;'>⚠️ Best Match: {fname} ({sim_pct:.2f}%)</h3>" if sim_pct >= 40 else \
|
| 315 |
+
f"<h3 style='color:red;'>❌ Low Match: {fname} ({sim_pct:.2f}%)</h3>"
|
| 316 |
+
|
| 317 |
+
return (
|
| 318 |
+
float(sim_pct), verdict, missing_formatted, suggestions_text,
|
| 319 |
+
job_suggestions, projects_section, project_fit_verdict, resume_keywords_text, jd_keywords_text, fname
|
| 320 |
+
)
|
|
|
|
| 321 |
|
| 322 |
|
| 323 |
# --------------------------
|
|
|
|
| 338 |
|
| 339 |
with gr.Row():
|
| 340 |
with gr.Column(scale=2):
|
| 341 |
+
file_in = gr.File(label="Upload resumes (PDF or DOCX)", file_count="multiple",
|
| 342 |
+
file_types=[".pdf", ".docx"])
|
| 343 |
job_desc = gr.Textbox(lines=10, label="Job Description",
|
| 344 |
placeholder="Paste the full job description here...")
|
| 345 |
mode = gr.Radio(choices=["sbert", "bert"], value="sbert", label="Analysis Mode",
|
|
|
|
| 370 |
jd_keywords_out = gr.Textbox(label="Top Job Description Keywords")
|
| 371 |
|
| 372 |
run_btn.click(
|
| 373 |
+
analyze_resumes,
|
| 374 |
inputs=[file_in, job_desc, mode],
|
| 375 |
outputs=[score_slider, score_text, missing_out, suggestions_out, job_suggestions_out, projects_out,
|
| 376 |
+
project_fit_out, resume_keywords_out, jd_keywords_out, gr.Textbox(label="Best Match Filename")],
|
|
|
|
| 377 |
show_progress='full'
|
| 378 |
)
|
| 379 |
|