Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -575,8 +575,15 @@ def summarize_resume_text(resume_text, models):
|
|
575 |
job_position = extract_job_position(resume_text)
|
576 |
skills = extract_skills(resume_text)
|
577 |
|
578 |
-
# Extract work experience
|
579 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
580 |
|
581 |
# Format the structured summary with different paragraphs for each critical piece
|
582 |
formatted_summary = f"Name: {name}\n\n"
|
@@ -584,15 +591,15 @@ def summarize_resume_text(resume_text, models):
|
|
584 |
formatted_summary += f"Expected Industry: {industry}\n\n"
|
585 |
formatted_summary += f"Expected Job Position: {job_position}\n\n"
|
586 |
formatted_summary += f"Skills: {', '.join(skills)}\n\n"
|
587 |
-
formatted_summary += f"Previous Work Experience: {
|
588 |
|
589 |
execution_time = time.time() - start_time
|
590 |
|
591 |
return formatted_summary, execution_time
|
592 |
|
593 |
-
# Extract work experience
|
594 |
-
def
|
595 |
-
"""Extract work experience from resume
|
596 |
# Work experience extraction
|
597 |
work_headers = [
|
598 |
"work experience", "professional experience", "employment history",
|
@@ -607,7 +614,7 @@ def extract_work_experience(text):
|
|
607 |
lines = text.split('\n')
|
608 |
text_lower = text.lower()
|
609 |
|
610 |
-
# Work experience extraction
|
611 |
work_section = []
|
612 |
in_work_section = False
|
613 |
|
@@ -627,49 +634,31 @@ def extract_work_experience(text):
|
|
627 |
if line.strip():
|
628 |
work_section.append(line.strip())
|
629 |
|
630 |
-
#
|
631 |
-
if
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
return "
|
653 |
-
|
654 |
-
|
655 |
-
work_lines = []
|
656 |
-
company_count = 0
|
657 |
-
|
658 |
-
for line in work_section:
|
659 |
-
# New company entry often has a date
|
660 |
-
if re.search(r'(19|20)\d{2}', line):
|
661 |
-
company_count += 1
|
662 |
-
if company_count <= 3: # Limit to 3 most recent positions
|
663 |
-
work_lines.append(f"• {line}")
|
664 |
-
else:
|
665 |
-
break
|
666 |
-
elif company_count <= 3 and len(work_lines) < 10: # Limit total lines
|
667 |
-
if line.strip() and len(line) > 5:
|
668 |
-
work_lines.append(f" {line}")
|
669 |
-
|
670 |
-
if work_lines:
|
671 |
-
return "\n".join(work_lines)
|
672 |
-
return "Work experience mentioned but details unclear"
|
673 |
|
674 |
#####################################
|
675 |
# Function: Extract Job Requirements
|
|
|
575 |
job_position = extract_job_position(resume_text)
|
576 |
skills = extract_skills(resume_text)
|
577 |
|
578 |
+
# Extract work experience section
|
579 |
+
work_experience_text = extract_work_experience_section(resume_text)
|
580 |
+
|
581 |
+
# Use the summarization model to summarize the work experience
|
582 |
+
if work_experience_text:
|
583 |
+
# Summarize work experience using the model
|
584 |
+
work_summary = summarize_text(work_experience_text, models, max_length=150)
|
585 |
+
else:
|
586 |
+
work_summary = "No detailed work experience found in the resume."
|
587 |
|
588 |
# Format the structured summary with different paragraphs for each critical piece
|
589 |
formatted_summary = f"Name: {name}\n\n"
|
|
|
591 |
formatted_summary += f"Expected Industry: {industry}\n\n"
|
592 |
formatted_summary += f"Expected Job Position: {job_position}\n\n"
|
593 |
formatted_summary += f"Skills: {', '.join(skills)}\n\n"
|
594 |
+
formatted_summary += f"Previous Work Experience: {work_summary}"
|
595 |
|
596 |
execution_time = time.time() - start_time
|
597 |
|
598 |
return formatted_summary, execution_time
|
599 |
|
600 |
+
# Extract work experience section
|
601 |
+
def extract_work_experience_section(text):
|
602 |
+
"""Extract work experience section from resume for summarization"""
|
603 |
# Work experience extraction
|
604 |
work_headers = [
|
605 |
"work experience", "professional experience", "employment history",
|
|
|
614 |
lines = text.split('\n')
|
615 |
text_lower = text.lower()
|
616 |
|
617 |
+
# Work experience extraction
|
618 |
work_section = []
|
619 |
in_work_section = False
|
620 |
|
|
|
634 |
if line.strip():
|
635 |
work_section.append(line.strip())
|
636 |
|
637 |
+
# If we found a work section, join it back into text for summarization
|
638 |
+
if work_section:
|
639 |
+
return "\n".join(work_section)
|
640 |
+
|
641 |
+
# If no explicit work section found, try to extract paragraphs that might contain work experience
|
642 |
+
# Look for company names, dates, job titles
|
643 |
+
work_related_paragraphs = []
|
644 |
+
paragraphs = text.split('\n\n')
|
645 |
+
|
646 |
+
for paragraph in paragraphs:
|
647 |
+
# Check if paragraph has dates that look like work experience
|
648 |
+
if re.search(r'(19|20)\d{2}\s*-\s*(19|20)\d{2}|present|current', paragraph, re.IGNORECASE):
|
649 |
+
work_related_paragraphs.append(paragraph)
|
650 |
+
# Check for common job titles
|
651 |
+
elif re.search(r'\b(engineer|developer|manager|analyst|director|consultant|specialist)\b',
|
652 |
+
paragraph, re.IGNORECASE):
|
653 |
+
work_related_paragraphs.append(paragraph)
|
654 |
+
# Check for company indicators
|
655 |
+
elif re.search(r'\b(company|corporation|inc\.|corp\.|ltd\.)\b', paragraph, re.IGNORECASE):
|
656 |
+
work_related_paragraphs.append(paragraph)
|
657 |
+
|
658 |
+
if work_related_paragraphs:
|
659 |
+
return "\n\n".join(work_related_paragraphs)
|
660 |
+
|
661 |
+
return "" # Return empty string if no work experience found
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
662 |
|
663 |
#####################################
|
664 |
# Function: Extract Job Requirements
|