Spaces:
Build error
Build error
Update similarity_score_refined.py
Browse files- similarity_score_refined.py +13 -14
similarity_score_refined.py
CHANGED
|
@@ -32,9 +32,6 @@ def read_file(file_path):
|
|
| 32 |
# Provide a more informative error message if the file is not a valid docx
|
| 33 |
raise PackageNotFoundError(f"The file {file_path} is not a valid docx file. It may be corrupted or of a different format.")
|
| 34 |
|
| 35 |
-
import os
|
| 36 |
-
# os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/content/drive/MyDrive/Resume/firm-capsule-436804-b5-5f553d9f1043.json"
|
| 37 |
-
|
| 38 |
import os
|
| 39 |
# from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 40 |
# from langchain_community.vectorstores.faiss import FAISS
|
|
@@ -54,11 +51,9 @@ model = genai.GenerativeModel('gemini-pro')
|
|
| 54 |
def similarity_main(tailored_resume_path, job_description_path):
|
| 55 |
"""
|
| 56 |
Use Gemini Pro to evaluate the relevance score between a tailored resume and job description.
|
| 57 |
-
|
| 58 |
Args:
|
| 59 |
- tailored_resume (str): Tailored resume content.
|
| 60 |
- job_description (str): Job description content.
|
| 61 |
-
|
| 62 |
Returns:
|
| 63 |
- dict: A dictionary containing the 'score' (scaled to 0–100) and 'reason'.
|
| 64 |
"""
|
|
@@ -69,15 +64,18 @@ def similarity_main(tailored_resume_path, job_description_path):
|
|
| 69 |
You are a recruitment expert evaluating how well a tailored resume aligns with a job description. Provide a realistic and concise evaluation based on the following criteria:
|
| 70 |
1. Relevance of skills and experience: Do the candidate’s skills, accomplishments, and experience meet the job's core requirements?
|
| 71 |
2. Domain Match: Are the candidate's experiences and achievements relevant to the industry or role?
|
| 72 |
-
3. Clarity and Conciseness: Is the resume
|
| 73 |
4. Highlight any gaps or mismatched qualifications realistically.
|
| 74 |
-
|
|
|
|
| 75 |
Score: [Score between 0 and 1]
|
| 76 |
Reason: [One or two sentences explaining the score]
|
|
|
|
| 77 |
Here is the tailored resume:
|
| 78 |
[Resume Start]
|
| 79 |
{resume_text}
|
| 80 |
[Resume End]
|
|
|
|
| 81 |
And the job description below:
|
| 82 |
[Job Description Start]
|
| 83 |
{job_description}
|
|
@@ -86,28 +84,30 @@ And the job description below:
|
|
| 86 |
|
| 87 |
try:
|
| 88 |
# Get the response from Gemini Pro
|
| 89 |
-
|
|
|
|
| 90 |
candidates = response.candidates
|
| 91 |
if not candidates or len(candidates) == 0:
|
| 92 |
raise ValueError("No candidates found in the response.")
|
| 93 |
|
| 94 |
# Extract content text
|
| 95 |
content_text = candidates[0].content.parts[0].text
|
| 96 |
-
print(f"Response from Gemini Pro:\n{content_text}") # Debugging
|
| 97 |
|
| 98 |
# Extract score and reason with simple parsing
|
| 99 |
lines = content_text.split("\n")
|
| 100 |
score = None
|
| 101 |
reason = None
|
| 102 |
-
|
| 103 |
for line in lines:
|
| 104 |
if line.lower().startswith("score:"):
|
| 105 |
try:
|
| 106 |
-
|
|
|
|
| 107 |
except ValueError:
|
| 108 |
raise ValueError(f"Invalid score format: {line}")
|
| 109 |
elif line.lower().startswith("reason:"):
|
| 110 |
-
|
|
|
|
| 111 |
|
| 112 |
# Ensure both score and reason are extracted
|
| 113 |
if score is None:
|
|
@@ -119,5 +119,4 @@ And the job description below:
|
|
| 119 |
|
| 120 |
except Exception as e:
|
| 121 |
print(f"Error in relevance checking: {e}")
|
| 122 |
-
return None
|
| 123 |
-
|
|
|
|
| 32 |
# Provide a more informative error message if the file is not a valid docx
|
| 33 |
raise PackageNotFoundError(f"The file {file_path} is not a valid docx file. It may be corrupted or of a different format.")
|
| 34 |
|
|
|
|
|
|
|
|
|
|
| 35 |
import os
|
| 36 |
# from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 37 |
# from langchain_community.vectorstores.faiss import FAISS
|
|
|
|
| 51 |
def similarity_main(tailored_resume_path, job_description_path):
|
| 52 |
"""
|
| 53 |
Use Gemini Pro to evaluate the relevance score between a tailored resume and job description.
|
|
|
|
| 54 |
Args:
|
| 55 |
- tailored_resume (str): Tailored resume content.
|
| 56 |
- job_description (str): Job description content.
|
|
|
|
| 57 |
Returns:
|
| 58 |
- dict: A dictionary containing the 'score' (scaled to 0–100) and 'reason'.
|
| 59 |
"""
|
|
|
|
| 64 |
You are a recruitment expert evaluating how well a tailored resume aligns with a job description. Provide a realistic and concise evaluation based on the following criteria:
|
| 65 |
1. Relevance of skills and experience: Do the candidate’s skills, accomplishments, and experience meet the job's core requirements?
|
| 66 |
2. Domain Match: Are the candidate's experiences and achievements relevant to the industry or role?
|
| 67 |
+
3. Clarity and Conciseness: Is the resume focused on the job requirements?
|
| 68 |
4. Highlight any gaps or mismatched qualifications realistically.
|
| 69 |
+
|
| 70 |
+
Provide your response in this exact format and make sure that score is a floating point number.
|
| 71 |
Score: [Score between 0 and 1]
|
| 72 |
Reason: [One or two sentences explaining the score]
|
| 73 |
+
|
| 74 |
Here is the tailored resume:
|
| 75 |
[Resume Start]
|
| 76 |
{resume_text}
|
| 77 |
[Resume End]
|
| 78 |
+
|
| 79 |
And the job description below:
|
| 80 |
[Job Description Start]
|
| 81 |
{job_description}
|
|
|
|
| 84 |
|
| 85 |
try:
|
| 86 |
# Get the response from Gemini Pro
|
| 87 |
+
|
| 88 |
+
response = model.generate_content(prompt,generation_config={"temperature": 0.2})
|
| 89 |
candidates = response.candidates
|
| 90 |
if not candidates or len(candidates) == 0:
|
| 91 |
raise ValueError("No candidates found in the response.")
|
| 92 |
|
| 93 |
# Extract content text
|
| 94 |
content_text = candidates[0].content.parts[0].text
|
|
|
|
| 95 |
|
| 96 |
# Extract score and reason with simple parsing
|
| 97 |
lines = content_text.split("\n")
|
| 98 |
score = None
|
| 99 |
reason = None
|
| 100 |
+
print(content_text)
|
| 101 |
for line in lines:
|
| 102 |
if line.lower().startswith("score:"):
|
| 103 |
try:
|
| 104 |
+
line_cleaned = line.replace("**", "").strip()
|
| 105 |
+
score = float(line_cleaned.split(":", 1)[1].strip())
|
| 106 |
except ValueError:
|
| 107 |
raise ValueError(f"Invalid score format: {line}")
|
| 108 |
elif line.lower().startswith("reason:"):
|
| 109 |
+
|
| 110 |
+
reason = line.replace("**", "").split(":", 1)[1].strip()
|
| 111 |
|
| 112 |
# Ensure both score and reason are extracted
|
| 113 |
if score is None:
|
|
|
|
| 119 |
|
| 120 |
except Exception as e:
|
| 121 |
print(f"Error in relevance checking: {e}")
|
| 122 |
+
return None
|
|
|