Update app.py
Browse files
app.py
CHANGED
@@ -1,114 +1,114 @@
|
|
1 |
-
import os
|
2 |
-
import streamlit as st
|
3 |
-
from dotenv import load_dotenv
|
4 |
-
from PIL import Image
|
5 |
-
import google.generativeai as genai
|
6 |
-
from pdf2image import convert_from_path
|
7 |
-
import pytesseract
|
8 |
-
import pdfplumber
|
9 |
-
|
10 |
-
# Load environment variables
|
11 |
-
load_dotenv()
|
12 |
-
|
13 |
-
# Configure Google Gemini AI
|
14 |
-
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
15 |
-
|
16 |
-
|
17 |
-
# Function to extract text from PDF
|
18 |
-
def extract_text_from_pdf(pdf_path):
|
19 |
-
text = ""
|
20 |
-
try:
|
21 |
-
# Try direct text extraction
|
22 |
-
with pdfplumber.open(pdf_path) as pdf:
|
23 |
-
for page in pdf.pages:
|
24 |
-
page_text = page.extract_text()
|
25 |
-
if page_text:
|
26 |
-
text += page_text
|
27 |
-
|
28 |
-
if text.strip():
|
29 |
-
return text.strip()
|
30 |
-
except Exception as e:
|
31 |
-
print(f"Direct text extraction failed: {e}")
|
32 |
-
|
33 |
-
# Fallback to OCR for image-based PDFs
|
34 |
-
print("Falling back to OCR for image-based PDF.")
|
35 |
-
try:
|
36 |
-
images = convert_from_path(pdf_path)
|
37 |
-
for image in images:
|
38 |
-
page_text = pytesseract.image_to_string(image)
|
39 |
-
text += page_text + "\n"
|
40 |
-
except Exception as e:
|
41 |
-
print(f"OCR failed: {e}")
|
42 |
-
return text.strip()
|
43 |
-
# Function to get response from Gemini AI
|
44 |
-
def analyze_resume(resume_text, job_description=None):
|
45 |
-
if not resume_text:
|
46 |
-
return {"error": "Resume text is required for analysis."}
|
47 |
-
|
48 |
-
model = genai.GenerativeModel("gemini-1.5-flash")
|
49 |
-
|
50 |
-
base_prompt = f"""
|
51 |
-
You are an experienced HR with Technical Experience in the field of any one job role from Data Science, Data Analyst, DevOPS, Machine Learning Engineer, Prompt Engineer, AI Engineer, Full Stack Web Development, Big Data Engineering, Marketing Analyst, Human Resource Manager, Software Developer your task is to review the provided resume.
|
52 |
-
Please share your professional evaluation on whether the candidate's profile aligns with the role.ALso mention Skills he already have and siggest some skills to imorve his resume , alos suggest some course he might take to improve the skills.Highlight the strengths and weaknesses.
|
53 |
-
|
54 |
-
Resume:
|
55 |
-
{resume_text}
|
56 |
-
"""
|
57 |
-
|
58 |
-
if job_description:
|
59 |
-
base_prompt += f"""
|
60 |
-
Additionally, compare this resume to the following job description:
|
61 |
-
|
62 |
-
Job Description:
|
63 |
-
{job_description}
|
64 |
-
|
65 |
-
Highlight the strengths and weaknesses of the applicant in relation to the specified job requirements.
|
66 |
-
"""
|
67 |
-
|
68 |
-
response = model.generate_content(base_prompt)
|
69 |
-
|
70 |
-
analysis = response.text.strip()
|
71 |
-
return analysis
|
72 |
-
|
73 |
-
|
74 |
-
# Streamlit app
|
75 |
-
|
76 |
-
st.set_page_config(page_title="Resume Analyzer", layout="wide")
|
77 |
-
# Title
|
78 |
-
st.title("AI Resume Analyzer")
|
79 |
-
st.write("Analyze your resume and match it with job descriptions using Google Gemini AI.")
|
80 |
-
|
81 |
-
col1 , col2 = st.columns(2)
|
82 |
-
with col1:
|
83 |
-
uploaded_file = st.file_uploader("Upload your resume (PDF)", type=["pdf"])
|
84 |
-
with col2:
|
85 |
-
job_description = st.text_area("Enter Job Description:", placeholder="Paste the job description here...")
|
86 |
-
|
87 |
-
if uploaded_file is not None:
|
88 |
-
st.success("Resume uploaded successfully!")
|
89 |
-
else:
|
90 |
-
st.warning("Please upload a resume in PDF format.")
|
91 |
-
|
92 |
-
|
93 |
-
st.markdown("<div style= 'padding-top: 10px;'></div>", unsafe_allow_html=True)
|
94 |
-
if uploaded_file:
|
95 |
-
# Save uploaded file locally for processing
|
96 |
-
with open("uploaded_resume.pdf", "wb") as f:
|
97 |
-
f.write(uploaded_file.getbuffer())
|
98 |
-
# Extract text from PDF
|
99 |
-
resume_text = extract_text_from_pdf("uploaded_resume.pdf")
|
100 |
-
|
101 |
-
if st.button("Analyze Resume"):
|
102 |
-
with st.spinner("Analyzing resume..."):
|
103 |
-
try:
|
104 |
-
# Analyze resume
|
105 |
-
analysis = analyze_resume(resume_text, job_description)
|
106 |
-
st.success("Analysis complete!")
|
107 |
-
st.write(analysis)
|
108 |
-
except Exception as e:
|
109 |
-
st.error(f"Analysis failed: {e}")
|
110 |
-
|
111 |
-
#Footer
|
112 |
-
st.markdown("---")
|
113 |
-
st.markdown("""<p style= 'text-align: center;' >Powered by <b>Streamlit</b> and <b>Google Gemini AI</b> | Developed by <
|
114 |
-
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
from PIL import Image
|
5 |
+
import google.generativeai as genai
|
6 |
+
from pdf2image import convert_from_path
|
7 |
+
import pytesseract
|
8 |
+
import pdfplumber
|
9 |
+
|
10 |
+
# Load environment variables
|
11 |
+
load_dotenv()
|
12 |
+
|
13 |
+
# Configure Google Gemini AI
|
14 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
15 |
+
|
16 |
+
|
17 |
+
# Function to extract text from PDF
|
18 |
+
def extract_text_from_pdf(pdf_path):
|
19 |
+
text = ""
|
20 |
+
try:
|
21 |
+
# Try direct text extraction
|
22 |
+
with pdfplumber.open(pdf_path) as pdf:
|
23 |
+
for page in pdf.pages:
|
24 |
+
page_text = page.extract_text()
|
25 |
+
if page_text:
|
26 |
+
text += page_text
|
27 |
+
|
28 |
+
if text.strip():
|
29 |
+
return text.strip()
|
30 |
+
except Exception as e:
|
31 |
+
print(f"Direct text extraction failed: {e}")
|
32 |
+
|
33 |
+
# Fallback to OCR for image-based PDFs
|
34 |
+
print("Falling back to OCR for image-based PDF.")
|
35 |
+
try:
|
36 |
+
images = convert_from_path(pdf_path)
|
37 |
+
for image in images:
|
38 |
+
page_text = pytesseract.image_to_string(image)
|
39 |
+
text += page_text + "\n"
|
40 |
+
except Exception as e:
|
41 |
+
print(f"OCR failed: {e}")
|
42 |
+
return text.strip()
|
43 |
+
# Function to get response from Gemini AI
|
44 |
+
def analyze_resume(resume_text, job_description=None):
|
45 |
+
if not resume_text:
|
46 |
+
return {"error": "Resume text is required for analysis."}
|
47 |
+
|
48 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
49 |
+
|
50 |
+
base_prompt = f"""
|
51 |
+
You are an experienced HR with Technical Experience in the field of any one job role from Data Science, Data Analyst, DevOPS, Machine Learning Engineer, Prompt Engineer, AI Engineer, Full Stack Web Development, Big Data Engineering, Marketing Analyst, Human Resource Manager, Software Developer your task is to review the provided resume.
|
52 |
+
Please share your professional evaluation on whether the candidate's profile aligns with the role.ALso mention Skills he already have and siggest some skills to imorve his resume , alos suggest some course he might take to improve the skills.Highlight the strengths and weaknesses.
|
53 |
+
|
54 |
+
Resume:
|
55 |
+
{resume_text}
|
56 |
+
"""
|
57 |
+
|
58 |
+
if job_description:
|
59 |
+
base_prompt += f"""
|
60 |
+
Additionally, compare this resume to the following job description:
|
61 |
+
|
62 |
+
Job Description:
|
63 |
+
{job_description}
|
64 |
+
|
65 |
+
Highlight the strengths and weaknesses of the applicant in relation to the specified job requirements.
|
66 |
+
"""
|
67 |
+
|
68 |
+
response = model.generate_content(base_prompt)
|
69 |
+
|
70 |
+
analysis = response.text.strip()
|
71 |
+
return analysis
|
72 |
+
|
73 |
+
|
74 |
+
# Streamlit app
|
75 |
+
|
76 |
+
st.set_page_config(page_title="Resume Analyzer", layout="wide")
|
77 |
+
# Title
|
78 |
+
st.title("AI Resume Analyzer")
|
79 |
+
st.write("Analyze your resume and match it with job descriptions using Google Gemini AI.")
|
80 |
+
|
81 |
+
col1 , col2 = st.columns(2)
|
82 |
+
with col1:
|
83 |
+
uploaded_file = st.file_uploader("Upload your resume (PDF)", type=["pdf"])
|
84 |
+
with col2:
|
85 |
+
job_description = st.text_area("Enter Job Description:", placeholder="Paste the job description here...")
|
86 |
+
|
87 |
+
if uploaded_file is not None:
|
88 |
+
st.success("Resume uploaded successfully!")
|
89 |
+
else:
|
90 |
+
st.warning("Please upload a resume in PDF format.")
|
91 |
+
|
92 |
+
|
93 |
+
st.markdown("<div style= 'padding-top: 10px;'></div>", unsafe_allow_html=True)
|
94 |
+
if uploaded_file:
|
95 |
+
# Save uploaded file locally for processing
|
96 |
+
with open("uploaded_resume.pdf", "wb") as f:
|
97 |
+
f.write(uploaded_file.getbuffer())
|
98 |
+
# Extract text from PDF
|
99 |
+
resume_text = extract_text_from_pdf("uploaded_resume.pdf")
|
100 |
+
|
101 |
+
if st.button("Analyze Resume"):
|
102 |
+
with st.spinner("Analyzing resume..."):
|
103 |
+
try:
|
104 |
+
# Analyze resume
|
105 |
+
analysis = analyze_resume(resume_text, job_description)
|
106 |
+
st.success("Analysis complete!")
|
107 |
+
st.write(analysis)
|
108 |
+
except Exception as e:
|
109 |
+
st.error(f"Analysis failed: {e}")
|
110 |
+
|
111 |
+
#Footer
|
112 |
+
st.markdown("---")
|
113 |
+
st.markdown("""<p style= 'text-align: center;' >Powered by <b>Streamlit</b> and <b>Google Gemini AI</b> | Developed by <b>Max Johnson</b></a></p>""", unsafe_allow_html=True)
|
114 |
+
|