Spaces:
Running
Running
Johnny
commited on
Commit
·
a5446bf
1
Parent(s):
8f771eb
removed score and summarization functions until bug is fixed
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
-
from utils import evaluate_resumes, generate_pdf_report, store_in_supabase,
|
3 |
from config import supabase
|
4 |
from config import HF_API_TOKEN, HF_HEADERS, HF_MODELS
|
5 |
import fitz # PyMuPDF
|
@@ -25,7 +25,7 @@ def main():
|
|
25 |
if st.button("Evaluate Resumes"):
|
26 |
shortlisted = evaluate_resumes(uploaded_files, job_description)
|
27 |
for candidate in shortlisted:
|
28 |
-
st.write(f"**{candidate['name']}** - Score: {candidate['score']}
|
29 |
|
30 |
# Generate PDF Report
|
31 |
pdf_report = generate_pdf_report(shortlisted)
|
|
|
1 |
import streamlit as st
|
2 |
+
from utils import evaluate_resumes, generate_pdf_report, store_in_supabase, extract_email, parse_resume #removed score_candidate, summarize_resume
|
3 |
from config import supabase
|
4 |
from config import HF_API_TOKEN, HF_HEADERS, HF_MODELS
|
5 |
import fitz # PyMuPDF
|
|
|
25 |
if st.button("Evaluate Resumes"):
|
26 |
shortlisted = evaluate_resumes(uploaded_files, job_description)
|
27 |
for candidate in shortlisted:
|
28 |
+
st.write(f"**{candidate['name']}**") # removed - Score: {candidate['score']}
|
29 |
|
30 |
# Generate PDF Report
|
31 |
pdf_report = generate_pdf_report(shortlisted)
|
utils.py
CHANGED
@@ -13,24 +13,24 @@ def evaluate_resumes(uploaded_files, job_description):
|
|
13 |
candidates = []
|
14 |
for pdf_file in uploaded_files:
|
15 |
resume_text = parse_resume(pdf_file)
|
16 |
-
score = score_candidate(resume_text, job_description)
|
17 |
email = extract_email(resume_text)
|
18 |
|
19 |
-
# Generate a summary of the resume
|
20 |
-
summary = summarize_resume(resume_text)
|
21 |
|
22 |
candidates.append({
|
23 |
"name": pdf_file.name,
|
24 |
"resume": resume_text,
|
25 |
-
"score": score,
|
26 |
"email": email,
|
27 |
-
"summary": summary
|
28 |
})
|
29 |
|
30 |
# Store all details including summary in Supabase
|
31 |
-
store_in_supabase(resume_text,
|
32 |
|
33 |
-
return
|
34 |
|
35 |
def parse_resume(pdf_file):
|
36 |
"""Extracts text from a resume PDF."""
|
@@ -43,58 +43,58 @@ def extract_email(resume_text):
|
|
43 |
match = re.search(r"[\w\.-]+@[\w\.-]+", resume_text)
|
44 |
return match.group(0) if match else None
|
45 |
|
46 |
-
def score_candidate(resume_text, job_description):
|
47 |
-
|
48 |
-
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
# summarize_resume function will use HuggingFace BART model
|
78 |
-
def summarize_resume(resume_text):
|
79 |
-
|
80 |
-
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
def store_in_supabase(resume_text,
|
98 |
"""
|
99 |
Stores resume data in Supabase.
|
100 |
|
@@ -104,21 +104,20 @@ def store_in_supabase(resume_text, score, candidate_name, email, summary):
|
|
104 |
:param email: Candidate's email address.
|
105 |
:param summary: A summarized version of the resume.
|
106 |
"""
|
107 |
-
if score is None:
|
108 |
-
|
109 |
|
110 |
data = {
|
111 |
"name": candidate_name,
|
112 |
"resume": resume_text,
|
113 |
-
"score": score,
|
114 |
"email": email,
|
115 |
-
"summary": summary
|
116 |
}
|
117 |
|
118 |
response = supabase.table("candidates").insert(data).execute()
|
119 |
return response
|
120 |
|
121 |
-
# Test with 10 resumes, if they will be shortlisted
|
122 |
def generate_pdf_report(shortlisted_candidates):
|
123 |
"""Generates a PDF summary of shortlisted candidates."""
|
124 |
pdf = BytesIO()
|
@@ -127,15 +126,15 @@ def generate_pdf_report(shortlisted_candidates):
|
|
127 |
for candidate in shortlisted_candidates:
|
128 |
page = doc.new_page()
|
129 |
|
130 |
-
# Use the stored summary, or provide a fallback
|
131 |
-
summary = candidate.get("summary", "No summary available")
|
132 |
|
133 |
page.insert_text(
|
134 |
(50, 50),
|
135 |
f"Candidate: {candidate['name']}\n"
|
136 |
f"Email: {candidate['email']}\n"
|
137 |
-
f"Score: {candidate['score']}\n"
|
138 |
-
f"Summary: {summary}"
|
139 |
)
|
140 |
|
141 |
doc.save(pdf)
|
|
|
13 |
candidates = []
|
14 |
for pdf_file in uploaded_files:
|
15 |
resume_text = parse_resume(pdf_file)
|
16 |
+
#score = score_candidate(resume_text, job_description)
|
17 |
email = extract_email(resume_text)
|
18 |
|
19 |
+
# # Generate a summary of the resume
|
20 |
+
# summary = summarize_resume(resume_text)
|
21 |
|
22 |
candidates.append({
|
23 |
"name": pdf_file.name,
|
24 |
"resume": resume_text,
|
25 |
+
#"score": score,
|
26 |
"email": email,
|
27 |
+
#"summary": summary
|
28 |
})
|
29 |
|
30 |
# Store all details including summary in Supabase
|
31 |
+
store_in_supabase(resume_text, pdf_file.name, email) # removed score, summary
|
32 |
|
33 |
+
return candidates # removed , key=lambda x: x["score"], reverse=True)[:5]
|
34 |
|
35 |
def parse_resume(pdf_file):
|
36 |
"""Extracts text from a resume PDF."""
|
|
|
43 |
match = re.search(r"[\w\.-]+@[\w\.-]+", resume_text)
|
44 |
return match.group(0) if match else None
|
45 |
|
46 |
+
# def score_candidate(resume_text, job_description):
|
47 |
+
# """
|
48 |
+
# Scores the candidate's resume based on the job description using the Hugging Face API.
|
49 |
|
50 |
+
# :param resume_text: The extracted resume text.
|
51 |
+
# :param job_description: The job description for comparison.
|
52 |
+
# :return: A numerical score (default 0 if scoring fails).
|
53 |
+
# """
|
54 |
+
# payload = {"inputs": f"Resume: {resume_text}\nJob Description: {job_description}"}
|
55 |
+
# response_gemma = query(payload, model="gemma") # Call Hugging Face API
|
56 |
+
|
57 |
+
# if response_gemma is None:
|
58 |
+
# print("API response is None")
|
59 |
+
# return 0
|
60 |
+
|
61 |
+
# print("API Response:", response_gemma) # Debugging
|
62 |
+
|
63 |
+
# # Handle list response
|
64 |
+
# if isinstance(response_gemma, list) and len(response_gemma) > 0:
|
65 |
+
# response_gemma = response_gemma[0] # Extract first item if response is a list
|
66 |
+
|
67 |
+
# try:
|
68 |
+
# if isinstance(response_gemma, dict) and "score" in response_gemma:
|
69 |
+
# return float(response_gemma["score"])
|
70 |
+
# else:
|
71 |
+
# print("Unexpected API response format:", response_gemma) # Debugging
|
72 |
+
# return 0 # Default if score is missing
|
73 |
+
# except (TypeError, ValueError) as e:
|
74 |
+
# print(f"Error parsing score: {e}")
|
75 |
+
# return 0
|
76 |
+
|
77 |
+
# # summarize_resume function will use HuggingFace BART model
|
78 |
+
# def summarize_resume(resume_text):
|
79 |
+
# """
|
80 |
+
# Summarizes the resume using Facebook's BART-Large-CNN model.
|
81 |
|
82 |
+
# :param resume_text: The extracted resume text.
|
83 |
+
# :return: A summarized version of the resume or an error message.
|
84 |
+
# """
|
85 |
+
# payload = {"inputs": resume_text}
|
86 |
+
# response_bart = query(payload, model="bart")
|
87 |
+
|
88 |
+
# if response_bart is None:
|
89 |
+
# return "Summary could not be generated." # Handle API failures gracefully
|
90 |
+
|
91 |
+
# try:
|
92 |
+
# summary = response_bart[0].get("summary_text", "Summary not available.")
|
93 |
+
# return summary
|
94 |
+
# except (IndexError, KeyError):
|
95 |
+
# return "Summary not available."
|
96 |
+
|
97 |
+
def store_in_supabase(resume_text, candidate_name, email, ): # removed score, summary
|
98 |
"""
|
99 |
Stores resume data in Supabase.
|
100 |
|
|
|
104 |
:param email: Candidate's email address.
|
105 |
:param summary: A summarized version of the resume.
|
106 |
"""
|
107 |
+
# if score is None:
|
108 |
+
# score = 0 # Ensure score is never NULL
|
109 |
|
110 |
data = {
|
111 |
"name": candidate_name,
|
112 |
"resume": resume_text,
|
113 |
+
#"score": score,
|
114 |
"email": email,
|
115 |
+
#"summary": summary
|
116 |
}
|
117 |
|
118 |
response = supabase.table("candidates").insert(data).execute()
|
119 |
return response
|
120 |
|
|
|
121 |
def generate_pdf_report(shortlisted_candidates):
|
122 |
"""Generates a PDF summary of shortlisted candidates."""
|
123 |
pdf = BytesIO()
|
|
|
126 |
for candidate in shortlisted_candidates:
|
127 |
page = doc.new_page()
|
128 |
|
129 |
+
# # Use the stored summary, or provide a fallback
|
130 |
+
# summary = candidate.get("summary", "No summary available")
|
131 |
|
132 |
page.insert_text(
|
133 |
(50, 50),
|
134 |
f"Candidate: {candidate['name']}\n"
|
135 |
f"Email: {candidate['email']}\n"
|
136 |
+
#f"Score: {candidate['score']}\n"
|
137 |
+
#f"Summary: {summary}"
|
138 |
)
|
139 |
|
140 |
doc.save(pdf)
|