Skip to content

Commit 17a256a

Browse files
authored
Create resume_ranker.py
1 parent b2a9ceb commit 17a256a

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

resume_ranker.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import os
2+
import argparse
3+
from sklearn.feature_extraction.text import TfidfVectorizer
4+
from sklearn.metrics.pairwise import cosine_similarity
5+
import PyPDF2
6+
7+
def extract_text_from_pdf(pdf_path):
8+
text = ""
9+
try:
10+
with open(pdf_path, "rb") as file:
11+
reader = PyPDF2.PdfReader(file)
12+
for page in reader.pages:
13+
text += page.extract_text() or ""
14+
except Exception as e:
15+
print(f"Error reading PDF: {e}")
16+
return text
17+
18+
def read_text_file(path):
19+
try:
20+
with open(path, "r", encoding="utf-8") as f:
21+
return f.read()
22+
except Exception as e:
23+
print(f"Error reading file: {e}")
24+
return ""
25+
26+
def calculate_similarity(resume_text, jd_text):
27+
tfidf = TfidfVectorizer(stop_words='english')
28+
tfidf_matrix = tfidf.fit_transform([resume_text, jd_text])
29+
score = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix[1:2])[0][0]
30+
return round(score * 100, 2) # percentage match
31+
32+
def main():
33+
parser = argparse.ArgumentParser(description="AI Resume Ranker")
34+
parser.add_argument('--resume', required=True, help="Path to resume file (.txt or .pdf)")
35+
parser.add_argument('--jd', required=True, help="Path to job description (.txt)")
36+
37+
args = parser.parse_args()
38+
39+
resume_path = args.resume
40+
jd_path = args.jd
41+
42+
# Load resume
43+
if resume_path.lower().endswith(".pdf"):
44+
resume_text = extract_text_from_pdf(resume_path)
45+
elif resume_path.lower().endswith(".txt"):
46+
resume_text = read_text_file(resume_path)
47+
else:
48+
print("Unsupported resume file type. Use .pdf or .txt")
49+
return
50+
51+
# Load job description
52+
jd_text = read_text_file(jd_path)
53+
54+
if not resume_text.strip() or not jd_text.strip():
55+
print("Both resume and job description must contain text.")
56+
return
57+
58+
score = calculate_similarity(resume_text, jd_text)
59+
print(f"\n🔍 Resume Match Score: {score}%")
60+
61+
if score > 80:
62+
print("✅ Strong match! Consider applying.")
63+
elif score > 60:
64+
print("⚠️ Decent match. Tailoring may help.")
65+
else:
66+
print("❌ Low match. Consider improving the resume.")
67+
68+
if __name__ == "__main__":
69+
main()

0 commit comments

Comments
 (0)