chrisandrei commited on
Commit
f1a246e
·
verified ·
1 Parent(s): 59b46e8

Update resume_screener.py

Browse files
Files changed (1) hide show
  1. resume_screener.py +126 -72
resume_screener.py CHANGED
@@ -1,72 +1,126 @@
1
- import streamlit as st
2
-
3
- #importing the pages
4
- from resume_screener import ResumeScreener
5
- from user_documentation import UserDocumentation
6
- from home import Home
7
-
8
- UserDocPage = st.Page(UserDocumentation, title="User Documentation", icon=":material/help:")
9
- ResumeScreenerPage = st.Page(ResumeScreener, title="Resume Screener", icon=":material/recent_actors:")
10
- HomePage = st.Page(Home, title="Home", icon=":material/home:")
11
-
12
-
13
- if "LOGGED_IN" not in st.session_state:
14
- st.session_state.LOGGED_IN = False
15
-
16
- if st.session_state.LOGGED_IN:
17
- pages = {
18
- "Dashboard": [
19
- HomePage,
20
- ResumeScreenerPage,
21
- ],
22
- "Resources": [
23
- UserDocPage,
24
- ]
25
- }
26
-
27
- pg = st.navigation(pages)
28
- pg.run()
29
-
30
- else:
31
- col1, col2, col3 = st.columns(spec=[1, 3, 1])
32
-
33
- with col2:
34
- st.title("Login")
35
- username = st.text_input("Email Address", value="johndoe@hr.company.com")
36
- password = st.text_input("Password", type="password")
37
-
38
- if st.button("Login"):
39
-
40
- class UnregisteredUser(Exception):
41
- """
42
- Represents an exception when the user is not registered.
43
- """
44
-
45
- def __init__(self, message="User not registered"):
46
- self.message = message
47
- super().__init__(self.message)
48
-
49
- class IncompleteDetails(Exception):
50
- """
51
- Represents an exception when the user's details are incomplete.
52
- """
53
-
54
- def __init__(self, message="Incomplete details"):
55
- self.message = message
56
- super().__init__(self.message)
57
-
58
- #imaginary db calls for existing user, if user is in imaginary db, user is logged in
59
- try:
60
- if username == "johndoe@hr.company.com" and password == "password":
61
- st.session_state.LOGGED_IN = True
62
- st.rerun()
63
-
64
- if username == "" or password == "":
65
- raise IncompleteDetails
66
-
67
- raise UnregisteredUser
68
-
69
- except UnregisteredUser as e:
70
- st.error(e)
71
- except IncompleteDetails as e:
72
- st.error(e)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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}")