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import load_dotenv
|
2 |
+
|
3 |
+
load_dotenv()
|
4 |
+
import base64
|
5 |
+
import streamlit as st
|
6 |
+
import os
|
7 |
+
import io
|
8 |
+
import textwrap
|
9 |
+
import tempfile
|
10 |
+
from PIL import Image
|
11 |
+
import fitz
|
12 |
+
import google.generativeai as genai
|
13 |
+
from prompts import (
|
14 |
+
input_prompt1,
|
15 |
+
input_prompt2,
|
16 |
+
input_prompt3,
|
17 |
+
input_prompt4,
|
18 |
+
input_prompt5,
|
19 |
+
input_prompt6,
|
20 |
+
input_prompt7,
|
21 |
+
input_prompt8,
|
22 |
+
)
|
23 |
+
|
24 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
25 |
+
|
26 |
+
|
27 |
+
def extract_field_from_description(description):
|
28 |
+
return input_role
|
29 |
+
|
30 |
+
|
31 |
+
def construct_prompt(template, field):
|
32 |
+
return template.replace("[User-Specified Field]", field)
|
33 |
+
|
34 |
+
|
35 |
+
def to_markdown(text):
|
36 |
+
text = text.replace("•", " *")
|
37 |
+
return textwrap.indent(text, "> ", predicate=lambda _: True)
|
38 |
+
|
39 |
+
|
40 |
+
def get_gemini_response(input, pdf_content, prompt):
|
41 |
+
model = genai.GenerativeModel("gemini-pro-vision")
|
42 |
+
response = model.generate_content([input, pdf_content[0], prompt])
|
43 |
+
# return response.text
|
44 |
+
return to_markdown(response.text)
|
45 |
+
|
46 |
+
|
47 |
+
def input_pdf_setup(uploaded_file):
|
48 |
+
if uploaded_file is not None:
|
49 |
+
file_content = uploaded_file.getvalue()
|
50 |
+
if file_content:
|
51 |
+
try:
|
52 |
+
doc = fitz.open(stream=file_content, filetype="pdf")
|
53 |
+
if len(doc) > 0:
|
54 |
+
page = doc.load_page(0) # first page
|
55 |
+
pix = page.get_pixmap()
|
56 |
+
img_byte_arr = pix.tobytes("png") # get bytes directly
|
57 |
+
|
58 |
+
pdf_parts = [
|
59 |
+
{
|
60 |
+
"mime_type": "image/png",
|
61 |
+
"data": base64.b64encode(img_byte_arr).decode(),
|
62 |
+
}
|
63 |
+
]
|
64 |
+
return pdf_parts
|
65 |
+
else:
|
66 |
+
raise ValueError("PDF does not contain any pages.")
|
67 |
+
except Exception as e:
|
68 |
+
st.error(f"Error processing PDF: {e}")
|
69 |
+
raise e
|
70 |
+
finally:
|
71 |
+
doc.close()
|
72 |
+
else:
|
73 |
+
st.error("Uploaded file is empty or invalid.")
|
74 |
+
raise ValueError("Uploaded file is empty or invalid.")
|
75 |
+
else:
|
76 |
+
st.error("No file uploaded.")
|
77 |
+
raise FileNotFoundError("No file uploaded")
|
78 |
+
|
79 |
+
|
80 |
+
# Streamlit App
|
81 |
+
|
82 |
+
st.set_page_config(
|
83 |
+
page_title="ATS Resume Expert",
|
84 |
+
page_icon="🔥",
|
85 |
+
)
|
86 |
+
st.header("ATS Friendly Resume and Analysis")
|
87 |
+
input_name = st.text_input("Enter your name: ", key="name", placeholder="John Doe")
|
88 |
+
input_role = st.text_input(
|
89 |
+
"Role you are applying for: ", key="role", placeholder="Software Engineer"
|
90 |
+
)
|
91 |
+
|
92 |
+
input_text = st.text_area(
|
93 |
+
"Job Description: ", key="input", placeholder="Paste the job description here..."
|
94 |
+
)
|
95 |
+
uploaded_file = st.file_uploader("Upload your resume(PDF)", type=["pdf"])
|
96 |
+
|
97 |
+
|
98 |
+
if "input_text" not in st.session_state:
|
99 |
+
st.session_state["input_text"] = input_text
|
100 |
+
|
101 |
+
if "input_name" not in st.session_state:
|
102 |
+
st.session_state["input_name"] = input_name
|
103 |
+
|
104 |
+
if "input_role" not in st.session_state:
|
105 |
+
st.session_state["input_role"] = input_role
|
106 |
+
|
107 |
+
if "input_text" not in st.session_state:
|
108 |
+
st.session_state["input_text"] = input_text
|
109 |
+
|
110 |
+
if "uploaded_file" not in st.session_state:
|
111 |
+
st.session_state["uploaded_file"] = uploaded_file
|
112 |
+
|
113 |
+
|
114 |
+
if uploaded_file is not None:
|
115 |
+
st.write("PDF uploaded successfully!")
|
116 |
+
|
117 |
+
# Prompts here
|
118 |
+
|
119 |
+
field = extract_field_from_description(input_text)
|
120 |
+
|
121 |
+
|
122 |
+
dynamic_prompt1 = construct_prompt(input_prompt1, field)
|
123 |
+
dynamic_prompt2 = construct_prompt(input_prompt2, field)
|
124 |
+
dynamic_prompt3 = construct_prompt(input_prompt3, field)
|
125 |
+
dynamic_prompt4 = construct_prompt(input_prompt4, field)
|
126 |
+
dynamic_prompt5 = construct_prompt(input_prompt5, field)
|
127 |
+
dynamic_prompt6 = construct_prompt(input_prompt6, field)
|
128 |
+
dynamic_prompt7 = construct_prompt(input_prompt7, field)
|
129 |
+
dynamic_prompt8 = construct_prompt(input_prompt8, field)
|
130 |
+
# Check if both the job description and the PDF file are provided
|
131 |
+
if input_text and uploaded_file:
|
132 |
+
try:
|
133 |
+
pdf_content = input_pdf_setup(uploaded_file)
|
134 |
+
print(pdf_content)
|
135 |
+
is_pdf_valid = True
|
136 |
+
|
137 |
+
except Exception as e:
|
138 |
+
st.error(f"Error processing the PDF file: {e}")
|
139 |
+
is_pdf_valid = False
|
140 |
+
|
141 |
+
if is_pdf_valid:
|
142 |
+
# Process for each tab if PDF is valid
|
143 |
+
field = extract_field_from_description(input_text)
|
144 |
+
|
145 |
+
st.subheader("Name : " + input_name)
|
146 |
+
st.subheader("Role : " + input_role)
|
147 |
+
|
148 |
+
tab1, tab2, tab3, tab4, tab5, tab6, tab7, tab8 = st.tabs(
|
149 |
+
[
|
150 |
+
"HR/Human Resume Analysis",
|
151 |
+
"ATS/AI Resume Analysis",
|
152 |
+
"Skills Review",
|
153 |
+
"ATS Friendly Resume",
|
154 |
+
"Cover Letter",
|
155 |
+
"LinkedIn",
|
156 |
+
"Interview Questions",
|
157 |
+
"Similar Companies",
|
158 |
+
]
|
159 |
+
)
|
160 |
+
|
161 |
+
with tab1:
|
162 |
+
st.header("HR/Human - Detailed Resume Analysis")
|
163 |
+
if uploaded_file is not None:
|
164 |
+
# pdf_content = input_pdf_setup(uploaded_file)
|
165 |
+
response = get_gemini_response(dynamic_prompt1, pdf_content, input_text)
|
166 |
+
st.write(response)
|
167 |
+
else:
|
168 |
+
st.write("Please upload the resume")
|
169 |
+
|
170 |
+
with tab2:
|
171 |
+
st.header("ATS/AI - Detailed Resume Analysis")
|
172 |
+
if uploaded_file is not None:
|
173 |
+
# pdf_content = input_pdf_setup(uploaded_file)
|
174 |
+
response = get_gemini_response(dynamic_prompt2, pdf_content, input_text)
|
175 |
+
st.write(response)
|
176 |
+
else:
|
177 |
+
st.write("Please upload the resume")
|
178 |
+
|
179 |
+
with tab3:
|
180 |
+
st.header("Skills Recommended for the Role")
|
181 |
+
if uploaded_file is not None:
|
182 |
+
# pdf_content = input_pdf_setup(uploaded_file)
|
183 |
+
response = get_gemini_response(dynamic_prompt3, pdf_content, input_text)
|
184 |
+
st.write(response)
|
185 |
+
else:
|
186 |
+
st.write("Please upload the resume")
|
187 |
+
with tab4:
|
188 |
+
st.header("ATS Friendly and optimized Resume")
|
189 |
+
if uploaded_file is not None:
|
190 |
+
# pdf_content = input_pdf_setup(uploaded_file)
|
191 |
+
response = get_gemini_response(dynamic_prompt4, pdf_content, input_text)
|
192 |
+
st.write(response)
|
193 |
+
else:
|
194 |
+
st.write("Please upload the resume")
|
195 |
+
with tab5:
|
196 |
+
st.header("Cover Letter for your resume")
|
197 |
+
if uploaded_file is not None:
|
198 |
+
# pdf_content = input_pdf_setup(uploaded_file)
|
199 |
+
response = get_gemini_response(dynamic_prompt5, pdf_content, input_text)
|
200 |
+
st.write(response)
|
201 |
+
else:
|
202 |
+
st.write("Please upload the resume")
|
203 |
+
with tab6:
|
204 |
+
st.header("LinkedIn Profile Recommendations")
|
205 |
+
if uploaded_file is not None:
|
206 |
+
# pdf_content = input_pdf_setup(uploaded_file)
|
207 |
+
response = get_gemini_response(dynamic_prompt6, pdf_content, input_text)
|
208 |
+
st.write(response)
|
209 |
+
else:
|
210 |
+
st.write("Please upload the resume")
|
211 |
+
with tab7:
|
212 |
+
st.header("Interview Questions and Questions to ask the interviewer")
|
213 |
+
if uploaded_file is not None:
|
214 |
+
# pdf_content = input_pdf_setup(uploaded_file)
|
215 |
+
response = get_gemini_response(dynamic_prompt7, pdf_content, input_text)
|
216 |
+
st.write(response)
|
217 |
+
else:
|
218 |
+
st.write("Please upload the resume")
|
219 |
+
with tab8:
|
220 |
+
st.header("Similar companies you can apply for")
|
221 |
+
if uploaded_file is not None:
|
222 |
+
# pdf_content = input_pdf_setup(uploaded_file)
|
223 |
+
response = get_gemini_response(dynamic_prompt8, pdf_content, input_text)
|
224 |
+
st.write(response)
|
225 |
+
else:
|
226 |
+
st.write("Please upload the resume")
|
227 |
+
|
228 |
+
else:
|
229 |
+
st.write("Please provide the job description and upload the resume PDF.")
|