earlsab commited on
Commit
81c559a
·
1 Parent(s): 4c4ac7c

add sort + fix spelling

Browse files
Files changed (1) hide show
  1. app.py +77 -4
app.py CHANGED
@@ -7,6 +7,16 @@ from typing import List, Dict, Any
7
  from dotenv import load_dotenv
8
  import concurrent.futures
9
 
 
 
 
 
 
 
 
 
 
 
10
  # Load environment variables
11
  load_dotenv(".env.local")
12
 
@@ -329,6 +339,8 @@ def create_html_output(job_result: Dict, resume_results: List[Dict]) -> str:
329
  html += "<th style='padding: 8px; text-align: center; border: 1px solid #ddd;'>Category</th>"
330
  html += "<th style='padding: 8px; text-align: center; border: 1px solid #ddd;'>Actions</th></tr>"
331
 
 
 
332
  for i, resume_result in enumerate(resume_results, 1):
333
  # Calculate skill match
334
  resume_skills = [skill['text'].lower() for skill in resume_result['skills']]
@@ -350,10 +362,71 @@ def create_html_output(job_result: Dict, resume_results: List[Dict]) -> str:
350
  category = "Advanced"
351
 
352
  # Add quality modifier if 50% above average
353
- if leadership_count > avg_leadership * 1.5:
 
 
 
 
354
  category = f"Quality {category} (Leadership)"
355
- elif collaboration_count > avg_collaboration * 1.5:
 
356
  category = f"Quality {category} (Collaboration)"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
357
 
358
  # Add row to summary table
359
  html += f"<tr><td style='padding: 8px; border: 1px solid #ddd;'>Resume {i}</td>"
@@ -537,7 +610,7 @@ def process_inputs(job_description: str, input_type: str, resume_text: str, resu
537
  return html_output
538
 
539
  # Create Gradio interface
540
- with gr.Blocks(title="Beyond Keywords: Resume Analysis System") as demo:
541
  gr.Markdown("# Beyond Keywords: Job Description and Resume Analyzer")
542
  gr.Markdown("Upload a job description and resume(s) to analyze skill matches and quality.")
543
 
@@ -558,7 +631,7 @@ with gr.Blocks(title="Beyond Keywords: Resume Analysis System") as demo:
558
  resume_input = gr.Group()
559
  with resume_input:
560
  input_type = gr.Radio(
561
- choices=["Paste Text", "Upload File"],
562
  label="Input Method",
563
  value="Paste Text"
564
  )
 
7
  from dotenv import load_dotenv
8
  import concurrent.futures
9
 
10
+ js_func = """
11
+ function refresh() {
12
+ const url = new URL(window.location);
13
+
14
+ if (url.searchParams.get('__theme') !== 'light') {
15
+ url.searchParams.set('__theme', 'light');
16
+ window.location.href = url.href;
17
+ }
18
+ }
19
+ """
20
  # Load environment variables
21
  load_dotenv(".env.local")
22
 
 
339
  html += "<th style='padding: 8px; text-align: center; border: 1px solid #ddd;'>Category</th>"
340
  html += "<th style='padding: 8px; text-align: center; border: 1px solid #ddd;'>Actions</th></tr>"
341
 
342
+ # Create a list of resume data for sorting
343
+ resume_data = []
344
  for i, resume_result in enumerate(resume_results, 1):
345
  # Calculate skill match
346
  resume_skills = [skill['text'].lower() for skill in resume_result['skills']]
 
362
  category = "Advanced"
363
 
364
  # Add quality modifier if 50% above average
365
+ is_quality_leadership = leadership_count > avg_leadership * 1.5
366
+ is_quality_collaboration = collaboration_count > avg_collaboration * 1.5
367
+
368
+ quality_score = 0
369
+ if is_quality_leadership:
370
  category = f"Quality {category} (Leadership)"
371
+ quality_score = 2
372
+ elif is_quality_collaboration:
373
  category = f"Quality {category} (Collaboration)"
374
+ quality_score = 1
375
+
376
+ # Add to resume data list for sorting
377
+ resume_data.append({
378
+ 'index': i,
379
+ 'match_count': match_count,
380
+ 'match_percentage': match_percentage,
381
+ 'leadership_count': leadership_count,
382
+ 'collaboration_count': collaboration_count,
383
+ 'total_experience': total_experience,
384
+ 'category': category,
385
+ 'quality_score': quality_score,
386
+ 'resume_result': resume_result
387
+ })
388
+
389
+ # Sort resume data:
390
+ # 1. By matched skills (highest first)
391
+ # 2. By years of experience (highest first)
392
+ # 3. By quality category for resumes with experience within 1 year
393
+ def sort_key(resume):
394
+ return (-resume['match_count'], -resume['total_experience'], -resume['quality_score'])
395
+
396
+ sorted_resumes = sorted(resume_data, key=sort_key)
397
+
398
+ # Group resumes with experience within 1 year and sort by quality
399
+ final_sorted = []
400
+ i = 0
401
+ while i < len(sorted_resumes):
402
+ current = sorted_resumes[i]
403
+ similar_exp = [current]
404
+ j = i + 1
405
+
406
+ # Find all resumes with similar experience to the current one
407
+ while j < len(sorted_resumes) and sorted_resumes[j]['match_count'] == current['match_count']:
408
+ if abs(sorted_resumes[j]['total_experience'] - current['total_experience']) <= 1:
409
+ similar_exp.append(sorted_resumes[j])
410
+ sorted_resumes.pop(j)
411
+ else:
412
+ j += 1
413
+
414
+ # Sort by quality score if there are resumes with similar experience
415
+ if len(similar_exp) > 1:
416
+ similar_exp.sort(key=lambda x: -x['quality_score'])
417
+
418
+ final_sorted.extend(similar_exp)
419
+ i = j if len(similar_exp) == 1 else i + 1
420
+
421
+ # Add sorted rows to summary table
422
+ for resume_data in final_sorted:
423
+ i = resume_data['index']
424
+ match_count = resume_data['match_count']
425
+ match_percentage = resume_data['match_percentage']
426
+ leadership_count = resume_data['leadership_count']
427
+ collaboration_count = resume_data['collaboration_count']
428
+ total_experience = resume_data['total_experience']
429
+ category = resume_data['category']
430
 
431
  # Add row to summary table
432
  html += f"<tr><td style='padding: 8px; border: 1px solid #ddd;'>Resume {i}</td>"
 
610
  return html_output
611
 
612
  # Create Gradio interface
613
+ with gr.Blocks(title="Beyond Keywords: Resume Analysis System", js=js_func) as demo:
614
  gr.Markdown("# Beyond Keywords: Job Description and Resume Analyzer")
615
  gr.Markdown("Upload a job description and resume(s) to analyze skill matches and quality.")
616
 
 
631
  resume_input = gr.Group()
632
  with resume_input:
633
  input_type = gr.Radio(
634
+ choices=["Paste Text", "Upload File(s)"],
635
  label="Input Method",
636
  value="Paste Text"
637
  )