-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
108 lines (87 loc) · 3.98 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import streamlit as st
import google.generativeai as genai
import os
import docx2txt
import PyPDF2 as pdf
from dotenv import load_dotenv
# Load environment variables from a .env file
load_dotenv()
# Configure the generative AI model with the Google API key
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
# Set up the model configuration for text generation
generation_config = {
"temperature": 0.4,
"top_p": 1,
"top_k": 32,
"max_output_tokens": 4096,
}
# Define safety settings for content generation
safety_settings = [
{"category": f"HARM_CATEGORY_{category}", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}
for category in ["HARASSMENT", "HATE_SPEECH", "SEXUALLY_EXPLICIT", "DANGEROUS_CONTENT"]
]
def generate_response_from_gemini(input_text):
# Create a GenerativeModel instance with 'gemini-pro' as the model type
llm = genai.GenerativeModel(
model_name="gemini-pro",
generation_config=generation_config,
safety_settings=safety_settings,
)
# Generate content based on the input text
output = llm.generate_content(input_text)
# Return the generated text
return output.text
def extract_text_from_pdf_file(uploaded_file):
# Use PdfReader to read the text content from a PDF file
pdf_reader = pdf.PdfReader(uploaded_file)
text_content = ""
for page in pdf_reader.pages:
text_content += str(page.extract_text())
return text_content
def extract_text_from_docx_file(uploaded_file):
# Use docx2txt to extract text from a DOCX file
return docx2txt.process(uploaded_file)
# Prompt Template
input_prompt_template = """
As an experienced Applicant Tracking System (ATS) analyst,
with profound knowledge in technology, software engineering, data science,
and big data engineering, your role involves evaluating resumes against job descriptions.
Recognizing the competitive job market, provide top-notch assistance for resume improvement.
Your goal is to analyze the resume against the given job description,
assign a percentage match based on key criteria, and pinpoint missing keywords accurately.
resume:{text}
description:{job_description}
I want the response in one single string having the structure
{{"Job Description Match":"%","Missing Keywords":"","Candidate Summary":"","Experience":""}}
"""
# Streamlit app
# Initialize Streamlit app
st.title("""
Matchmaker for Careers: Unveiling Your Resume's Job Potential
""")
st.markdown('<style>h1{color: orange; text-align: center;}</style>', unsafe_allow_html=True)
# Job Description
job_description = st.text_area("Paste the Job Description",height=300)
# Upload Resume
uploaded_file = st.file_uploader("Upload Your Resume", type=["pdf", "docx"], help="Please upload a PDF/DOCX file")
# Submit Button
submit_button = st.button("Submit")
if submit_button:
if uploaded_file is not None:
if uploaded_file.type == "application/pdf":
resume_text = extract_text_from_pdf_file(uploaded_file)
elif uploaded_file.type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
resume_text = extract_text_from_docx_file(uploaded_file)
response_text = generate_response_from_gemini(input_prompt_template.format(text=resume_text, job_description=job_description))
# Extract Job Description Match percentage from the response
match_percentage_str = response_text.split('"Job Description Match":"')[1].split('"')[0]
# Remove percentage symbol and convert to float
match_percentage = float(match_percentage_str.rstrip('%'))
st.subheader("ATS Evaluation Result:")
st.write(response_text)
#st.write(f'{{\n"Job Description Match": "{match_percentage}%",\n"Missing Keywords": "",\n"Candidate Summary": "",\n"Experience": ""\n}}')
# Display message based on Job Description Match percentage
if match_percentage >= 75:
st.text("Move forward with hiring!🎉🥳")
else:
st.text("Not a Match ☹️🥺, Best wishes for your job search!🍀🌈🌟")