Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,83 +1,81 @@
|
|
| 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_dotenv()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 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 |
-
# Ensure we get only the text response
|
| 43 |
-
response_text = response.text.strip()
|
| 44 |
-
|
| 45 |
-
# Attempt to extract JSON from the response
|
| 46 |
-
try:
|
| 47 |
-
parsed_response = json.loads(response_text)
|
| 48 |
-
return parsed_response # Return parsed JSON
|
| 49 |
-
except json.JSONDecodeError:
|
| 50 |
-
return None # Return None if response is not valid JSON
|
| 51 |
-
|
| 52 |
-
def input_pdf_text(uploaded_file):
|
| 53 |
-
"""Extracts text from the uploaded PDF resume."""
|
| 54 |
-
reader = pdf.PdfReader(uploaded_file)
|
| 55 |
-
text = ""
|
| 56 |
-
for page in range(len(reader.pages)):
|
| 57 |
-
extracted_text = reader.pages[page].extract_text()
|
| 58 |
-
if extracted_text:
|
| 59 |
-
text += extracted_text
|
| 60 |
-
return text
|
| 61 |
-
|
| 62 |
-
# Streamlit app
|
| 63 |
-
st.title("Smart ATS")
|
| 64 |
-
st.text("Improve Your Resume for ATS Systems")
|
| 65 |
-
|
| 66 |
-
jd = st.text_area("Paste the Job Description")
|
| 67 |
-
uploaded_file = st.file_uploader("Upload Your Resume", type="pdf", help="Please upload a PDF file")
|
| 68 |
-
|
| 69 |
-
submit = st.button("Submit")
|
| 70 |
-
|
| 71 |
-
if submit:
|
| 72 |
-
if uploaded_file is not None and jd:
|
| 73 |
-
text = input_pdf_text(uploaded_file)
|
| 74 |
-
response = get_gemini_response(text, jd) # Pass formatted resume & JD
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
else:
|
| 83 |
-
st.warning("Please upload
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from dotenv import load_dotenv
|
|
|
|
| 2 |
|
| 3 |
+
load_dotenv()
|
| 4 |
+
import base64
|
| 5 |
+
import streamlit as st
|
| 6 |
+
import os
|
| 7 |
+
import io
|
| 8 |
+
from PIL import Image
|
| 9 |
+
import pdf2image
|
| 10 |
+
import google.generativeai as genai
|
| 11 |
|
| 12 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 13 |
|
| 14 |
+
def get_gemini_response(input_text, pdf_content, prompt):
|
| 15 |
+
model = genai.GenerativeModel('gemini-pro-vision')
|
| 16 |
+
response = model.generate_content([input_text, pdf_content, prompt])
|
| 17 |
+
return response.text
|
| 18 |
+
|
| 19 |
+
def input_pdf_setup(uploaded_file):
|
| 20 |
+
if not uploaded_file:
|
| 21 |
+
st.warning("Please upload a PDF file.")
|
| 22 |
+
st.stop()
|
| 23 |
+
|
| 24 |
+
# Convert PDF to images
|
| 25 |
+
images = pdf2image.convert_from_bytes(uploaded_file.read())
|
| 26 |
+
first_page = images[0]
|
| 27 |
+
|
| 28 |
+
# Convert first page to bytes
|
| 29 |
+
img_byte_arr = io.BytesIO()
|
| 30 |
+
first_page.save(img_byte_arr, format='JPEG')
|
| 31 |
+
img_byte_arr = img_byte_arr.getvalue()
|
| 32 |
+
|
| 33 |
+
# Encode as base64
|
| 34 |
+
pdf_parts = [{
|
| 35 |
+
"mime_type": "image/jpeg",
|
| 36 |
+
"data": base64.b64encode(img_byte_arr).decode()
|
| 37 |
+
}]
|
| 38 |
+
return pdf_parts
|
| 39 |
+
|
| 40 |
+
# Streamlit App
|
| 41 |
+
st.set_page_config(page_title="ATS Resume Expert")
|
| 42 |
+
st.header("ATS Tracking System")
|
| 43 |
+
|
| 44 |
+
input_text = st.text_area("Job Description:", key="input")
|
| 45 |
+
uploaded_file = st.file_uploader("Upload your resume (PDF)...", type=["pdf"])
|
| 46 |
+
|
| 47 |
+
if uploaded_file:
|
| 48 |
+
st.success("PDF Uploaded Successfully")
|
| 49 |
+
|
| 50 |
+
submit1 = st.button("Tell Me About the Resume")
|
| 51 |
+
submit3 = st.button("Percentage Match")
|
| 52 |
+
|
| 53 |
+
input_prompt1 = """
|
| 54 |
+
You are an experienced Technical Human Resource Manager. Your task is to review the provided resume against the job description.
|
| 55 |
+
Please share your professional evaluation on whether the candidate's profile aligns with the role.
|
| 56 |
+
Highlight the strengths and weaknesses of the applicant in relation to the specified job requirements.
|
| 57 |
"""
|
| 58 |
|
| 59 |
+
input_prompt3 = """
|
| 60 |
+
You are a skilled ATS (Applicant Tracking System) scanner with expertise in data science and ATS functionality.
|
| 61 |
+
Your task is to evaluate the resume against the provided job description. Provide a percentage match if the resume aligns with the job description.
|
| 62 |
+
First, output the percentage match. Then, list missing keywords, followed by final thoughts.
|
| 63 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
if submit1 and not submit3:
|
| 66 |
+
if uploaded_file:
|
| 67 |
+
pdf_content = input_pdf_setup(uploaded_file)
|
| 68 |
+
response = get_gemini_response(input_prompt1, pdf_content, input_text)
|
| 69 |
+
st.subheader("Response:")
|
| 70 |
+
st.write(response)
|
| 71 |
+
else:
|
| 72 |
+
st.warning("Please upload the resume.")
|
| 73 |
+
|
| 74 |
+
elif submit3 and not submit1:
|
| 75 |
+
if uploaded_file:
|
| 76 |
+
pdf_content = input_pdf_setup(uploaded_file)
|
| 77 |
+
response = get_gemini_response(input_prompt3, pdf_content, input_text)
|
| 78 |
+
st.subheader("Response:")
|
| 79 |
+
st.write(response)
|
| 80 |
else:
|
| 81 |
+
st.warning("Please upload the resume.")
|