Spaces:
Sleeping
Sleeping
Update resume_screener.py
Browse files- resume_screener.py +126 -72
resume_screener.py
CHANGED
|
@@ -1,72 +1,126 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
#
|
| 4 |
-
from
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from helpers import *
|
| 2 |
+
|
| 3 |
+
# uuid generator
|
| 4 |
+
from uuid import uuid4
|
| 5 |
+
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
def ResumeScreener():
|
| 9 |
+
|
| 10 |
+
class EmptyText(Exception):
|
| 11 |
+
"""
|
| 12 |
+
A custom exception for when an input component
|
| 13 |
+
like st.text_area is empty.
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
def __init__(self, message = 'Text area cannot be empty'):
|
| 17 |
+
self.message = message
|
| 18 |
+
super().__init__(self.message)
|
| 19 |
+
|
| 20 |
+
st.set_page_config(
|
| 21 |
+
page_title="Screening Tool",
|
| 22 |
+
page_icon="🔎",
|
| 23 |
+
layout="wide",
|
| 24 |
+
initial_sidebar_state="auto"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
try:
|
| 28 |
+
# raises an error if keys are missing
|
| 29 |
+
check_missing_keys()
|
| 30 |
+
|
| 31 |
+
# Initialize the vector store -> the pinecone vector store
|
| 32 |
+
vector_store = pinecone_vector_store(
|
| 33 |
+
embedding="text-embedding-3-small",
|
| 34 |
+
index='resumedb'
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# File Uploader component -> list of Documents()
|
| 38 |
+
documents = file_uploader()
|
| 39 |
+
|
| 40 |
+
# 'Upload the documents' button to the vector store
|
| 41 |
+
upload_button(
|
| 42 |
+
documents=documents,
|
| 43 |
+
vector_store=vector_store
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
col1, col2 = st.columns(
|
| 47 |
+
spec=[2, 3],
|
| 48 |
+
gap="medium"
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
# Job Description text area
|
| 53 |
+
with col1:
|
| 54 |
+
|
| 55 |
+
# Dynamic text area height
|
| 56 |
+
st.markdown("""
|
| 57 |
+
<style>
|
| 58 |
+
textarea {
|
| 59 |
+
height: calc(100vh - 350px) !important; /* Adjust based on screen height */
|
| 60 |
+
min-height: 200px; /* Optional: Set a minimum height */
|
| 61 |
+
}
|
| 62 |
+
</style>
|
| 63 |
+
""", unsafe_allow_html=True)
|
| 64 |
+
|
| 65 |
+
txt = st.text_area(
|
| 66 |
+
"Describe the job description to match.",
|
| 67 |
+
placeholder = "Position: Data Scientist ...",
|
| 68 |
+
height = 600,
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
# Documents to retrieve
|
| 72 |
+
docs_num = st.number_input(
|
| 73 |
+
label="Number of resumes to retrieve",
|
| 74 |
+
step=1,
|
| 75 |
+
min_value=1,
|
| 76 |
+
max_value=100,
|
| 77 |
+
value=10
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
if 'DISPLAY_RESULTS' not in st.session_state:
|
| 81 |
+
st.session_state.DISPLAY_RESULTS = False
|
| 82 |
+
|
| 83 |
+
# Match resumes button
|
| 84 |
+
if st.button(
|
| 85 |
+
label= 'Match resumes',
|
| 86 |
+
disabled = st.session_state.KEYS_ARE_MISSING,
|
| 87 |
+
use_container_width = True,
|
| 88 |
+
type = 'primary'
|
| 89 |
+
):
|
| 90 |
+
|
| 91 |
+
st.session_state.DISPLAY_RESULTS = True
|
| 92 |
+
|
| 93 |
+
# Display the results here
|
| 94 |
+
with col2:
|
| 95 |
+
if st.session_state.DISPLAY_RESULTS:
|
| 96 |
+
|
| 97 |
+
# Dynamic UI height
|
| 98 |
+
st.markdown("""
|
| 99 |
+
<style>
|
| 100 |
+
textarea {
|
| 101 |
+
height: calc(100vh - 350px) !important; /* Adjust based on screen height */
|
| 102 |
+
min-height: 200px; /* Optional: Set a minimum height */
|
| 103 |
+
}
|
| 104 |
+
</style>
|
| 105 |
+
""", unsafe_allow_html=True)
|
| 106 |
+
with st.container(
|
| 107 |
+
height=600,
|
| 108 |
+
border=False
|
| 109 |
+
):
|
| 110 |
+
|
| 111 |
+
# The LLM chain for summarization
|
| 112 |
+
if 'SUMMARIZATION_CHAIN' not in st.session_state:
|
| 113 |
+
st.session_state.SUMMARIZATION_CHAIN = summarize_chain()
|
| 114 |
+
|
| 115 |
+
# The results component
|
| 116 |
+
match_resumes(
|
| 117 |
+
job_description=txt,
|
| 118 |
+
k=docs_num,
|
| 119 |
+
vector_store=vector_store,
|
| 120 |
+
summarization_chain=st.session_state.SUMMARIZATION_CHAIN
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
st.session_state.DISPLAY_RESULTS = False
|
| 124 |
+
|
| 125 |
+
except Exception as e:
|
| 126 |
+
st.error(f"An error in function ResumeScreener has occurred: {e}")
|