Update app.py
Browse files
app.py
CHANGED
|
@@ -3,9 +3,9 @@ from sentence_transformers import SentenceTransformer, util
|
|
| 3 |
import docx
|
| 4 |
import os
|
| 5 |
from PyPDF2 import PdfReader
|
|
|
|
| 6 |
import requests
|
| 7 |
import pandas as pd
|
| 8 |
-
import re
|
| 9 |
|
| 10 |
# Load pre-trained model for sentence embedding
|
| 11 |
model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
|
|
@@ -70,7 +70,7 @@ def system_prompt_to_extract_info(resume_text):
|
|
| 70 |
"""
|
| 71 |
return prompt
|
| 72 |
|
| 73 |
-
# Function to extract candidate information from resume text
|
| 74 |
def extract_entities_via_gemini(resume_text):
|
| 75 |
api_key = get_google_api_key() # Fetch the API key from environment variables
|
| 76 |
endpoint = "https://gemini.googleapis.com/v1/documents:analyzeEntities" # Placeholder API endpoint (adjust as necessary)
|
|
@@ -86,42 +86,49 @@ def extract_entities_via_gemini(resume_text):
|
|
| 86 |
"content": resume_text
|
| 87 |
}
|
| 88 |
}
|
| 89 |
-
|
| 90 |
# Send request to Gemini or another NLP API
|
| 91 |
response = requests.post(endpoint, headers=headers, json=document)
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
if response.status_code != 200:
|
| 94 |
-
return {"error": "Failed to extract entities from resume", "status_code": response.status_code, "response": response.
|
| 95 |
-
|
| 96 |
-
#
|
| 97 |
-
|
|
|
|
|
|
|
| 98 |
extracted_info = {"name": "Unknown Candidate", "email": "No Email", "contact": "No Contact"}
|
| 99 |
|
| 100 |
-
for
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
return extracted_info
|
| 109 |
|
| 110 |
-
#
|
| 111 |
-
def
|
| 112 |
-
# Define
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
| 125 |
|
| 126 |
# Function to check similarity between resumes and job description
|
| 127 |
def check_similarity(job_description, resume_files):
|
|
@@ -141,7 +148,7 @@ def check_similarity(job_description, resume_files):
|
|
| 141 |
# Convert similarity score to percentage
|
| 142 |
similarity_percentage = similarity_score * 100
|
| 143 |
|
| 144 |
-
# Extract leadership experience
|
| 145 |
leadership_experience = extract_leadership_experience(resume_text)
|
| 146 |
|
| 147 |
# Extract name, email, and contact info using Google Gemini API
|
|
@@ -197,11 +204,10 @@ def download_results(results):
|
|
| 197 |
interface = gr.Interface(
|
| 198 |
fn=check_similarity,
|
| 199 |
inputs=[job_desc_input, resumes_input],
|
| 200 |
-
outputs=[results_output, gr.File(label="Download CSV")],
|
| 201 |
title="HR Assistant - Resume Screening & Leadership Experience",
|
| 202 |
description="Upload job description and resumes to screen candidates for managerial and team leadership roles and extract candidate details.",
|
| 203 |
allow_flagging="never"
|
| 204 |
)
|
| 205 |
|
| 206 |
-
# Launch the interface
|
| 207 |
interface.launch()
|
|
|
|
| 3 |
import docx
|
| 4 |
import os
|
| 5 |
from PyPDF2 import PdfReader
|
| 6 |
+
import re
|
| 7 |
import requests
|
| 8 |
import pandas as pd
|
|
|
|
| 9 |
|
| 10 |
# Load pre-trained model for sentence embedding
|
| 11 |
model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
|
|
|
|
| 70 |
"""
|
| 71 |
return prompt
|
| 72 |
|
| 73 |
+
# Function to extract candidate information from resume text using Gemini API
|
| 74 |
def extract_entities_via_gemini(resume_text):
|
| 75 |
api_key = get_google_api_key() # Fetch the API key from environment variables
|
| 76 |
endpoint = "https://gemini.googleapis.com/v1/documents:analyzeEntities" # Placeholder API endpoint (adjust as necessary)
|
|
|
|
| 86 |
"content": resume_text
|
| 87 |
}
|
| 88 |
}
|
| 89 |
+
|
| 90 |
# Send request to Gemini or another NLP API
|
| 91 |
response = requests.post(endpoint, headers=headers, json=document)
|
| 92 |
|
| 93 |
+
# Debugging: Log raw response
|
| 94 |
+
print(f"Response Status Code: {response.status_code}")
|
| 95 |
+
print(f"Response Content: {response.text}") # Log the raw response content
|
| 96 |
+
|
| 97 |
if response.status_code != 200:
|
| 98 |
+
return {"error": "Failed to extract entities from resume", "status_code": response.status_code, "response": response.text}
|
| 99 |
+
|
| 100 |
+
# Use the raw text response (instead of parsing as JSON)
|
| 101 |
+
response_text = response.text
|
| 102 |
+
|
| 103 |
+
# You can now use `response_text` directly as you wish. For example, if you're extracting specific information:
|
| 104 |
extracted_info = {"name": "Unknown Candidate", "email": "No Email", "contact": "No Contact"}
|
| 105 |
|
| 106 |
+
# Check for keywords in the response text to extract candidate info
|
| 107 |
+
if "name" in response_text:
|
| 108 |
+
extracted_info['name'] = extract_info_from_text(response_text, 'name')
|
| 109 |
+
if "email" in response_text:
|
| 110 |
+
extracted_info['email'] = extract_info_from_text(response_text, 'email')
|
| 111 |
+
if "contact" in response_text:
|
| 112 |
+
extracted_info['contact'] = extract_info_from_text(response_text, 'contact')
|
| 113 |
+
|
| 114 |
return extracted_info
|
| 115 |
|
| 116 |
+
# Helper function to extract specific information from raw response text
|
| 117 |
+
def extract_info_from_text(response_text, info_type):
|
| 118 |
+
# Define simple patterns to match relevant information (you can improve this regex as needed)
|
| 119 |
+
if info_type == 'name':
|
| 120 |
+
match = re.search(r"Name: (\S+ \S+)", response_text)
|
| 121 |
+
if match:
|
| 122 |
+
return match.group(1)
|
| 123 |
+
elif info_type == 'email':
|
| 124 |
+
match = re.search(r"Email: (\S+@\S+)", response_text)
|
| 125 |
+
if match:
|
| 126 |
+
return match.group(1)
|
| 127 |
+
elif info_type == 'contact':
|
| 128 |
+
match = re.search(r"Contact: (\S+)", response_text)
|
| 129 |
+
if match:
|
| 130 |
+
return match.group(1)
|
| 131 |
+
return f"No {info_type}"
|
| 132 |
|
| 133 |
# Function to check similarity between resumes and job description
|
| 134 |
def check_similarity(job_description, resume_files):
|
|
|
|
| 148 |
# Convert similarity score to percentage
|
| 149 |
similarity_percentage = similarity_score * 100
|
| 150 |
|
| 151 |
+
# Extract leadership experience (make sure this function is implemented)
|
| 152 |
leadership_experience = extract_leadership_experience(resume_text)
|
| 153 |
|
| 154 |
# Extract name, email, and contact info using Google Gemini API
|
|
|
|
| 204 |
interface = gr.Interface(
|
| 205 |
fn=check_similarity,
|
| 206 |
inputs=[job_desc_input, resumes_input],
|
| 207 |
+
outputs=[results_output, gr.File(label="Download CSV", fn=download_results)],
|
| 208 |
title="HR Assistant - Resume Screening & Leadership Experience",
|
| 209 |
description="Upload job description and resumes to screen candidates for managerial and team leadership roles and extract candidate details.",
|
| 210 |
allow_flagging="never"
|
| 211 |
)
|
| 212 |
|
|
|
|
| 213 |
interface.launch()
|