Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +144 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
+
import os
|
| 4 |
+
import PyPDF2 as pdf
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
import json
|
| 7 |
+
|
| 8 |
+
# Load environment variables
|
| 9 |
+
load_dotenv()
|
| 10 |
+
|
| 11 |
+
# Configure Google Generative AI
|
| 12 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 13 |
+
|
| 14 |
+
# Function to get response from Gemini
|
| 15 |
+
def get_gemini_response(input):
|
| 16 |
+
model = genai.GenerativeModel('gemini-pro')
|
| 17 |
+
response = model.generate_content(input)
|
| 18 |
+
return response.text
|
| 19 |
+
|
| 20 |
+
# Function to extract text from PDF
|
| 21 |
+
def input_pdf_text(uploaded_file):
|
| 22 |
+
if uploaded_file is not None:
|
| 23 |
+
reader = pdf.PdfReader(uploaded_file)
|
| 24 |
+
text = ""
|
| 25 |
+
for page in range(len(reader.pages)):
|
| 26 |
+
page = reader.pages[page]
|
| 27 |
+
text += str(page.extract_text())
|
| 28 |
+
return text
|
| 29 |
+
else:
|
| 30 |
+
return ""
|
| 31 |
+
|
| 32 |
+
# Prompt templates for predefined questions
|
| 33 |
+
predefined_prompts = {
|
| 34 |
+
"What needs to improve?": """
|
| 35 |
+
As a skilled ATS with a deep understanding of the tech field, software engineering, data science,
|
| 36 |
+
data analysis, and big data engineering, evaluate the resume based on the given job description.
|
| 37 |
+
Provide feedback on what needs to be improved in the resume in concise, bullet points, and short,
|
| 38 |
+
containing useful tips relevant to the job description.
|
| 39 |
+
resume: {text}
|
| 40 |
+
description: {jd}
|
| 41 |
+
""",
|
| 42 |
+
"How well does my resume match the job description?": """
|
| 43 |
+
As a skilled ATS with a deep understanding of the tech field, software engineering, data science,
|
| 44 |
+
data analysis, and big data engineering, evaluate the resume based on the given job description.
|
| 45 |
+
Assign a percentage match based on the job description and the resume.
|
| 46 |
+
resume: {text}
|
| 47 |
+
description: {jd}
|
| 48 |
+
""",
|
| 49 |
+
"What are the missing keywords?": """
|
| 50 |
+
As a skilled ATS with a deep understanding of the tech field, software engineering, data science,
|
| 51 |
+
data analysis, and big data engineering, evaluate the resume based on the given job description.
|
| 52 |
+
Identify the missing keywords in the resume in concise, bullet points.
|
| 53 |
+
resume: {text}
|
| 54 |
+
description: {jd}
|
| 55 |
+
""",
|
| 56 |
+
"Can you summarize the profile?": """
|
| 57 |
+
As a skilled ATS with a deep understanding of the tech field, software engineering, data science,
|
| 58 |
+
data analysis, and big data engineering, evaluate the resume based on the given job description.
|
| 59 |
+
Provide a concise summary of the profile.
|
| 60 |
+
resume: {text}
|
| 61 |
+
description: {jd}
|
| 62 |
+
"""
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
# app
|
| 66 |
+
st.title("Smart ATS")
|
| 67 |
+
st.sidebar.title("Job Description and Resume")
|
| 68 |
+
|
| 69 |
+
# Job Description input
|
| 70 |
+
jd = st.sidebar.text_area("Paste the Job Description", help="Enter the job description for the position you are applying for.")
|
| 71 |
+
|
| 72 |
+
# Resume upload
|
| 73 |
+
uploaded_file = st.sidebar.file_uploader("Upload Your Resume", type="pdf", help="Please upload your resume in PDF format.")
|
| 74 |
+
|
| 75 |
+
resume_text = input_pdf_text(uploaded_file)
|
| 76 |
+
|
| 77 |
+
# Pre-written questions
|
| 78 |
+
st.sidebar.subheader("Quick Questions")
|
| 79 |
+
questions = [
|
| 80 |
+
"What needs to improve?",
|
| 81 |
+
"How well does my resume match the job description?",
|
| 82 |
+
"What are the missing keywords?",
|
| 83 |
+
"Can you summarize the profile?"
|
| 84 |
+
]
|
| 85 |
+
|
| 86 |
+
selected_question = st.sidebar.radio("Choose a question:", questions)
|
| 87 |
+
|
| 88 |
+
# Custom question input
|
| 89 |
+
custom_question = st.text_input("Ask a custom question:", help="Enter any custom question related to your resume and job description.")
|
| 90 |
+
|
| 91 |
+
# Submit button for custom question
|
| 92 |
+
custom_submit = st.button("Reply")
|
| 93 |
+
|
| 94 |
+
# Function to display formatted response
|
| 95 |
+
def display_response(response):
|
| 96 |
+
st.subheader("According to ATS:")
|
| 97 |
+
formatted_response = format_response(response)
|
| 98 |
+
st.markdown(formatted_response, unsafe_allow_html=True)
|
| 99 |
+
|
| 100 |
+
def format_response(response):
|
| 101 |
+
lines = response.split("\n")
|
| 102 |
+
html_list = "<ol>"
|
| 103 |
+
for line in lines:
|
| 104 |
+
if line.strip():
|
| 105 |
+
parts = line.split(":", 1)
|
| 106 |
+
main_point = parts[0].strip()
|
| 107 |
+
details = parts[1].strip() if len(parts) > 1 else ""
|
| 108 |
+
html_list += f"<li><b>{main_point}:</b> {details}</li>"
|
| 109 |
+
html_list += "</ol>"
|
| 110 |
+
return html_list
|
| 111 |
+
|
| 112 |
+
# Handle pre-written question
|
| 113 |
+
if selected_question and resume_text and not custom_submit:
|
| 114 |
+
input_text = predefined_prompts[selected_question].format(text=resume_text, jd=jd)
|
| 115 |
+
response = get_gemini_response(input_text)
|
| 116 |
+
st.subheader(selected_question)
|
| 117 |
+
display_response(response)
|
| 118 |
+
|
| 119 |
+
# Handle custom question
|
| 120 |
+
if custom_submit and custom_question and resume_text and jd:
|
| 121 |
+
custom_prompt = f"""
|
| 122 |
+
As a skilled ATS with a deep understanding of the tech field, software engineering, data science,
|
| 123 |
+
data analysis, and big data engineering, evaluate the resume based on the given job description.
|
| 124 |
+
Respond to the following custom question: {custom_question}
|
| 125 |
+
resume: {{text}}
|
| 126 |
+
description: {{jd}}
|
| 127 |
+
"""
|
| 128 |
+
input_text = custom_prompt.format(text=resume_text, jd=jd)
|
| 129 |
+
response = get_gemini_response(input_text)
|
| 130 |
+
st.subheader("Your Question Response")
|
| 131 |
+
display_response(response)
|
| 132 |
+
|
| 133 |
+
# Styling for buttons
|
| 134 |
+
st.markdown(
|
| 135 |
+
"""
|
| 136 |
+
<style>
|
| 137 |
+
.stButton button {
|
| 138 |
+
background-color: #4CAF50;
|
| 139 |
+
color: white;
|
| 140 |
+
}
|
| 141 |
+
</style>
|
| 142 |
+
""",
|
| 143 |
+
unsafe_allow_html=True
|
| 144 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
PyPDF2
|
| 3 |
+
google.generativeai
|
| 4 |
+
python-dotenv
|