-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
150 lines (119 loc) · 4.14 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import streamlit as st
import os
import openai
from dotenv import load_dotenv
from llama_index.core.llama_pack import download_llama_pack
load_dotenv()
openai.api_key = os.environ["OPENAI_API_KEY"]
pack_folder = "./resume_screener_pack"
ResumeScreenerPack = download_llama_pack("ResumeScreenerPack", pack_folder)
# if not os.path.exists(pack_folder):
# ResumeScreenerPack = download_llama_pack("ResumeScreenerPack", pack_folder)
# else:
# from resume_screener_pack.llama_index.packs.resume_screener import (
# ResumeScreenerPack,
# )
def fact_check_resume(resume_content, criteria_decisions):
fact_check_prompt = f"""
Givent the following resume content and criteria decisions, please fact-check the claims made in the resume:
Resume Content:
{resume_content}
Criteria Decision:
{criteria_decisions}
Please list any potential discrepancies or areas that may need verification:
"""
response = openai.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "system",
"content": "You are a helpful assistant for fact-checking resumes.",
},
{"role": "user", "content": fact_check_prompt},
],
)
return response.choices[0].message.content
def rate_resume(criteria_decisions, overall_decision):
rate_prompt = f"""
Given the criteria decisions and overall decision, please rate the resume from 1 (lowest) to 10 (highest):
Criteria Decisions:
{criteria_decisions}
Overall Decision:
{overall_decision}
Please provide a numerical rating and a brief explanation for your rating:
"""
response = openai.chat.completions.create(
model="gpt-4",
messages=[
{
"role": "system",
"content": "You are a helpful assistant for rating resumes.",
},
{"role": "user", "content": rate_prompt},
],
)
return response.choices[0].message.content
st.title("ResuMate")
uploaded_file = st.file_uploader("Upload the Resume File", type=["pdf"])
col1, col2 = st.columns(2)
with col1:
job_description = st.text_area("Job Description", "")
with col2:
criteria = st.text_area("Selection Criteria (One per line)", "")
if (
st.button("Screen Resume")
and uploaded_file is not None
and job_description
and criteria
):
with open("temp_resume.pdf", "wb") as f:
f.write(uploaded_file.getbuffer())
criteria_list = [c.strip() for c in criteria.split("\n") if c.strip()]
resume_screener = ResumeScreenerPack(
job_description=job_description,
criteria=criteria_list,
)
response = resume_screener.run(resume_path="temp_resume.pdf")
st.subheader("Screening Results")
decisions = [
{
"title": f"Criteria Decision {i+1}",
"reasoning": cd.reasoning,
"decision": cd.decision,
}
for i, cd in enumerate(response.criteria_decisions)
]
decisions.append(
{
"title": "Overall Decision",
"reasoning": response.overall_reasoning,
"decision": response.overall_decision,
}
)
decision_summary = []
for decision in decisions:
st.markdown(f"#### {decision['title']}")
st.write(decision["reasoning"])
st.write(f"Decision: {decision['decision']}")
decision_summary.extend(
[
decision["title"],
decision["reasoning"],
f"Decision: {decision['decision']}",
"",
]
)
decision_summary = "\n".join(decision_summary).strip()
st.subheader("Fact-Checking Results")
fact_check_results = fact_check_resume(
decision_summary, response.criteria_decisions
)
st.markdown(fact_check_results)
st.subheader("Resume Rating")
rating_results = rate_resume(response.criteria_decisions, response.overall_decision)
st.markdown(rating_results)
os.remove("temp_resume.pdf")
else:
st.info(
"Please upload a resume file, enter job description and criteria, then click 'Screen Resume'."
)