Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,12 @@
|
|
| 1 |
-
import time
|
| 2 |
import gradio as gr
|
| 3 |
-
from sentence_transformers import SentenceTransformer
|
| 4 |
import os
|
| 5 |
from PyPDF2 import PdfReader
|
| 6 |
import docx
|
| 7 |
import re
|
| 8 |
import google.generativeai as genai
|
| 9 |
import pandas as pd
|
| 10 |
-
import
|
| 11 |
|
| 12 |
# Load pre-trained embedding model for basic analysis
|
| 13 |
sentence_model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
|
|
@@ -21,6 +20,51 @@ genai.configure(api_key=api_key)
|
|
| 21 |
# Maximum resumes to process
|
| 22 |
MAX_RESUMES = 10
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
# Helper Functions
|
| 25 |
def extract_text_from_file(file_path):
|
| 26 |
ext = os.path.splitext(file_path)[1].lower()
|
|
@@ -107,42 +151,6 @@ def calculate_overall_match(leadership_years, management_years, skills, required
|
|
| 107 |
overall_match = (leadership_score * leadership_weight) + (management_score * management_weight) + (skill_score * skills_weight)
|
| 108 |
return round(overall_match, 2)
|
| 109 |
|
| 110 |
-
def process_resume(resume, job_desc, required_skills):
|
| 111 |
-
resume_text = extract_text_from_file(resume.name)
|
| 112 |
-
|
| 113 |
-
if not resume_text.strip():
|
| 114 |
-
return {
|
| 115 |
-
"Resume": resume.name,
|
| 116 |
-
"Candidate Name": "N/A",
|
| 117 |
-
"Email": "N/A",
|
| 118 |
-
"Contact": "N/A",
|
| 119 |
-
"Overall Match Percentage": 0.0,
|
| 120 |
-
"Gemini Analysis": "Failed to extract text from resume."
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
# Detailed analysis with Gemini API
|
| 124 |
-
try:
|
| 125 |
-
gemini_analysis = analyze_with_gemini(resume_text, job_desc)
|
| 126 |
-
# Extract leadership and management details
|
| 127 |
-
leadership_years, management_years, skills = extract_management_details(gemini_analysis)
|
| 128 |
-
# Calculate overall match percentage
|
| 129 |
-
overall_match = calculate_overall_match(leadership_years, management_years, skills, required_skills)
|
| 130 |
-
# Extract candidate details
|
| 131 |
-
name, email, contact = extract_candidate_details(gemini_analysis)
|
| 132 |
-
except Exception as e:
|
| 133 |
-
gemini_analysis = f"Gemini analysis failed: {str(e)}"
|
| 134 |
-
name, email, contact = "N/A", "N/A", "N/A"
|
| 135 |
-
overall_match = 0.0
|
| 136 |
-
|
| 137 |
-
return {
|
| 138 |
-
"Resume": resume.name,
|
| 139 |
-
"Candidate Name": name,
|
| 140 |
-
"Email": email,
|
| 141 |
-
"Contact": contact,
|
| 142 |
-
"Overall Match Percentage": overall_match,
|
| 143 |
-
"Gemini Analysis": gemini_analysis
|
| 144 |
-
}
|
| 145 |
-
|
| 146 |
def process_resumes(job_desc_file, resumes):
|
| 147 |
if not job_desc_file or not resumes:
|
| 148 |
return "Please upload a job description and resumes for analysis."
|
|
@@ -153,16 +161,43 @@ def process_resumes(job_desc_file, resumes):
|
|
| 153 |
# Load job description text
|
| 154 |
job_desc = extract_text_from_file(job_desc_file)
|
| 155 |
|
| 156 |
-
# Define the key leadership and management skills you're looking for
|
| 157 |
-
required_skills = ["strategic planning", "team management", "project management", "decision making", "communication"]
|
| 158 |
-
|
| 159 |
results = []
|
| 160 |
-
for
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
# Create a pandas DataFrame for better formatting and downloadable output
|
| 168 |
df = pd.DataFrame(results)
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from sentence_transformers import SentenceTransformer, util
|
| 3 |
import os
|
| 4 |
from PyPDF2 import PdfReader
|
| 5 |
import docx
|
| 6 |
import re
|
| 7 |
import google.generativeai as genai
|
| 8 |
import pandas as pd
|
| 9 |
+
import time
|
| 10 |
|
| 11 |
# Load pre-trained embedding model for basic analysis
|
| 12 |
sentence_model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
|
|
|
|
| 20 |
# Maximum resumes to process
|
| 21 |
MAX_RESUMES = 10
|
| 22 |
|
| 23 |
+
# Define the key leadership and management skills you're looking for
|
| 24 |
+
required_skills = [
|
| 25 |
+
"strategic planning",
|
| 26 |
+
"team management",
|
| 27 |
+
"project management",
|
| 28 |
+
"decision making",
|
| 29 |
+
"communication",
|
| 30 |
+
"leadership",
|
| 31 |
+
"conflict resolution",
|
| 32 |
+
"delegation",
|
| 33 |
+
"performance management",
|
| 34 |
+
"budget management",
|
| 35 |
+
"resource allocation",
|
| 36 |
+
"staff development",
|
| 37 |
+
"change management",
|
| 38 |
+
"risk management",
|
| 39 |
+
"problem solving",
|
| 40 |
+
"negotiation",
|
| 41 |
+
"executive leadership",
|
| 42 |
+
"organizational skills",
|
| 43 |
+
"business development",
|
| 44 |
+
"stakeholder management",
|
| 45 |
+
"collaboration",
|
| 46 |
+
"emotional intelligence",
|
| 47 |
+
"coaching",
|
| 48 |
+
"mentoring",
|
| 49 |
+
"time management",
|
| 50 |
+
"cross-functional team leadership",
|
| 51 |
+
"innovation",
|
| 52 |
+
"organizational culture",
|
| 53 |
+
"team motivation",
|
| 54 |
+
"employee engagement",
|
| 55 |
+
"organizational design",
|
| 56 |
+
"continuous improvement",
|
| 57 |
+
"decision-making under pressure",
|
| 58 |
+
"adaptability",
|
| 59 |
+
"accountability",
|
| 60 |
+
"team building",
|
| 61 |
+
"succession planning",
|
| 62 |
+
"strategic partnerships",
|
| 63 |
+
"executive presence",
|
| 64 |
+
"influencing",
|
| 65 |
+
"visionary leadership"
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
# Helper Functions
|
| 69 |
def extract_text_from_file(file_path):
|
| 70 |
ext = os.path.splitext(file_path)[1].lower()
|
|
|
|
| 151 |
overall_match = (leadership_score * leadership_weight) + (management_score * management_weight) + (skill_score * skills_weight)
|
| 152 |
return round(overall_match, 2)
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
def process_resumes(job_desc_file, resumes):
|
| 155 |
if not job_desc_file or not resumes:
|
| 156 |
return "Please upload a job description and resumes for analysis."
|
|
|
|
| 161 |
# Load job description text
|
| 162 |
job_desc = extract_text_from_file(job_desc_file)
|
| 163 |
|
|
|
|
|
|
|
|
|
|
| 164 |
results = []
|
| 165 |
+
for resume in resumes:
|
| 166 |
+
resume_text = extract_text_from_file(resume.name)
|
| 167 |
+
|
| 168 |
+
if not resume_text.strip():
|
| 169 |
+
results.append({
|
| 170 |
+
"Resume": resume.name,
|
| 171 |
+
"Candidate Name": "N/A",
|
| 172 |
+
"Email": "N/A",
|
| 173 |
+
"Contact": "N/A",
|
| 174 |
+
"Overall Match Percentage": 0.0,
|
| 175 |
+
"Gemini Analysis": "Failed to extract text from resume."
|
| 176 |
+
})
|
| 177 |
+
continue
|
| 178 |
+
|
| 179 |
+
# Detailed analysis with Gemini API
|
| 180 |
+
try:
|
| 181 |
+
gemini_analysis = analyze_with_gemini(resume_text, job_desc)
|
| 182 |
+
# Extract leadership and management details
|
| 183 |
+
leadership_years, management_years, skills = extract_management_details(gemini_analysis)
|
| 184 |
+
# Calculate overall match percentage
|
| 185 |
+
overall_match = calculate_overall_match(leadership_years, management_years, skills, required_skills)
|
| 186 |
+
# Extract candidate details
|
| 187 |
+
name, email, contact = extract_candidate_details(gemini_analysis)
|
| 188 |
+
except Exception as e:
|
| 189 |
+
gemini_analysis = f"Gemini analysis failed: {str(e)}"
|
| 190 |
+
name, email, contact = "N/A", "N/A", "N/A"
|
| 191 |
+
overall_match = 0.0
|
| 192 |
+
|
| 193 |
+
results.append({
|
| 194 |
+
"Resume": resume.name,
|
| 195 |
+
"Candidate Name": name,
|
| 196 |
+
"Email": email,
|
| 197 |
+
"Contact": contact,
|
| 198 |
+
"Overall Match Percentage": f"{overall_match}%",
|
| 199 |
+
"Gemini Analysis": gemini_analysis
|
| 200 |
+
})
|
| 201 |
|
| 202 |
# Create a pandas DataFrame for better formatting and downloadable output
|
| 203 |
df = pd.DataFrame(results)
|