Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,56 +59,62 @@ def display_resume(file, index):
|
|
| 59 |
else:
|
| 60 |
st.error(f"Unsupported file type for {file.name}. Please upload a PDF or DOCX file.")
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
def analyze_multiple_resumes(resumes, job_description):
|
| 63 |
"""Analyze multiple resumes and display the results."""
|
| 64 |
-
|
| 65 |
for index, resume in enumerate(resumes):
|
| 66 |
resume.seek(0) # Reset file pointer
|
| 67 |
file_type = resume.name.split('.')[-1].lower()
|
| 68 |
|
| 69 |
# Extract resume text based on file type
|
| 70 |
if file_type == 'pdf':
|
| 71 |
-
|
| 72 |
elif file_type == 'docx':
|
| 73 |
-
|
| 74 |
|
| 75 |
-
# Analyze the resume
|
| 76 |
-
analysis = analyze_documents(
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
st.write(response_text)
|
| 84 |
-
|
| 85 |
-
# Extract match percentage safely
|
| 86 |
-
lines = response_text.split("\n")
|
| 87 |
-
match_percentage = None
|
| 88 |
-
for line in lines:
|
| 89 |
-
if "match percentage" in line.lower():
|
| 90 |
-
# Try to extract the match percentage
|
| 91 |
-
percentage_str = ''.join(filter(str.isdigit, line.split(":")[-1].strip()))
|
| 92 |
-
if percentage_str: # If there's a valid numeric match percentage
|
| 93 |
-
try:
|
| 94 |
-
match_percentage = int(percentage_str)
|
| 95 |
-
# Cap the match percentage to 100
|
| 96 |
-
if match_percentage > 100:
|
| 97 |
-
match_percentage = 100
|
| 98 |
-
except ValueError:
|
| 99 |
-
st.error(f"Error processing match percentage in resume {resume.name}")
|
| 100 |
-
match_percentage = 0 # Default to 0 if there's an issue
|
| 101 |
-
|
| 102 |
-
if match_percentage is not None:
|
| 103 |
-
match_percentages.append(match_percentage)
|
| 104 |
-
st.write(f"### Match Percentage for {resume.name}: {match_percentage}%")
|
| 105 |
-
st.progress(match_percentage / 100) # Convert to decimal format
|
| 106 |
-
|
| 107 |
-
# Display overall match percentage across all resumes
|
| 108 |
-
if match_percentages:
|
| 109 |
-
avg_match_percentage = sum(match_percentages) / len(match_percentages)
|
| 110 |
-
st.write(f"### Average Match Percentage for All Resumes: {avg_match_percentage:.2f}%")
|
| 111 |
-
st.progress(avg_match_percentage / 100) # Convert to decimal format
|
| 112 |
|
| 113 |
# Streamlit app configuration
|
| 114 |
st.set_page_config(page_title="ATS Resume Evaluation System", layout="wide")
|
|
|
|
| 59 |
else:
|
| 60 |
st.error(f"Unsupported file type for {file.name}. Please upload a PDF or DOCX file.")
|
| 61 |
|
| 62 |
+
def extract_full_analysis(response):
|
| 63 |
+
"""Extract the full analysis (match percentage, missing keywords, etc.) from the API response."""
|
| 64 |
+
try:
|
| 65 |
+
# Get the analysis content from the API response
|
| 66 |
+
analysis_content = response.get("choices", [{}])[0].get("text", "")
|
| 67 |
+
|
| 68 |
+
# Regex to extract the match percentage, missing keywords, final thoughts, and recommendations
|
| 69 |
+
match_percentage = re.search(r"Match Percentage:.*?([a-zA-Z0-9\s\-\(\)<>\d]+%)", analysis_content)
|
| 70 |
+
missing_keywords = re.search(r"Missing Keywords:([\s\S]*?)(?=\n\n|Final Thoughts)", analysis_content)
|
| 71 |
+
final_thoughts = re.search(r"Final Thoughts:\n\n([\s\S]*?)(?=\n\n|Recommendations)", analysis_content)
|
| 72 |
+
recommendations = re.search(r"Recommendations:\n\n([\s\S]*?)(?=\n\n|$)", analysis_content)
|
| 73 |
+
|
| 74 |
+
# Extracted content
|
| 75 |
+
match_percentage = match_percentage.group(1) if match_percentage else "Match Percentage: N/A"
|
| 76 |
+
missing_keywords = missing_keywords.group(1).strip() if missing_keywords else "No missing keywords identified."
|
| 77 |
+
final_thoughts = final_thoughts.group(1).strip() if final_thoughts else "No final thoughts provided."
|
| 78 |
+
recommendations = recommendations.group(1).strip() if recommendations else "No recommendations provided."
|
| 79 |
+
|
| 80 |
+
return {
|
| 81 |
+
"match_percentage": match_percentage,
|
| 82 |
+
"missing_keywords": missing_keywords,
|
| 83 |
+
"final_thoughts": final_thoughts,
|
| 84 |
+
"recommendations": recommendations
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
except Exception as e:
|
| 88 |
+
st.error(f"Error extracting analysis: {str(e)}")
|
| 89 |
+
return {
|
| 90 |
+
"match_percentage": "Match Percentage: N/A",
|
| 91 |
+
"missing_keywords": "Error extracting missing keywords.",
|
| 92 |
+
"final_thoughts": "Error extracting final thoughts.",
|
| 93 |
+
"recommendations": "Error extracting recommendations."
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
def analyze_multiple_resumes(resumes, job_description):
|
| 97 |
"""Analyze multiple resumes and display the results."""
|
| 98 |
+
|
| 99 |
for index, resume in enumerate(resumes):
|
| 100 |
resume.seek(0) # Reset file pointer
|
| 101 |
file_type = resume.name.split('.')[-1].lower()
|
| 102 |
|
| 103 |
# Extract resume text based on file type
|
| 104 |
if file_type == 'pdf':
|
| 105 |
+
text = extract_text_from_pdf(resume) # Use PyMuPDF
|
| 106 |
elif file_type == 'docx':
|
| 107 |
+
text = extract_text_from_docx(resume)
|
| 108 |
|
| 109 |
+
# Analyze the resume once
|
| 110 |
+
analysis = analyze_documents(text, job_description)
|
| 111 |
+
full_analysis = extract_full_analysis(analysis)
|
| 112 |
|
| 113 |
+
# Display the full analysis result
|
| 114 |
+
st.write(f"### Match Percentage: {full_analysis['match_percentage']}")
|
| 115 |
+
st.write(f"### Missing Keywords: {full_analysis['missing_keywords']}")
|
| 116 |
+
st.write(f"### Final Thoughts:\n{full_analysis['final_thoughts']}")
|
| 117 |
+
st.write(f"### Recommendations:\n{full_analysis['recommendations']}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
# Streamlit app configuration
|
| 120 |
st.set_page_config(page_title="ATS Resume Evaluation System", layout="wide")
|