Kensium commited on
Commit
c72e56e
Β·
verified Β·
1 Parent(s): 416688b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -83
app.py CHANGED
@@ -1,85 +1,89 @@
 
 
 
 
 
1
  import streamlit as st
2
- import PyPDF2
3
- import re
4
-
5
- # Function to extract text from a PDF
6
- def extract_text_from_pdf(uploaded_file):
7
- pdf_reader = PyPDF2.PdfReader(uploaded_file)
8
- text = " ".join([page.extract_text() for page in pdf_reader.pages if page.extract_text()])
9
- return text
10
-
11
- # Function to extract skills from text (reference resumes and user resumes)
12
- def extract_skills_from_text(text):
13
- # A simple way to extract skills based on words in the resume.
14
- # This can be more advanced by integrating NER (Named Entity Recognition) or using predefined skill lists.
15
- skills = re.findall(r'\b[A-Za-z]+\b', text.lower()) # Extract words
16
- skills = set(skills) # Remove duplicates
17
- return skills
18
-
19
- # Function to evaluate user's resume based on job description
20
- def evaluate_resume(candidate_text, job_description_text):
21
- # Extract skills dynamically from job description
22
- job_description_skills = extract_skills_from_text(job_description_text)
23
-
24
- # Extract skills from candidate's resume
25
- candidate_skills = extract_skills_from_text(candidate_text)
26
-
27
- # Calculate matching skills
28
- matching_skills = job_description_skills.intersection(candidate_skills)
29
- missing_skills = job_description_skills.difference(candidate_skills)
30
-
31
- # Calculate improvement skills (skills present in the JD but not in candidate's resume)
32
- improvement_skills = job_description_skills.difference(matching_skills)
33
-
34
- # Calculate matching percentage (based on skills)
35
- matching_percentage = (len(matching_skills) / len(job_description_skills)) * 100 if len(job_description_skills) > 0 else 0
36
-
37
- result = {
38
- "matching_skills": list(matching_skills),
39
- "missing_skills": list(missing_skills),
40
- "improvement_skills": list(improvement_skills),
41
- "matching_percentage": round(matching_percentage, 2)
42
- }
43
-
44
- return result
45
-
46
- # Streamlit UI
47
- st.title("πŸ“„ Resume Screening with Job Description Matching")
48
- st.write("Upload a candidate's resume and provide a job description to check the matching percentage based on skills.")
49
-
50
- # Upload job description
51
- st.subheader("Upload Job Description")
52
- job_description_file = st.file_uploader("Upload Job Description (PDF)", type=["pdf"])
53
-
54
- # Upload candidate resume
55
- st.subheader("Upload Candidate Resume")
56
- uploaded_file = st.file_uploader("Upload Candidate Resume (PDF)", type=["pdf"])
57
-
58
- if uploaded_file and job_description_file:
59
- st.write("πŸ” **Processing resume and job description...**")
60
-
61
- # Extract text from candidate resume
62
- candidate_text = extract_text_from_pdf(uploaded_file)
63
-
64
- # Extract text from job description
65
- job_description_text = extract_text_from_pdf(job_description_file)
66
-
67
- # Evaluate resume based on job description
68
- evaluation = evaluate_resume(candidate_text, job_description_text)
69
-
70
- # Display results
71
- st.subheader("πŸ“Œ Evaluation Result:")
72
- st.write(f"**πŸ”’ Matching Percentage:** {evaluation['matching_percentage']}%")
73
- # st.write(f"**βœ… Matching Skills:** {', '.join(evaluation['matching_skills']) or 'None'}")
74
- # st.write(f"**❌ Missing Skills:** {', '.join(evaluation['missing_skills']) or 'None'}")
75
- st.write(f"**πŸ’‘ Improvement Skills (Required but Missing):** {', '.join(evaluation['improvement_skills']) or 'None'}")
76
-
77
-
78
- if evaluation["matching_percentage"] > 70:
79
- st.success("βœ… Resume is a strong match for the job description!")
80
- elif evaluation["matching_percentage"] > 40:
81
- st.warning("⚠️ Resume is a partial match for the job description.")
82
  else:
83
- st.error("❌ Resume does not match well with the job description.")
84
- else:
85
- st.write("Please upload both the job description and candidate resume.")
 
 
 
 
 
 
 
 
 
1
+
2
+ from dotenv import load_dotenv
3
+
4
+ load_dotenv()
5
+ import base64
6
  import streamlit as st
7
+ import os
8
+ import io
9
+ from PIL import Image
10
+ import pdf2image
11
+ import google.generativeai as genai
12
+
13
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
14
+
15
+ def get_gemini_response(input,pdf_cotent,prompt):
16
+ model=genai.GenerativeModel('gemini-pro-vision')
17
+ response=model.generate_content([input,pdf_content[0],prompt])
18
+ return response.text
19
+
20
+ def input_pdf_setup(uploaded_file):
21
+ if uploaded_file is not None:
22
+ ## Convert the PDF to image
23
+ images=pdf2image.convert_from_bytes(uploaded_file.read())
24
+
25
+ first_page=images[0]
26
+
27
+ # Convert to bytes
28
+ img_byte_arr = io.BytesIO()
29
+ first_page.save(img_byte_arr, format='JPEG')
30
+ img_byte_arr = img_byte_arr.getvalue()
31
+
32
+ pdf_parts = [
33
+ {
34
+ "mime_type": "image/jpeg",
35
+ "data": base64.b64encode(img_byte_arr).decode() # encode to base64
36
+ }
37
+ ]
38
+ return pdf_parts
39
+ else:
40
+ raise FileNotFoundError("No file uploaded")
41
+
42
+ ## Streamlit App
43
+
44
+ st.set_page_config(page_title="ATS Resume EXpert")
45
+ st.header("ATS Tracking System")
46
+ input_text=st.text_area("Job Description: ",key="input")
47
+ uploaded_file=st.file_uploader("Upload your resume(PDF)...",type=["pdf"])
48
+
49
+
50
+ if uploaded_file is not None:
51
+ st.write("PDF Uploaded Successfully")
52
+
53
+
54
+ submit1 = st.button("Tell Me About the Resume")
55
+
56
+ #submit2 = st.button("How Can I Improvise my Skills")
57
+
58
+ submit3 = st.button("Percentage match")
59
+
60
+ input_prompt1 = """
61
+ You are an experienced Technical Human Resource Manager,your task is to review the provided resume against the job description.
62
+ Please share your professional evaluation on whether the candidate's profile aligns with the role.
63
+ Highlight the strengths and weaknesses of the applicant in relation to the specified job requirements.
64
+ """
65
+
66
+ input_prompt3 = """
67
+ You are an skilled ATS (Applicant Tracking System) scanner with a deep understanding of data science and ATS functionality,
68
+ your task is to evaluate the resume against the provided job description. give me the percentage of match if the resume matches
69
+ the job description. First the output should come as percentage and then keywords missing and last final thoughts.
70
+ """
71
+
72
+ if submit1:
73
+ if uploaded_file is not None:
74
+ pdf_content=input_pdf_setup(uploaded_file)
75
+ response=get_gemini_response(input_prompt1,pdf_content,input_text)
76
+ st.subheader("The Repsonse is")
77
+ st.write(response)
 
 
 
 
 
 
 
 
 
78
  else:
79
+ st.write("Please uplaod the resume")
80
+
81
+ elif submit3:
82
+ if uploaded_file is not None:
83
+ pdf_content=input_pdf_setup(uploaded_file)
84
+ response=get_gemini_response(input_prompt3,pdf_content,input_text)
85
+ st.subheader("The Repsonse is")
86
+ st.write(response)
87
+ else:
88
+ st.write("Please uplaod the resume")
89
+