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 # Load environment variables # Function to extract text from PDF @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 # Function to extract information using Generative AI 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) # Adjust resolution as needed st.image(image._repr_png_(), caption=f"Page {i+1}", use_column_width=True) def main(): # st.title("CareerSync: Harmonizing Resumes with Job Descriptions") st.markdown( "

CareerSync: Harmonizing Resumes with Job Descriptions

", 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.") # Input job description st.subheader("Step 1: Enter Job Description") job_description = st.text_area("Paste or type the job description here", height=200) # Upload resume st.subheader("Step 2: Upload Resume") resume_file = st.file_uploader("Upload your resume (PDF only)", type=['pdf']) # Button to compare 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) # Displaying extracted content with st.expander("Candidate Resume:"): # st.write(resume_content) pdf_name = resume_file.name read_pdf(pdf_name, resume_file) with st.expander("Enhanced Job Description:"): st.write(enhanced_job_description) # Generating evaluation prompt 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}" # prompt_template = f"Assess the candidate's suitability for the position. Provide your evaluation in the form of a Python list with two indices: the first index indicates either 'pass' or 'fail', and the second index denotes a score ranging from 1 to 10. Pay close attention to the alignment between the job's required experience outlined in the job description and the candidate's experience as reflected in the resume, as well as the specific skill set essential for the role.\n\nBelow is the content of the candidate's resume:\n{resume_content}\n\nFurthermore, consider the following enhanced description of the job role:\n{enhanced_job_description}" result = extract_information(prompt_template) st.subheader("Evaluation Result:") st.write(result) lst = eval(result) # Displaying evaluation results st.subheader("Evaluation Details:") st.write(f"Evaluation: {lst[0]}") st.write(f"Score: {lst[1]}") # Running HR app if score is high 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()