CR7CAD commited on
Commit
d746933
·
verified ·
1 Parent(s): 99470dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -50
app.py CHANGED
@@ -410,80 +410,90 @@ def analyze_google_fit(resume_summary):
410
 
411
  # Create a more specific prompt for T5 that focuses on detailed assessment
412
  prompt = f"""
413
- Generate a professional expert assessment for a Google job candidate.
414
- Skills detected: {skills_text}.
415
- Strongest area: {top_category} ({categories_sorted[0][1]["adjusted_score"]}%).
416
- Weakest area: {weak_category} ({categories_sorted[-1][1]["adjusted_score"]}%).
417
- Overall match: {match_percentage}%.
418
 
419
- Write an evaluative assessment that analyzes the candidate's fit for Google.
420
- Start with "This candidate" and:
421
- - Evaluate their technical skills in relation to Google's standards
422
- - Assess their strengths and potential contributions
423
- - Provide specific areas where improvement is needed
424
- - Give an overall evaluation of their Google fit
425
 
426
- Your assessment should be an expert evaluation, not a summary of their resume.
427
- Include specific actionable advice for improvement.
428
 
429
- This candidate
430
- """
431
-
432
  try:
433
  # Generate the assessment using T5
434
  assessment_results = models['evaluator'](
435
  prompt,
436
  max_length=300,
437
  do_sample=True,
438
- temperature=0.75, # Slightly higher temperature for more evaluative content
439
  num_return_sequences=3
440
  )
441
 
442
- # Find the best response
443
  best_assessment = None
444
  for result in assessment_results:
445
- text = result['generated_text'].strip()
446
-
447
- # Clean up and check if valid
448
- text = re.sub(r'Generate a professional expert assessment.*?Overall match:.*?%\.', '', text, flags=re.DOTALL)
449
- text = re.sub(r'Write an evaluative assessment.*?This candidate', 'This candidate', text, flags=re.DOTALL)
450
 
451
- # Check if it's a good response - looking for evaluative language
452
- if (text.lower().startswith("this candidate") and
453
- len(text) > 100 and
454
- ("would" in text.lower() or "could" in text.lower() or "should" in text.lower() or
455
- "needs" in text.lower() or "requires" in text.lower() or "lacks" in text.lower())):
456
- best_assessment = text
457
- break
 
 
 
 
 
 
 
 
 
 
458
 
459
- # Use the best response or the first one if none were ideal
460
  if best_assessment:
461
  assessment = best_assessment
462
  else:
463
- # Use first response but clean it up
464
- text = assessment_results[0]['generated_text']
465
- text = re.sub(r'Generate a professional expert assessment.*?Overall match:.*?%\.', '', text, flags=re.DOTALL)
466
- text = re.sub(r'Write an evaluative assessment.*?This candidate', 'This candidate', text, flags=re.DOTALL)
467
-
468
- # Remove numbering or bullets if present
469
- text = re.sub(r'[-•]\s', '', text)
470
- text = re.sub(r'\d\.\s', '', text)
471
-
472
- if not text.lower().startswith("this candidate"):
473
- text = "This candidate " + text
474
-
475
- assessment = text
476
 
477
  except Exception as e:
478
- # Fall back to manual assessment - making this more evaluative
479
  print(f"Error in T5 assessment generation: {e}")
480
- assessment = f"""This candidate shows promise in {top_category} but would need significant development in {weak_category} to meet Google's standards. Their technical skills in {skills_text} align with Google's engineering needs, but they would benefit from developing stronger problem-solving capabilities and a more innovative approach to complex challenges. At {match_percentage}%, they could become a more competitive candidate with targeted improvement in these areas."""
481
-
482
- # Final cleanup
483
- # Remove any remaining artifacts or formatting
484
- assessment = re.sub(r'\n+', ' ', assessment)
 
 
 
 
 
 
 
 
 
 
485
  assessment = re.sub(r'\s+', ' ', assessment)
486
  assessment = assessment.strip()
 
 
 
 
 
 
 
 
487
 
488
  # Make sure percentages are consistent
489
  assessment = re.sub(r'\b\d{1,2}%\b', f"{match_percentage}%", assessment)
 
410
 
411
  # Create a more specific prompt for T5 that focuses on detailed assessment
412
  prompt = f"""
413
+ Generate a professional expert assessment for a Google job candidate.
414
+ Skills detected: {skills_text}.
415
+ Strongest area: {top_category} ({categories_sorted[0][1]["adjusted_score"]}%).
416
+ Weakest area: {weak_category} ({categories_sorted[-1][1]["adjusted_score"]}%).
417
+ Overall match: {match_percentage}%.
418
 
419
+ Write an evaluative assessment that analyzes the candidate's fit for Google.
420
+ Start with "This candidate" and provide an expert evaluation of their Google fit.
 
 
 
 
421
 
422
+ This candidate"""
 
423
 
 
 
 
424
  try:
425
  # Generate the assessment using T5
426
  assessment_results = models['evaluator'](
427
  prompt,
428
  max_length=300,
429
  do_sample=True,
430
+ temperature=0.75,
431
  num_return_sequences=3
432
  )
433
 
434
+ # Find the best response with much more thorough cleaning
435
  best_assessment = None
436
  for result in assessment_results:
437
+ # Get the raw text
438
+ raw_text = result['generated_text'].strip()
 
 
 
439
 
440
+ # Extract just the part that starts with "This candidate"
441
+ if "This candidate" in raw_text:
442
+ # Find the start of the actual assessment
443
+ start_idx = raw_text.find("This candidate")
444
+ text = raw_text[start_idx:]
445
+
446
+ # Check if it's actually an assessment (not just instructions)
447
+ if len(text) > 50 and not any(x in text.lower() for x in [
448
+ "actionable advice",
449
+ "include specific",
450
+ "make an assessment",
451
+ "evaluate their",
452
+ "assess their",
453
+ "provide specific areas"
454
+ ]):
455
+ best_assessment = text
456
+ break
457
 
458
+ # Use the best response or generate a fallback if none were ideal
459
  if best_assessment:
460
  assessment = best_assessment
461
  else:
462
+ # Generate a completely manual assessment since T5 responses contain too many instructions
463
+ assessment = f"""This candidate demonstrates solid {top_category} with proficiency in {skills_text}.
464
+ However, they would need to strengthen their {weak_category} to meet Google's high standards.
465
+ To become more competitive, they should develop advanced problem-solving skills through algorithmic
466
+ challenges and contribute to open-source projects. Overall, at {match_percentage}% match,
467
+ they show potential but require targeted skill development before being ready for Google."""
 
 
 
 
 
 
 
468
 
469
  except Exception as e:
470
+ # Fallback to a completely manual assessment
471
  print(f"Error in T5 assessment generation: {e}")
472
+ assessment = f"""This candidate demonstrates solid {top_category} with proficiency in {skills_text}.
473
+ However, they would need to strengthen their {weak_category} to meet Google's high standards.
474
+ To become more competitive, they should develop advanced problem-solving skills through algorithmic
475
+ challenges and contribute to open-source projects. Overall, at {match_percentage}% match,
476
+ they show potential but require targeted skill development before being ready for Google."""
477
+
478
+ # Final cleanup - more aggressive to remove any remaining instructions
479
+ assessment = re.sub(r'include specific actionable advice.*?improvement\.', '', assessment, flags=re.DOTALL|re.IGNORECASE)
480
+ assessment = re.sub(r'make an assessment.*?resume\.', '', assessment, flags=re.DOTALL|re.IGNORECASE)
481
+ assessment = re.sub(r'evaluate their technical skills.*?google\.', '', assessment, flags=re.DOTALL|re.IGNORECASE)
482
+ assessment = re.sub(r'assess their strengths.*?contributions', '', assessment, flags=re.DOTALL|re.IGNORECASE)
483
+ assessment = re.sub(r'provide specific areas.*?needed', '', assessment, flags=re.DOTALL|re.IGNORECASE)
484
+ assessment = re.sub(r'give an overall.*?google', '', assessment, flags=re.DOTALL|re.IGNORECASE)
485
+
486
+ # Clean up any double spaces, newlines, etc.
487
  assessment = re.sub(r'\s+', ' ', assessment)
488
  assessment = assessment.strip()
489
+
490
+ # If cleaning removed too much text, use the fallback
491
+ if len(assessment) < 50 or not assessment.startswith("This candidate"):
492
+ assessment = f"""This candidate demonstrates solid {top_category} with proficiency in {skills_text}.
493
+ However, they would need to strengthen their {weak_category} to meet Google's high standards.
494
+ To become more competitive, they should develop advanced problem-solving skills through algorithmic
495
+ challenges and contribute to open-source projects. Overall, at {match_percentage}% match,
496
+ they show potential but require targeted skill development before being ready for Google."""
497
 
498
  # Make sure percentages are consistent
499
  assessment = re.sub(r'\b\d{1,2}%\b', f"{match_percentage}%", assessment)