|
import streamlit as st |
|
import subprocess |
|
from langchain.document_loaders import PyPDFLoader, Docx2txtLoader |
|
import google.generativeai as gen_ai |
|
import tempfile |
|
import os |
|
from dotenv import load_dotenv |
|
import pdfplumber |
|
import time |
|
|
|
|
|
|
|
|
|
|
|
@st.cache_data |
|
def extract_text_from_pdf(uploaded_file): |
|
st.write(f"Extracting text from {uploaded_file.name}...") |
|
with tempfile.NamedTemporaryFile(delete=False, prefix=uploaded_file.name, dir=os.path.dirname(uploaded_file.name)) as temp_file: |
|
temp_file.write(uploaded_file.read()) |
|
|
|
pdf_file_path = temp_file.name |
|
|
|
text = [] |
|
loader = PyPDFLoader(pdf_file_path) |
|
documents = loader.load() |
|
text.extend(documents) |
|
|
|
os.remove(pdf_file_path) |
|
|
|
return text |
|
|
|
|
|
def extract_information(data): |
|
gen_ai.configure(api_key=os.getenv('GEMINI')) |
|
safety_settings = [ |
|
{ |
|
"category": "HARM_CATEGORY_DANGEROUS", |
|
"threshold": "BLOCK_NONE", |
|
}, |
|
{ |
|
"category": "HARM_CATEGORY_HARASSMENT", |
|
"threshold": "BLOCK_NONE", |
|
}, |
|
{ |
|
"category": "HARM_CATEGORY_HATE_SPEECH", |
|
"threshold": "BLOCK_NONE", |
|
}, |
|
{ |
|
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", |
|
"threshold": "BLOCK_NONE", |
|
}, |
|
{ |
|
"category": "HARM_CATEGORY_DANGEROUS_CONTENT", |
|
"threshold": "BLOCK_NONE", |
|
}, |
|
] |
|
|
|
|
|
model = gen_ai.GenerativeModel('gemini-pro',safety_settings=safety_settings) |
|
response = model.generate_content(data) |
|
return response.text.strip() |
|
|
|
|
|
def read_pdf(pdf_name, file): |
|
with pdfplumber.open(file) as pdf: |
|
for i, page in enumerate(pdf.pages): |
|
|
|
image = page.to_image(resolution=600) |
|
st.image(image._repr_png_(), caption=f"Page {i+1}", use_column_width=True) |
|
|
|
|
|
def main(): |
|
|
|
st.markdown( |
|
"<h1 style='color: orange;'>CareerSync: Harmonizing Resumes with Job Descriptions</h1>", |
|
unsafe_allow_html=True |
|
) |
|
st.header("Welcome to CareerSync!") |
|
st.write("This app helps you compare a resume with a job description to find the best fit.") |
|
|
|
|
|
st.subheader("Step 1: Enter Job Description") |
|
job_description = st.text_area("Paste or type the job description here", height=200) |
|
|
|
|
|
st.subheader("Step 2: Upload Resume") |
|
resume_file = st.file_uploader("Upload your resume (PDF only)", type=['pdf']) |
|
|
|
|
|
if st.button("Compare Resumes"): |
|
if job_description and resume_file is not None: |
|
resume_content = extract_text_from_pdf(resume_file) |
|
enhanced_job_description = f"Enhanced Job Description:\n{job_description}" |
|
enhanced_job_description = extract_information(enhanced_job_description) |
|
|
|
|
|
|
|
with st.expander("Candidate Resume:"): |
|
|
|
pdf_name = resume_file.name |
|
read_pdf(pdf_name, resume_file) |
|
|
|
with st.expander("Enhanced Job Description:"): |
|
st.write(enhanced_job_description) |
|
|
|
|
|
prompt_template = f"Is the candidate a good fit? Return a Python list. The first index should be either 'pass' or 'fail', and the second index should have a score from 1 to 10.\n\nHere is the content of the resume:\n{resume_content}\n\nAnd here is the enhanced description of the job:\n{enhanced_job_description}" |
|
|
|
|
|
result = extract_information(prompt_template) |
|
st.subheader("Evaluation Result:") |
|
st.write(result) |
|
lst = eval(result) |
|
|
|
|
|
st.subheader("Evaluation Details:") |
|
st.write(f"Evaluation: {lst[0]}") |
|
st.write(f"Score: {lst[1]}") |
|
|
|
|
|
point = lst[1] |
|
if int(point) >= 7: |
|
st.success("Congratulations! The candidate is a good fit.") |
|
time.sleep(3) |
|
st.switch_page("pages/hr.py") |
|
else: |
|
st.warning("The candidate does not pass the critera. ") |
|
|
|
|
|
|
|
else: |
|
st.warning("Please enter the job description and upload the resume.") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|