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models import ChatMistralAI
|
| 5 |
+
import json
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
from PIL import Image
|
| 8 |
+
import pytesseract
|
| 9 |
+
import time
|
| 10 |
+
|
| 11 |
+
load_dotenv()
|
| 12 |
+
|
| 13 |
+
# Set up the Mistral AI client
|
| 14 |
+
mistral_api_key = os.getenv("MISTRAL_API_KEY")
|
| 15 |
+
client = ChatMistralAI(api_key=mistral_api_key)
|
| 16 |
+
|
| 17 |
+
# Define the input prompts
|
| 18 |
+
input_prompt1 = """
|
| 19 |
+
You are an skilled Applicant Tracking System scanner with a deep understanding of Applicant Tracking System functionality,
|
| 20 |
+
your task is to evaluate the resume against the provided job description.
|
| 21 |
+
Show a single percentage reflecting the overall match between resume and job description.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
input_prompt2 = """
|
| 25 |
+
You are an skilled Applicant Tracking System scanner with a deep understanding of Applicant Tracking System functionality,
|
| 26 |
+
your task is to evaluate the resume against the provided job description.
|
| 27 |
+
Find out the requirements the make this resume disqualified for this job in a list.
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
input_prompt3 = """
|
| 31 |
+
You are an skilled Applicant Tracking System scanner with a deep understanding of Applicant Tracking System functionality,
|
| 32 |
+
your task is to evaluate the resume against the provided job description.
|
| 33 |
+
Find out the most critical keywords in the resume that match the job description in a list.
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
input_prompt4 = """
|
| 37 |
+
You are submitting a resume to a job with the provided job description.
|
| 38 |
+
Find out the requirements in the job description you should add to make you qualify for this job.
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
input_prompt5 = """
|
| 42 |
+
You are the applicant who applied for this job and want to compose a strong but concise coverletter to convince the employer you have the skills and the expereince for this job.
|
| 43 |
+
The first paragraph of the cover letter must briefly discuss the your backgroud.
|
| 44 |
+
The second paragraph discuss how the applicant fit this role based on your skillsets matches the job requirements.
|
| 45 |
+
The third paragraph discuss the your interest in this role and thanks for the consideration .
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
# Define a function to extract text from a PDF file
|
| 49 |
+
def extract_text_from_pdf(file):
|
| 50 |
+
reader = PyPDF2.PdfReader(file)
|
| 51 |
+
text = ""
|
| 52 |
+
for page in range(len(reader.pages)):
|
| 53 |
+
text += reader.pages[page].extract_text()
|
| 54 |
+
return text
|
| 55 |
+
|
| 56 |
+
# Set up the Streamlit app
|
| 57 |
+
st.set_page_config(page_title="Resume Match Maker", page_icon=":robot:", layout="wide")
|
| 58 |
+
|
| 59 |
+
# Add a header to the app
|
| 60 |
+
st.header("Resume Match Maker")
|
| 61 |
+
st.markdown("## Created by Gokul Palanisamy")
|
| 62 |
+
|
| 63 |
+
# Add a ticker to the app
|
| 64 |
+
st.markdown("""<div style='position:fixed;bottom:0;left:0;background-color:#222;color:#fff;padding:10px;border-radius:5px;'>
|
| 65 |
+
<marquee behavior="scroll" direction="left">Resume Match Maker helps you match your resume to job descriptions and generate cover letters. Created by Gokul Palanisamy.</marquee>
|
| 66 |
+
</div>""", unsafe_allow_html=True)
|
| 67 |
+
|
| 68 |
+
# Add a sidebar to the app
|
| 69 |
+
with st.sidebar:
|
| 70 |
+
st.markdown("# Resume Match Maker")
|
| 71 |
+
st.markdown("## Match your resume to job descriptions and generate cover letters")
|
| 72 |
+
|
| 73 |
+
# Add input fields for job description and resume
|
| 74 |
+
use_image = st.checkbox("Use Image for Job Description")
|
| 75 |
+
|
| 76 |
+
if use_image:
|
| 77 |
+
job_description_image = st.file_uploader("Upload Job Description Image", type=["jpg", "jpeg", "png"])
|
| 78 |
+
if job_description_image:
|
| 79 |
+
# Perform OCR on the image
|
| 80 |
+
image = Image.open(job_description_image)
|
| 81 |
+
gray_image = image.convert("L")
|
| 82 |
+
job_description = pytesseract.image_to_string(gray_image)
|
| 83 |
+
else:
|
| 84 |
+
job_description = ""
|
| 85 |
+
else:
|
| 86 |
+
job_description = st.text_area("Enter Job Description", value="")
|
| 87 |
+
|
| 88 |
+
st.markdown("## Upload Resume")
|
| 89 |
+
resume = st.file_uploader("", type="pdf")
|
| 90 |
+
|
| 91 |
+
# Add a button to generate results
|
| 92 |
+
if st.button("Generate Results"):
|
| 93 |
+
# Display a loading spinner while the results are being generated
|
| 94 |
+
with st.spinner("Generating results..."):
|
| 95 |
+
# Display a progress bar while the results are being generated
|
| 96 |
+
progress_bar = st.progress(0)
|
| 97 |
+
|
| 98 |
+
# Extract text from the resume
|
| 99 |
+
if resume:
|
| 100 |
+
resume_text = extract_text_from_pdf(resume)
|
| 101 |
+
else:
|
| 102 |
+
st.error("Please upload a resume.")
|
| 103 |
+
resume_text = ""
|
| 104 |
+
|
| 105 |
+
# Generate results using Mistral AI
|
| 106 |
+
if job_description and resume_text:
|
| 107 |
+
# Match percentage
|
| 108 |
+
response1 = client.invoke(input_prompt1 + resume_text + job_description)
|
| 109 |
+
progress_bar.progress(20)
|
| 110 |
+
time.sleep(0.5)
|
| 111 |
+
|
| 112 |
+
# Disqualifying factors
|
| 113 |
+
response2 = client.invoke(input_prompt2 + resume_text + job_description)
|
| 114 |
+
progress_bar.progress(40)
|
| 115 |
+
time.sleep(0.5)
|
| 116 |
+
|
| 117 |
+
# Matching keywords
|
| 118 |
+
response3 = client.invoke(input_prompt3 + resume_text + job_description)
|
| 119 |
+
progress_bar.progress(60)
|
| 120 |
+
time.sleep(0.5)
|
| 121 |
+
|
| 122 |
+
# Missing keywords
|
| 123 |
+
response4 = client.invoke(input_prompt4 + resume_text + job_description)
|
| 124 |
+
progress_bar.progress(80)
|
| 125 |
+
time.sleep(0.5)
|
| 126 |
+
|
| 127 |
+
# Cover letter
|
| 128 |
+
response5 = client.invoke(input_prompt5 + resume_text + job_description)
|
| 129 |
+
progress_bar.progress(100)
|
| 130 |
+
time.sleep(0.5)
|
| 131 |
+
|
| 132 |
+
# Display the results
|
| 133 |
+
st.markdown("## Match Percentage")
|
| 134 |
+
st.markdown(f'* {response1.content}')
|
| 135 |
+
|
| 136 |
+
st.markdown("## Disqualifying Factors")
|
| 137 |
+
st.markdown(f'* {response2.content}')
|
| 138 |
+
|
| 139 |
+
st.markdown("## Matching Keywords")
|
| 140 |
+
st.markdown(f'* {response3.content}')
|
| 141 |
+
|
| 142 |
+
st.markdown("## Missing Keywords")
|
| 143 |
+
st.markdown(f'* {response4.content}')
|
| 144 |
+
|
| 145 |
+
st.markdown("## Cover Letter")
|
| 146 |
+
st.markdown(f'* {response5.content}')
|
| 147 |
+
|
| 148 |
+
else:
|
| 149 |
+
st.error("Please enter a job description and upload a resume.")
|