Spaces:
Sleeping
Sleeping
File size: 5,247 Bytes
e1721e7 |
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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
import streamlit as st
import google.generativeai as genai
import os
import PyPDF2 as pdf
from dotenv import load_dotenv
import json
# Load environment variables
load_dotenv()
# Configure Google Generative AI
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
# Function to get response from Gemini
def get_gemini_response(input):
model = genai.GenerativeModel('gemini-pro')
response = model.generate_content(input)
return response.text
# Function to extract text from PDF
def input_pdf_text(uploaded_file):
if uploaded_file is not None:
reader = pdf.PdfReader(uploaded_file)
text = ""
for page in range(len(reader.pages)):
page = reader.pages[page]
text += str(page.extract_text())
return text
else:
return ""
# Prompt templates for predefined questions
predefined_prompts = {
"What needs to improve?": """
As a skilled ATS with a deep understanding of the tech field, software engineering, data science,
data analysis, and big data engineering, evaluate the resume based on the given job description.
Provide feedback on what needs to be improved in the resume in concise, bullet points, and short,
containing useful tips relevant to the job description.
resume: {text}
description: {jd}
""",
"How well does my resume match the job description?": """
As a skilled ATS with a deep understanding of the tech field, software engineering, data science,
data analysis, and big data engineering, evaluate the resume based on the given job description.
Assign a percentage match based on the job description and the resume.
resume: {text}
description: {jd}
""",
"What are the missing keywords?": """
As a skilled ATS with a deep understanding of the tech field, software engineering, data science,
data analysis, and big data engineering, evaluate the resume based on the given job description.
Identify the missing keywords in the resume in concise, bullet points.
resume: {text}
description: {jd}
""",
"Can you summarize the profile?": """
As a skilled ATS with a deep understanding of the tech field, software engineering, data science,
data analysis, and big data engineering, evaluate the resume based on the given job description.
Provide a concise summary of the profile.
resume: {text}
description: {jd}
"""
}
# app
st.title("Smart ATS")
st.sidebar.title("Job Description and Resume")
# Job Description input
jd = st.sidebar.text_area("Paste the Job Description", help="Enter the job description for the position you are applying for.")
# Resume upload
uploaded_file = st.sidebar.file_uploader("Upload Your Resume", type="pdf", help="Please upload your resume in PDF format.")
resume_text = input_pdf_text(uploaded_file)
# Pre-written questions
st.sidebar.subheader("Quick Questions")
questions = [
"What needs to improve?",
"How well does my resume match the job description?",
"What are the missing keywords?",
"Can you summarize the profile?"
]
selected_question = st.sidebar.radio("Choose a question:", questions)
# Custom question input
custom_question = st.text_input("Ask a custom question:", help="Enter any custom question related to your resume and job description.")
# Submit button for custom question
custom_submit = st.button("Reply")
# Function to display formatted response
def display_response(response):
st.subheader("According to ATS:")
formatted_response = format_response(response)
st.markdown(formatted_response, unsafe_allow_html=True)
def format_response(response):
lines = response.split("\n")
html_list = "<ol>"
for line in lines:
if line.strip():
parts = line.split(":", 1)
main_point = parts[0].strip()
details = parts[1].strip() if len(parts) > 1 else ""
html_list += f"<li><b>{main_point}:</b> {details}</li>"
html_list += "</ol>"
return html_list
# Handle pre-written question
if selected_question and resume_text and not custom_submit:
input_text = predefined_prompts[selected_question].format(text=resume_text, jd=jd)
response = get_gemini_response(input_text)
st.subheader(selected_question)
display_response(response)
# Handle custom question
if custom_submit and custom_question and resume_text and jd:
custom_prompt = f"""
As a skilled ATS with a deep understanding of the tech field, software engineering, data science,
data analysis, and big data engineering, evaluate the resume based on the given job description.
Respond to the following custom question: {custom_question}
resume: {{text}}
description: {{jd}}
"""
input_text = custom_prompt.format(text=resume_text, jd=jd)
response = get_gemini_response(input_text)
st.subheader("Your Question Response")
display_response(response)
# Styling for buttons
st.markdown(
"""
<style>
.stButton button {
background-color: #4CAF50;
color: white;
}
</style>
""",
unsafe_allow_html=True
)
|