Spaces:
Running
Running
Commit
·
c412b90
0
Parent(s):
Initial Commit
Browse files- .gitignore +4 -0
- LICENSE +201 -0
- README.md +51 -0
- app.py +47 -0
- components/candidate_data_schema.py +38 -0
- components/llm_model.py +3 -0
- components/llm_resume_parser.py +23 -0
- components/ui/education.py +65 -0
- components/ui/experience.py +78 -0
- components/ui/personal_data.py +20 -0
- components/ui/sidebar.py +31 -0
- components/ui/skills.py +54 -0
- components/utils.py +107 -0
- requirements.txt +11 -0
.gitignore
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.env
|
2 |
+
venv
|
3 |
+
__pycache__
|
4 |
+
data
|
LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Apache License
|
2 |
+
Version 2.0, January 2004
|
3 |
+
http://www.apache.org/licenses/
|
4 |
+
|
5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6 |
+
|
7 |
+
1. Definitions.
|
8 |
+
|
9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
11 |
+
|
12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13 |
+
the copyright owner that is granting the License.
|
14 |
+
|
15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
16 |
+
other entities that control, are controlled by, or are under common
|
17 |
+
control with that entity. For the purposes of this definition,
|
18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
19 |
+
direction or management of such entity, whether by contract or
|
20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22 |
+
|
23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24 |
+
exercising permissions granted by this License.
|
25 |
+
|
26 |
+
"Source" form shall mean the preferred form for making modifications,
|
27 |
+
including but not limited to software source code, documentation
|
28 |
+
source, and configuration files.
|
29 |
+
|
30 |
+
"Object" form shall mean any form resulting from mechanical
|
31 |
+
transformation or translation of a Source form, including but
|
32 |
+
not limited to compiled object code, generated documentation,
|
33 |
+
and conversions to other media types.
|
34 |
+
|
35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
36 |
+
Object form, made available under the License, as indicated by a
|
37 |
+
copyright notice that is included in or attached to the work
|
38 |
+
(an example is provided in the Appendix below).
|
39 |
+
|
40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41 |
+
form, that is based on (or derived from) the Work and for which the
|
42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
44 |
+
of this License, Derivative Works shall not include works that remain
|
45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46 |
+
the Work and Derivative Works thereof.
|
47 |
+
|
48 |
+
"Contribution" shall mean any work of authorship, including
|
49 |
+
the original version of the Work and any modifications or additions
|
50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
54 |
+
means any form of electronic, verbal, or written communication sent
|
55 |
+
to the Licensor or its representatives, including but not limited to
|
56 |
+
communication on electronic mailing lists, source code control systems,
|
57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
59 |
+
excluding communication that is conspicuously marked or otherwise
|
60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
61 |
+
|
62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
64 |
+
subsequently incorporated within the Work.
|
65 |
+
|
66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
71 |
+
Work and such Derivative Works in Source or Object form.
|
72 |
+
|
73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76 |
+
(except as stated in this section) patent license to make, have made,
|
77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78 |
+
where such license applies only to those patent claims licensable
|
79 |
+
by such Contributor that are necessarily infringed by their
|
80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
82 |
+
institute patent litigation against any entity (including a
|
83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84 |
+
or a Contribution incorporated within the Work constitutes direct
|
85 |
+
or contributory patent infringement, then any patent licenses
|
86 |
+
granted to You under this License for that Work shall terminate
|
87 |
+
as of the date such litigation is filed.
|
88 |
+
|
89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
90 |
+
Work or Derivative Works thereof in any medium, with or without
|
91 |
+
modifications, and in Source or Object form, provided that You
|
92 |
+
meet the following conditions:
|
93 |
+
|
94 |
+
(a) You must give any other recipients of the Work or
|
95 |
+
Derivative Works a copy of this License; and
|
96 |
+
|
97 |
+
(b) You must cause any modified files to carry prominent notices
|
98 |
+
stating that You changed the files; and
|
99 |
+
|
100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
101 |
+
that You distribute, all copyright, patent, trademark, and
|
102 |
+
attribution notices from the Source form of the Work,
|
103 |
+
excluding those notices that do not pertain to any part of
|
104 |
+
the Derivative Works; and
|
105 |
+
|
106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107 |
+
distribution, then any Derivative Works that You distribute must
|
108 |
+
include a readable copy of the attribution notices contained
|
109 |
+
within such NOTICE file, excluding those notices that do not
|
110 |
+
pertain to any part of the Derivative Works, in at least one
|
111 |
+
of the following places: within a NOTICE text file distributed
|
112 |
+
as part of the Derivative Works; within the Source form or
|
113 |
+
documentation, if provided along with the Derivative Works; or,
|
114 |
+
within a display generated by the Derivative Works, if and
|
115 |
+
wherever such third-party notices normally appear. The contents
|
116 |
+
of the NOTICE file are for informational purposes only and
|
117 |
+
do not modify the License. You may add Your own attribution
|
118 |
+
notices within Derivative Works that You distribute, alongside
|
119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
120 |
+
that such additional attribution notices cannot be construed
|
121 |
+
as modifying the License.
|
122 |
+
|
123 |
+
You may add Your own copyright statement to Your modifications and
|
124 |
+
may provide additional or different license terms and conditions
|
125 |
+
for use, reproduction, or distribution of Your modifications, or
|
126 |
+
for any such Derivative Works as a whole, provided Your use,
|
127 |
+
reproduction, and distribution of the Work otherwise complies with
|
128 |
+
the conditions stated in this License.
|
129 |
+
|
130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
132 |
+
by You to the Licensor shall be under the terms and conditions of
|
133 |
+
this License, without any additional terms or conditions.
|
134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135 |
+
the terms of any separate license agreement you may have executed
|
136 |
+
with Licensor regarding such Contributions.
|
137 |
+
|
138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
140 |
+
except as required for reasonable and customary use in describing the
|
141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
142 |
+
|
143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144 |
+
agreed to in writing, Licensor provides the Work (and each
|
145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147 |
+
implied, including, without limitation, any warranties or conditions
|
148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150 |
+
appropriateness of using or redistributing the Work and assume any
|
151 |
+
risks associated with Your exercise of permissions under this License.
|
152 |
+
|
153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
154 |
+
whether in tort (including negligence), contract, or otherwise,
|
155 |
+
unless required by applicable law (such as deliberate and grossly
|
156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157 |
+
liable to You for damages, including any direct, indirect, special,
|
158 |
+
incidental, or consequential damages of any character arising as a
|
159 |
+
result of this License or out of the use or inability to use the
|
160 |
+
Work (including but not limited to damages for loss of goodwill,
|
161 |
+
work stoppage, computer failure or malfunction, or any and all
|
162 |
+
other commercial damages or losses), even if such Contributor
|
163 |
+
has been advised of the possibility of such damages.
|
164 |
+
|
165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168 |
+
or other liability obligations and/or rights consistent with this
|
169 |
+
License. However, in accepting such obligations, You may act only
|
170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171 |
+
of any other Contributor, and only if You agree to indemnify,
|
172 |
+
defend, and hold each Contributor harmless for any liability
|
173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
174 |
+
of your accepting any such warranty or additional liability.
|
175 |
+
|
176 |
+
END OF TERMS AND CONDITIONS
|
177 |
+
|
178 |
+
APPENDIX: How to apply the Apache License to your work.
|
179 |
+
|
180 |
+
To apply the Apache License to your work, attach the following
|
181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182 |
+
replaced with your own identifying information. (Don't include
|
183 |
+
the brackets!) The text should be enclosed in the appropriate
|
184 |
+
comment syntax for the file format. We also recommend that a
|
185 |
+
file or class name and description of purpose be included on the
|
186 |
+
same "printed page" as the copyright notice for easier
|
187 |
+
identification within third-party archives.
|
188 |
+
|
189 |
+
Copyright [yyyy] [name of copyright owner]
|
190 |
+
|
191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192 |
+
you may not use this file except in compliance with the License.
|
193 |
+
You may obtain a copy of the License at
|
194 |
+
|
195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
196 |
+
|
197 |
+
Unless required by applicable law or agreed to in writing, software
|
198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200 |
+
See the License for the specific language governing permissions and
|
201 |
+
limitations under the License.
|
README.md
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: LLM Resume Parsing App
|
3 |
+
emoji: 🤗
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: green
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: "1.36.0"
|
8 |
+
app_file: app.py
|
9 |
+
pinned: true
|
10 |
+
---
|
11 |
+
|
12 |
+
# LLM Resume Parser APP
|
13 |
+
|
14 |
+
A job application form powered by a Large Language Model (LLM) Resume Parser using StreamLit, LangChain, Groq and LLAMA3.
|
15 |
+
|
16 |
+
|
17 |
+
This project combines `LangChain`, `StreamLit`, `Groq` and `LLAMA3`
|
18 |
+
|
19 |
+
|
20 |
+
## How it works:
|
21 |
+
|
22 |
+
Once applicant's upload their resume file (pdf or word), the resume text is extracted and sent to Groq API to LLAMA3 model. The model returned a `json blob` as prompted and this data is automatically entered into the application form where the user can edit it or add to it.
|
23 |
+
|
24 |
+
## Notes
|
25 |
+
|
26 |
+
I included a variable called `job_title` and assigned it the value "Data Scientist", this variable is used in page title and on top of the page, more importantly, it's used in the llm model prompt to help the model pick skills that are relevant to `job_title`. It possible to chang the job title or further more, include the full job description for evaluating and scoring resumes.<br>
|
27 |
+
|
28 |
+
I prefered to use an open source LLM as companies can host their own open source model and use it for resume parsing rather than having to rely on 3rd party providers which would help protect Applicants Data.
|
29 |
+
|
30 |
+
## Findings Throughout Development
|
31 |
+
|
32 |
+
One of the issues I encountered while testing was that the model would return a string date for dates like "December 2018" even when instructed to return a datetime string format. The reason, in addition to the imperfection of LLMs, is probably the long context as the model has to extract a lot of data and is doing it all in one call to the API. The problem was solved after I instructed the model to return day, month and year instead.<br>
|
33 |
+
|
34 |
+
It was and still possible to divide the data extracting process to multiple parallel calls which would make it easier for the model as it would have to extract less data in each call. It would probably take 3 to 4 parallel calls.
|
35 |
+
|
36 |
+
## Final Comment
|
37 |
+
|
38 |
+
Thank you for taking the time to explore my code and looking forward to hearing your opinions and comments on the project.<br>
|
39 |
+
|
40 |
+
**Please take a look at code and live demo on the links below:**<br>
|
41 |
+
|
42 |
+
**Live Demo** on `Hugghingface` `Spaces`:
|
43 |
+
|
44 |
+
https://huggingface.co/spaces/w-sliman/LLM_Resume_Parser_App
|
45 |
+
|
46 |
+
`Github` Repo:
|
47 |
+
|
48 |
+
https://github.com/w-sliman/LLM-Resume-Parsing-App
|
49 |
+
|
50 |
+
|
51 |
+
|
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
from dotenv import load_dotenv, find_dotenv
|
4 |
+
_ = load_dotenv(find_dotenv())
|
5 |
+
|
6 |
+
from components.ui.sidebar import sidebar_section
|
7 |
+
from components.ui.personal_data import personal_data_section
|
8 |
+
from components.ui.education import education_section
|
9 |
+
from components.ui.experience import experience_section
|
10 |
+
from components.ui.skills import skills_section
|
11 |
+
|
12 |
+
# This job_title variable will show up in the page title and will be used by LLM to determine relevant skills:
|
13 |
+
job_title= "Data Scientist"
|
14 |
+
|
15 |
+
# App configuration
|
16 |
+
st.set_page_config(page_title=f"Applying to {job_title} Vacancy", layout="wide")
|
17 |
+
|
18 |
+
st.title(f"Applying to {job_title} Vacancy", anchor="center")
|
19 |
+
|
20 |
+
st.write("### *This is a demo for resume parsing with Large Language Models.*")
|
21 |
+
st.write("Upload your resume on the left sidebar to automatically parse your data.")
|
22 |
+
st.write("*Warning: the contents of the file you upload will be sent to Groq-API for inference*")
|
23 |
+
|
24 |
+
# Sidebar
|
25 |
+
sidebar_section(job_title= job_title)
|
26 |
+
|
27 |
+
# Personal Data Section
|
28 |
+
personal_data_section()
|
29 |
+
|
30 |
+
# Education Section
|
31 |
+
education_section()
|
32 |
+
|
33 |
+
# Experience Section
|
34 |
+
experience_section()
|
35 |
+
|
36 |
+
# Skills Section
|
37 |
+
skills_section()
|
38 |
+
|
39 |
+
|
40 |
+
st.write("* Clicking the submit button below will only show you the final data dictionary after parsing the resume and performing manual edits on it.*")
|
41 |
+
submit = st.button('Submit', key="sumbit")
|
42 |
+
|
43 |
+
if submit:
|
44 |
+
st.divider()
|
45 |
+
st.write("### Final Candidate Data:")
|
46 |
+
st.write(st.session_state.candidate_data)
|
47 |
+
|
components/candidate_data_schema.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel, Field
|
2 |
+
from typing import List, Optional
|
3 |
+
|
4 |
+
class date(BaseModel):
|
5 |
+
"""Date"""
|
6 |
+
day: Optional[int] = Field(default=1, description="Day of month, a integer from 1 and 31, if unkown the default is 1")
|
7 |
+
month: Optional[int] = Field(description="Month of year, an integer from 1 to 12")
|
8 |
+
year: Optional[int] = Field(description="Year in yyyy format")
|
9 |
+
|
10 |
+
|
11 |
+
class job(BaseModel):
|
12 |
+
"""Job details"""
|
13 |
+
job_title: Optional[str] = Field(description="Job titile")
|
14 |
+
job_description: Optional[str] = Field(description="Information about the job and what did the candidate do in it if available.")
|
15 |
+
started_at: Optional[date] = Field(description="When did the candidate start this job? Retrun None if not available")
|
16 |
+
ended_at: Optional[date] = Field(description="When did the candidate end this job? Retrun None if not available")
|
17 |
+
current_job: Optional[bool] = Field(description="True if this the candidates current job, False if it's not the candidate's current job")
|
18 |
+
|
19 |
+
|
20 |
+
class degree(BaseModel):
|
21 |
+
"""degree details, which only includes Bachelor's, Master's or Phd degrees"""
|
22 |
+
degree_type: Optional[str] = Field(description="Degree type, which is Bachelor's, Master's or Phd")
|
23 |
+
major: Optional[str] = Field(description="Degree major")
|
24 |
+
university: Optional[str] = Field(description="Degree university")
|
25 |
+
graduation_date: Optional[date] = Field(description="When did the candidate graduate? Retrun None if not available")
|
26 |
+
|
27 |
+
|
28 |
+
class candidate(BaseModel):
|
29 |
+
"""personal information about the candidate"""
|
30 |
+
first_name: Optional[str] = Field(description="First name")
|
31 |
+
last_name: Optional[str] = Field(description="Last name")
|
32 |
+
country__phone_code: Optional[str] = Field(description="Country phone code, examples: +1 or +39")
|
33 |
+
phone_number: Optional[int] = Field(description="Phone number, without country phone code")
|
34 |
+
email: Optional[str] = Field(description="Email address")
|
35 |
+
country: Optional[str] = Field(description="country")
|
36 |
+
degrees: Optional[List[degree]] = Field(description="list of all candidate's degrees")
|
37 |
+
jobs: Optional[List[job]] = Field(description="Only include jobs the candidate listed in a work experience section. Return None if he hasn't listed any.")
|
38 |
+
skills: Optional[list[str]] = Field(description="list of candidate's skills that are relevant to the job")
|
components/llm_model.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from langchain_groq import ChatGroq
|
2 |
+
|
3 |
+
llm = ChatGroq(temperature=0, model_name="llama3-8b-8192", model_kwargs={"response_format": {"type": "json_object"}})
|
components/llm_resume_parser.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.output_parsers import PydanticOutputParser
|
2 |
+
from langchain_core.prompts import PromptTemplate
|
3 |
+
|
4 |
+
from components.candidate_data_schema import candidate
|
5 |
+
from components.llm_model import llm
|
6 |
+
|
7 |
+
parser = PydanticOutputParser(pydantic_object=candidate)
|
8 |
+
|
9 |
+
prompt_template = """\
|
10 |
+
You are tasked with extracting data from resume for a {job_title} job and retruning a JSON structre.\n
|
11 |
+
{format_instructions}\n
|
12 |
+
|
13 |
+
Resume text: {resume_text}
|
14 |
+
"""
|
15 |
+
|
16 |
+
prompt = PromptTemplate(
|
17 |
+
template=prompt_template,
|
18 |
+
input_variables=["job_title", "resume_text"],
|
19 |
+
partial_variables={"format_instructions": parser.get_format_instructions()},
|
20 |
+
)
|
21 |
+
|
22 |
+
llm_resume_parser = prompt | llm | parser
|
23 |
+
|
components/ui/education.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
def education_section():
|
4 |
+
|
5 |
+
st.write("## Education")
|
6 |
+
|
7 |
+
with st.container(border= True):
|
8 |
+
if st.session_state.candidate_data.get("degrees"):
|
9 |
+
for i, item in enumerate(st.session_state.candidate_data["degrees"]):
|
10 |
+
|
11 |
+
st.markdown("#### Education " + str(i + 1))
|
12 |
+
|
13 |
+
col1, col2 = st.columns(2)
|
14 |
+
degree_type = col1.text_input("**Degree Type**", key="degree_type" + str(i), value=item.get("degree_type", ""))
|
15 |
+
major = col2.text_input("**Major**", key="major" + str(i), value=item.get("major", ""))
|
16 |
+
|
17 |
+
col1, col2 = st.columns(2)
|
18 |
+
university = col1.text_input("**University**", key="university" + str(i), value=item.get("university", ""))
|
19 |
+
graduation_date = col2.date_input("**Graduation Date**", key="graduation_date" + str(i), value=item.get("graduation_date", ""))
|
20 |
+
|
21 |
+
st.session_state.candidate_data["degrees"][i] = {
|
22 |
+
"degree_type": degree_type,
|
23 |
+
"major": major,
|
24 |
+
"university": university,
|
25 |
+
"graduation_date": graduation_date
|
26 |
+
}
|
27 |
+
|
28 |
+
if st.button(f"Remove Education {i + 1}", key=f"remove_education_{i}"):
|
29 |
+
st.session_state.candidate_data["degrees"].pop(i)
|
30 |
+
st.rerun()
|
31 |
+
|
32 |
+
if "new_education" not in st.session_state:
|
33 |
+
st.session_state.new_education = {}
|
34 |
+
|
35 |
+
if "new_education_clicked" not in st.session_state:
|
36 |
+
st.session_state.new_education_clicked = False
|
37 |
+
|
38 |
+
if st.session_state.new_education_clicked:
|
39 |
+
|
40 |
+
st.write("#### New Education")
|
41 |
+
|
42 |
+
col1, col2 = st.columns(2)
|
43 |
+
st.session_state.new_education["degree_type"] = col1.text_input("**Degree Type**", key="degree_type", value= st.session_state.new_education.get("degree_type",""))
|
44 |
+
st.session_state.new_education["major"] = col2.text_input("**Major**", key="major", value= st.session_state.new_education.get("major",""))
|
45 |
+
|
46 |
+
col1, col2 = st.columns(2)
|
47 |
+
st.session_state.new_education["university"] = col1.text_input("**University**", key="university", value= st.session_state.new_education.get("university",""))
|
48 |
+
st.session_state.new_education["graduation_date"] = col2.date_input("**Graduation Date**", key="graduation_date", value= st.session_state.new_education.get("graduation_date",None))
|
49 |
+
|
50 |
+
|
51 |
+
new_education_button = st.button("Add New Education" if not st.session_state.new_education_clicked else "Save")
|
52 |
+
|
53 |
+
if new_education_button:
|
54 |
+
if st.session_state.new_education_clicked:
|
55 |
+
if "degrees" not in st.session_state.candidate_data:
|
56 |
+
st.session_state.candidate_data["degrees"] = []
|
57 |
+
|
58 |
+
st.session_state.candidate_data["degrees"].append(st.session_state.new_education.copy())
|
59 |
+
st.session_state.new_education = {}
|
60 |
+
st.session_state.new_education_clicked = False
|
61 |
+
|
62 |
+
else:
|
63 |
+
st.session_state.new_education_clicked = True
|
64 |
+
|
65 |
+
st.rerun()
|
components/ui/experience.py
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
def experience_section():
|
4 |
+
|
5 |
+
st.write("## Experience")
|
6 |
+
|
7 |
+
with st.container(border= True):
|
8 |
+
if st.session_state.candidate_data.get("jobs"):
|
9 |
+
for i, item in enumerate(st.session_state.candidate_data["jobs"]):
|
10 |
+
|
11 |
+
col1, col2 = st.columns(2)
|
12 |
+
col1.markdown("##### Work Experience " + str(i + 1))
|
13 |
+
|
14 |
+
|
15 |
+
current_job = col2.checkbox("**Current Job**", key="current_job" + str(i), value=item.get("current_job", False))
|
16 |
+
|
17 |
+
col1, col2 = st.columns(2)
|
18 |
+
started_at = col1.date_input("**From**", key="started_at" + str(i), value=item.get("started_at", None))
|
19 |
+
|
20 |
+
|
21 |
+
if not st.session_state["current_job" + str(i)]:
|
22 |
+
ended_at = col2.date_input("**To**", key="ended_at" + str(i), value=item.get("ended_at", None))
|
23 |
+
else:
|
24 |
+
ended_at = None
|
25 |
+
|
26 |
+
col1, col2 = st.columns(2)
|
27 |
+
job_title = col1.text_input("**Job Title**", key="job_title" + str(i), value=item.get("job_title", ""))
|
28 |
+
description = col2.text_area("**Job Description**", key="description" + str(i), value=item.get("job_description", ""))
|
29 |
+
|
30 |
+
#col1, col2 = st.columns(2)
|
31 |
+
remove_experience_button = st.button(f"Remove Experience {i + 1}", key=f"remove_experience_{i}")
|
32 |
+
|
33 |
+
st.session_state.candidate_data["jobs"][i] = {
|
34 |
+
"job_title": job_title,
|
35 |
+
"job_description": description,
|
36 |
+
"started_at": started_at,
|
37 |
+
"ended_at": ended_at,
|
38 |
+
"current_job": current_job
|
39 |
+
}
|
40 |
+
|
41 |
+
if remove_experience_button:
|
42 |
+
st.session_state.candidate_data["jobs"].pop(i)
|
43 |
+
st.rerun()
|
44 |
+
|
45 |
+
if "new_experience" not in st.session_state:
|
46 |
+
st.session_state.new_experience = {}
|
47 |
+
|
48 |
+
if "new_experience_clicked" not in st.session_state:
|
49 |
+
st.session_state.new_experience_clicked = False
|
50 |
+
|
51 |
+
if st.session_state.new_experience_clicked:
|
52 |
+
|
53 |
+
st.write("#### Update New Experience")
|
54 |
+
|
55 |
+
col1, col2 = st.columns(2)
|
56 |
+
st.session_state.new_experience["started_at"] = col1.date_input("**From**", key="from", value= st.session_state.new_experience.get("started_at",None))
|
57 |
+
st.session_state.new_experience["ended_at"] = col2.date_input("**To**", key="to", value= st.session_state.new_experience.get("ended_at",None))
|
58 |
+
|
59 |
+
col1, col2 = st.columns(2)
|
60 |
+
st.session_state.new_experience["job_title"] = col1.text_input("**Job Title**", key="job_title", value= st.session_state.new_experience.get("job_title",""))
|
61 |
+
st.session_state.new_experience["job_description"] = col2.text_area("**Job Description**", key="job_description", value= st.session_state.new_experience.get("job_description",""))
|
62 |
+
|
63 |
+
|
64 |
+
new_experience_button = st.button("Add New Experience" if not st.session_state.new_experience_clicked else "Save")
|
65 |
+
|
66 |
+
if new_experience_button:
|
67 |
+
if st.session_state.new_experience_clicked:
|
68 |
+
if "jobs" not in st.session_state.candidate_data:
|
69 |
+
st.session_state.candidate_data["jobs"] = []
|
70 |
+
|
71 |
+
st.session_state.candidate_data["jobs"].append(st.session_state.new_experience.copy())
|
72 |
+
st.session_state.new_experience = {}
|
73 |
+
st.session_state.new_experience_clicked = False
|
74 |
+
|
75 |
+
else:
|
76 |
+
st.session_state.new_experience_clicked = True
|
77 |
+
|
78 |
+
st.rerun()
|
components/ui/personal_data.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from components.utils import is_valid_email
|
3 |
+
|
4 |
+
def personal_data_section():
|
5 |
+
|
6 |
+
st.write("## Personal Data")
|
7 |
+
|
8 |
+
with st.container(border= True):
|
9 |
+
|
10 |
+
col1, col2 = st.columns(2)
|
11 |
+
st.session_state.candidate_data["first_name"] = col1.text_input("**First Name**", st.session_state.candidate_data.get("first_name", ""))
|
12 |
+
st.session_state.candidate_data["last_name"] = col2.text_input("**Last Name**", st.session_state.candidate_data.get("last_name", ""))
|
13 |
+
|
14 |
+
col1, col2 = st.columns(2)
|
15 |
+
st.session_state.candidate_data["country_phone_code"] = col1.text_input("**Country Code**", st.session_state.candidate_data.get("country_phone_code", ""))
|
16 |
+
st.session_state.candidate_data["phone_number"] = col2.text_input("**Phone Number**", st.session_state.candidate_data.get("phone_number", ""))
|
17 |
+
|
18 |
+
col1, col2 = st.columns(2)
|
19 |
+
st.session_state.candidate_data["email"] = st.text_input("**Email**", st.session_state.candidate_data.get("email", ""))
|
20 |
+
st.session_state.candidate_data["country"] = st.text_input("**Country**", st.session_state.candidate_data.get("country", ""))
|
components/ui/sidebar.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from components.utils import extract_resume_text, convert_dates_to_datetime, is_valid_email
|
3 |
+
from components.llm_resume_parser import llm_resume_parser
|
4 |
+
from components.utils import read_pdf_text
|
5 |
+
|
6 |
+
|
7 |
+
resumes_for_testing = {"resume1": "./resumes_for_testing/resume1.pdf",
|
8 |
+
"resume2": "./resumes_for_testing/resume2.pdf",
|
9 |
+
"resume3": "./resumes_for_testing/resume3.pdf"}
|
10 |
+
|
11 |
+
def sidebar_section(job_title):
|
12 |
+
|
13 |
+
with st.sidebar:
|
14 |
+
|
15 |
+
resume_file = st.file_uploader("**Upload Your Resume (PDF, Word)**", type=["pdf","docx"])
|
16 |
+
|
17 |
+
|
18 |
+
if 'candidate_data' not in st.session_state:
|
19 |
+
st.session_state.candidate_data = {}
|
20 |
+
|
21 |
+
if resume_file:
|
22 |
+
resume_text = extract_resume_text(resume_file)
|
23 |
+
|
24 |
+
parsed_candidate_data = llm_resume_parser.invoke({"job_title": job_title, "resume_text":resume_text})
|
25 |
+
|
26 |
+
if "parsed_candidate_data" not in st.session_state:
|
27 |
+
st.session_state.parsed_candidate_data = parsed_candidate_data
|
28 |
+
st.session_state.candidate_data = convert_dates_to_datetime(parsed_candidate_data)
|
29 |
+
|
30 |
+
if ("email" in st.session_state.candidate_data) and not is_valid_email(st.session_state.candidate_data["email"]):
|
31 |
+
st.session_state.candidate_data["email"] = ""
|
components/ui/skills.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
def skills_section():
|
4 |
+
|
5 |
+
st.write("## Skills")
|
6 |
+
|
7 |
+
def onchange_skill_checkbox(skill_id):
|
8 |
+
|
9 |
+
if st.session_state[skill_id]:
|
10 |
+
return
|
11 |
+
|
12 |
+
skill_to_remove = skill_id.split("_")[0]
|
13 |
+
st.session_state.candidate_data["skills"] = [skill for skill in st.session_state.candidate_data["skills"] if skill != skill_to_remove]
|
14 |
+
|
15 |
+
|
16 |
+
def add_new_skill():
|
17 |
+
|
18 |
+
if st.session_state.new_skill_input == '':
|
19 |
+
return
|
20 |
+
|
21 |
+
new_skill = st.session_state.new_skill_input.strip().lower()
|
22 |
+
|
23 |
+
if "skills" not in st.session_state.candidate_data:
|
24 |
+
st.session_state.candidate_data["skills"] = []
|
25 |
+
|
26 |
+
skills = [skill.lower() for skill in st.session_state.candidate_data["skills"]]
|
27 |
+
|
28 |
+
if new_skill not in skills:
|
29 |
+
st.session_state.candidate_data["skills"].append(new_skill.capitalize())
|
30 |
+
|
31 |
+
st.session_state.new_skill_input = ''
|
32 |
+
|
33 |
+
|
34 |
+
with st.container(border= True):
|
35 |
+
|
36 |
+
#skills = st.session_state.skills
|
37 |
+
|
38 |
+
col1, col2, col3, col4 = st.columns(4)
|
39 |
+
if "skills" in st.session_state.candidate_data:
|
40 |
+
for i, skill in enumerate(st.session_state.candidate_data["skills"]):
|
41 |
+
skill_id = f"{skill}_{i}"
|
42 |
+
if i % 4 == 0:
|
43 |
+
col1.checkbox(skill, key=skill_id, value=True, on_change=onchange_skill_checkbox, args=(skill_id,))
|
44 |
+
elif i % 4 == 1:
|
45 |
+
col2.checkbox(skill, key=skill_id, value=True, on_change=onchange_skill_checkbox, args=(skill_id,))
|
46 |
+
elif i % 4 == 2:
|
47 |
+
col3.checkbox(skill, key=skill_id, value=True, on_change=onchange_skill_checkbox, args=(skill_id,))
|
48 |
+
elif i % 4 == 3:
|
49 |
+
col4.checkbox(skill, key=skill_id, value=True, on_change=onchange_skill_checkbox, args=(skill_id,))
|
50 |
+
|
51 |
+
st.write("#### Add Skill")
|
52 |
+
col1, col2 = st.columns(2)
|
53 |
+
new_skill_input = col1.text_input("Add a new skill", label_visibility="collapsed", key="new_skill_input", on_change=add_new_skill)
|
54 |
+
add_skill_button = col2.button("Add Skill", on_click=add_new_skill)
|
components/utils.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import PyPDF2
|
2 |
+
import docx
|
3 |
+
import io
|
4 |
+
import datetime
|
5 |
+
from components.candidate_data_schema import candidate
|
6 |
+
import re
|
7 |
+
|
8 |
+
def read_pdf_text(resume_file):
|
9 |
+
"""
|
10 |
+
Extracts text from a PDF file.
|
11 |
+
|
12 |
+
Args:
|
13 |
+
resume_file (file-like object): The PDF file to be read.
|
14 |
+
|
15 |
+
Returns:
|
16 |
+
str: The extracted text from the PDF.
|
17 |
+
"""
|
18 |
+
pdf_reader = PyPDF2.PdfReader(io.BytesIO(resume_file.read()))
|
19 |
+
text = ""
|
20 |
+
for page_num in range(len(pdf_reader.pages)):
|
21 |
+
page = pdf_reader.pages[page_num]
|
22 |
+
text += page.extract_text().strip()
|
23 |
+
return text
|
24 |
+
|
25 |
+
|
26 |
+
def read_docx_text(word_file):
|
27 |
+
"""
|
28 |
+
Extracts text from a DOCX file.
|
29 |
+
|
30 |
+
Args:
|
31 |
+
word_file (file-like object): The DOCX file to be read.
|
32 |
+
|
33 |
+
Returns:
|
34 |
+
str: The extracted text from the DOCX file.
|
35 |
+
"""
|
36 |
+
doc = docx.Document(io.BytesIO(word_file.read()))
|
37 |
+
text = ""
|
38 |
+
for paragraph in doc.paragraphs:
|
39 |
+
text += paragraph.text.strip() + "\n"
|
40 |
+
return text
|
41 |
+
|
42 |
+
|
43 |
+
def extract_resume_text(resume_file):
|
44 |
+
"""
|
45 |
+
Extracts text from a resume file, either PDF or DOCX.
|
46 |
+
|
47 |
+
Args:
|
48 |
+
resume_file (file-like object): The resume file to be read.
|
49 |
+
|
50 |
+
Returns:
|
51 |
+
str: The extracted text from the resume file.
|
52 |
+
"""
|
53 |
+
file_type = resume_file.name.split(".")[-1]
|
54 |
+
if file_type == "pdf":
|
55 |
+
return read_pdf_text(resume_file)
|
56 |
+
elif file_type == "docx":
|
57 |
+
return read_docx_text(resume_file)
|
58 |
+
|
59 |
+
|
60 |
+
def date_to_datetime(input):
|
61 |
+
"""
|
62 |
+
Converts a dictionary representing a date to a datetime.date object.
|
63 |
+
|
64 |
+
Args:
|
65 |
+
input (dict): Dictionary with keys 'year', 'month', 'day'.
|
66 |
+
|
67 |
+
Returns:
|
68 |
+
datetime.date or None: The corresponding datetime.date object or None if input is invalid.
|
69 |
+
"""
|
70 |
+
for _, value in input.items():
|
71 |
+
if value is None:
|
72 |
+
return None
|
73 |
+
|
74 |
+
return datetime.date(**input)
|
75 |
+
|
76 |
+
|
77 |
+
def convert_dates_to_datetime(candidate_data: candidate):
|
78 |
+
"""
|
79 |
+
Returns the model_dump() dictionary of a "candidate" pydantic class after converting dates to datetime.date objects.
|
80 |
+
|
81 |
+
Args:
|
82 |
+
candidate_data (candidate): The candidate object containing date fields.
|
83 |
+
|
84 |
+
Returns:
|
85 |
+
dict: The candidate model_dump dictionary with date fields converted to datetime.date objects.
|
86 |
+
"""
|
87 |
+
candidate_dict = candidate_data.model_dump()
|
88 |
+
|
89 |
+
if "degrees" in candidate_dict.keys():
|
90 |
+
for degree in candidate_dict["degrees"]:
|
91 |
+
if degree["graduation_date"]:
|
92 |
+
degree["graduation_date"] = date_to_datetime(degree["graduation_date"])
|
93 |
+
|
94 |
+
if "jobs" in candidate_dict.keys():
|
95 |
+
for job in candidate_dict["jobs"]:
|
96 |
+
if job["started_at"]:
|
97 |
+
job["started_at"] = date_to_datetime(job["started_at"])
|
98 |
+
if job["ended_at"]:
|
99 |
+
job["ended_at"] = date_to_datetime(job["ended_at"])
|
100 |
+
|
101 |
+
return candidate_dict
|
102 |
+
|
103 |
+
|
104 |
+
def is_valid_email(email):
|
105 |
+
|
106 |
+
pattern = r'^[\w\.-]+@[\w\.-]+\.\w+$'
|
107 |
+
return re.match(pattern, email) is not None
|
requirements.txt
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Python Version 3.9.0
|
2 |
+
|
3 |
+
langchain==0.2.10
|
4 |
+
langchain_core==0.2.22
|
5 |
+
langchain_groq==0.1.6
|
6 |
+
pydantic==2.8.2
|
7 |
+
email_validator==2.2.0
|
8 |
+
PyPDF2==3.0.1
|
9 |
+
python-dotenv==1.0.1
|
10 |
+
python_docx==1.1.2
|
11 |
+
streamlit==1.36.0
|