Krish30 commited on
Commit
84cf435
·
verified ·
1 Parent(s): e6109ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +135 -133
app.py CHANGED
@@ -1,133 +1,135 @@
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
- from fpdf import FPDF
7
- import tempfile
8
- import re
9
-
10
- load_dotenv()
11
-
12
- genai.configure(api_key=("AIzaSyDQxZw2oDaD_UFjtW1Q0rx4yfSQivYrj58"))
13
-
14
- # gemini function
15
- def get_gemini_response(input):
16
- model = genai.GenerativeModel('gemini-pro')
17
- response = model.generate_content(input)
18
- return response
19
-
20
- # convert pdf to text
21
- def input_pdf_text(uploaded_file):
22
- reader = pdf.PdfReader(uploaded_file)
23
- text = ""
24
- for page in range(len(reader.pages)):
25
- page = reader.pages[page]
26
- text += str(page.extract_text())
27
- return text
28
-
29
- # prompt template
30
- input_prompt = """
31
- ### As a skilled Application Tracking System(ATS) with advanced knowledge in technology and data science . your role is to meticulously evaluate a candidate's resume based on the provided job description.
32
-
33
- ### Your evaluation will involve analyzing the resume for relevant skills , experiences, and qualifications that align with the job requirements.Look for key buzzwords and specific criteria outlined in the job description to determine the candidate's suitability for the position.
34
-
35
- ### Provide a detailed assessment of how well the resume matches the job requiremnets ,highlighting strengths , weaknesses and any potential area of concern. Offer constructive feedback on how the condidate can enhance their resume to better align with the job description and improve their chances of securing the position.
36
-
37
- ### Your evaluation should be through, precise and objective,ensuring that the most qualified candidates are accurately identified based on their resume content in relation to the job criteria.
38
-
39
- ### Remember to utilize your expertise in technology and data science to conduct a comprehensive evaluation that optimizes the recruitment process for the hiring company. your insights will play a crucial role in determining the candidate's compatibility with the job role.
40
-
41
- ### parse data of job description and then make one list called Should do that is what candidate should do for that particular position.
42
-
43
- ### parse all CV of all candidates one time uploaded and then create one list called can do that is what candidate do.
44
-
45
- ### Now You should match all candidates can do generated list with should do list and give the report of each candidate with it's score and reasons of that score.
46
-
47
- ### Generate one pdf which contains matching score ,can do list , should do list,matching and missing from resume,highlighting strengths,Offer constructive feedback on how the condidate can enhance their resume to better align with the job description and improve their chances of securing the position.
48
- resume = {text}
49
- jd = {jd}
50
- """
51
-
52
- # Function to generate PDF
53
- class PDF(FPDF):
54
- def header(self):
55
- self.set_font('Arial', 'B', 12)
56
- self.cell(0, 10, 'Career Metaverse Smart ATS - Evaluation Report', 0, 1, 'C')
57
-
58
- def chapter_title(self, title):
59
- self.set_font('Arial', 'B', 12)
60
- self.cell(0, 10, title, 0, 1, 'L')
61
- self.ln(10)
62
-
63
- def chapter_body(self, body):
64
- for line in body.split('\n'):
65
- if line.startswith("**"):
66
- self.set_font('Arial', 'B', 12)
67
- self.multi_cell(0, 10, line.replace("**", "").strip())
68
- else:
69
- self.set_font('Arial', '', 12)
70
- self.multi_cell(0, 10, line)
71
- self.ln()
72
-
73
- def add_chapter(self, title, body):
74
- self.add_page()
75
- self.chapter_title(title)
76
- self.chapter_body(body)
77
-
78
- def generate_pdf(response_content, candidate_name):
79
- pdf = PDF()
80
- pdf.add_chapter('Evaluation Output', response_content)
81
-
82
- # Use tempfile to create a temporary file
83
- with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_file:
84
- pdf_output = tmp_file.name
85
- pdf.output(pdf_output)
86
-
87
- return pdf_output
88
-
89
- # Extract candidate's name from the response content
90
- def extract_candidate_name(response_content):
91
- # Use a regular expression to find the candidate's name
92
- # This assumes the candidate's name is mentioned at the beginning of the response
93
- match = re.search(r"Candidate Name:\s*(\w+\s*\w*)", response_content)
94
- if match:
95
- return match.group(1).strip()
96
- else:
97
- return "Candidate"
98
-
99
- # Streamlit App
100
- st.title("Career Metaverse Smart ATS")
101
- st.text("Improve your ATS system")
102
- jd = st.text_area("Paste job description here")
103
- uploaded_file = st.file_uploader("Upload your resume", type="pdf", help="Please upload the pdf")
104
-
105
- submit = st.button('Check Your Score')
106
- if submit:
107
- if uploaded_file is not None:
108
- text = input_pdf_text(uploaded_file)
109
- response = get_gemini_response(input_prompt.format(text=text, jd=jd))
110
-
111
- # Parse and display response in a structured way
112
- response_content = response.candidates[0].content.parts[0].text
113
- st.subheader("Evaluation Output")
114
-
115
- for line in response_content.split('\n'):
116
- if line.startswith("**"):
117
- st.markdown(f"**{line.replace('**', '').strip()}**")
118
- else:
119
- st.write(line)
120
-
121
- # Extract candidate's name
122
- candidate_name = extract_candidate_name(response_content)
123
-
124
- # Generate PDF
125
- pdf_path = generate_pdf(response_content, candidate_name)
126
-
127
- with open(pdf_path, "rb") as file:
128
- btn = st.download_button(
129
- label="Download Report as PDF",
130
- data=file,
131
- file_name=f"{candidate_name}_evaluation_report.pdf",
132
- mime="application/octet-stream"
133
- )
 
 
 
1
+
2
+
3
+ import streamlit as st
4
+ import google.generativeai as genai
5
+ import os
6
+ import PyPDF2 as pdf
7
+ from dotenv import load_dotenv
8
+ from fpdf import FPDF
9
+ import tempfile
10
+ import re
11
+
12
+ load_dotenv()
13
+
14
+ genai.configure(api_key=("AIzaSyDQxZw2oDaD_UFjtW1Q0rx4yfSQivYrj58"))
15
+
16
+ # gemini function
17
+ def get_gemini_response(input):
18
+ model = genai.GenerativeModel('gemini-pro')
19
+ response = model.generate_content(input)
20
+ return response
21
+
22
+ # convert pdf to text
23
+ def input_pdf_text(uploaded_file):
24
+ reader = pdf.PdfReader(uploaded_file)
25
+ text = ""
26
+ for page in range(len(reader.pages)):
27
+ page = reader.pages[page]
28
+ text += str(page.extract_text())
29
+ return text
30
+
31
+ # prompt template
32
+ input_prompt = """
33
+ ### As a skilled Application Tracking System(ATS) with advanced knowledge in technology and data science . your role is to meticulously evaluate a candidate's resume based on the provided job description.
34
+
35
+ ### Your evaluation will involve analyzing the resume for relevant skills , experiences, and qualifications that align with the job requirements.Look for key buzzwords and specific criteria outlined in the job description to determine the candidate's suitability for the position.
36
+
37
+ ### Provide a detailed assessment of how well the resume matches the job requiremnets ,highlighting strengths , weaknesses and any potential area of concern. Offer constructive feedback on how the condidate can enhance their resume to better align with the job description and improve their chances of securing the position.
38
+
39
+ ### Your evaluation should be through, precise and objective,ensuring that the most qualified candidates are accurately identified based on their resume content in relation to the job criteria.
40
+
41
+ ### Remember to utilize your expertise in technology and data science to conduct a comprehensive evaluation that optimizes the recruitment process for the hiring company. your insights will play a crucial role in determining the candidate's compatibility with the job role.
42
+
43
+ ### parse data of job description and then make one list called Should do that is what candidate should do for that particular position.
44
+
45
+ ### parse all CV of all candidates one time uploaded and then create one list called can do that is what candidate do.
46
+
47
+ ### Now You should match all candidates can do generated list with should do list and give the report of each candidate with it's score and reasons of that score.
48
+
49
+ ### Generate one pdf which contains matching score ,can do list , should do list,matching and missing from resume,highlighting strengths,Offer constructive feedback on how the condidate can enhance their resume to better align with the job description and improve their chances of securing the position.
50
+ resume = {text}
51
+ jd = {jd}
52
+ """
53
+
54
+ # Function to generate PDF
55
+ class PDF(FPDF):
56
+ def header(self):
57
+ self.set_font('Arial', 'B', 12)
58
+ self.cell(0, 10, 'Career Metaverse Smart ATS - Evaluation Report', 0, 1, 'C')
59
+
60
+ def chapter_title(self, title):
61
+ self.set_font('Arial', 'B', 12)
62
+ self.cell(0, 10, title, 0, 1, 'L')
63
+ self.ln(10)
64
+
65
+ def chapter_body(self, body):
66
+ for line in body.split('\n'):
67
+ if line.startswith("**"):
68
+ self.set_font('Arial', 'B', 12)
69
+ self.multi_cell(0, 10, line.replace("**", "").strip())
70
+ else:
71
+ self.set_font('Arial', '', 12)
72
+ self.multi_cell(0, 10, line)
73
+ self.ln()
74
+
75
+ def add_chapter(self, title, body):
76
+ self.add_page()
77
+ self.chapter_title(title)
78
+ self.chapter_body(body)
79
+
80
+ def generate_pdf(response_content, candidate_name):
81
+ pdf = PDF()
82
+ pdf.add_chapter('Evaluation Output', response_content)
83
+
84
+ # Use tempfile to create a temporary file
85
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_file:
86
+ pdf_output = tmp_file.name
87
+ pdf.output(pdf_output)
88
+
89
+ return pdf_output
90
+
91
+ # Extract candidate's name from the response content
92
+ def extract_candidate_name(response_content):
93
+ # Use a regular expression to find the candidate's name
94
+ # This assumes the candidate's name is mentioned at the beginning of the response
95
+ match = re.search(r"Candidate Name:\s*(\w+\s*\w*)", response_content)
96
+ if match:
97
+ return match.group(1).strip()
98
+ else:
99
+ return "Candidate"
100
+
101
+ # Streamlit App
102
+ st.title("Career Metaverse Smart ATS")
103
+ st.text("Improve your ATS system")
104
+ jd = st.text_area("Paste job description here")
105
+ uploaded_file = st.file_uploader("Upload your resume", type="pdf", help="Please upload the pdf")
106
+
107
+ submit = st.button('Check Your Score')
108
+ if submit:
109
+ if uploaded_file is not None:
110
+ text = input_pdf_text(uploaded_file)
111
+ response = get_gemini_response(input_prompt.format(text=text, jd=jd))
112
+
113
+ # Parse and display response in a structured way
114
+ response_content = response.candidates[0].content.parts[0].text
115
+ st.subheader("Evaluation Output")
116
+
117
+ for line in response_content.split('\n'):
118
+ if line.startswith("**"):
119
+ st.markdown(f"**{line.replace('**', '').strip()}**")
120
+ else:
121
+ st.write(line)
122
+
123
+ # Extract candidate's name
124
+ candidate_name = extract_candidate_name(response_content)
125
+
126
+ # Generate PDF
127
+ pdf_path = generate_pdf(response_content, candidate_name)
128
+
129
+ with open(pdf_path, "rb") as file:
130
+ btn = st.download_button(
131
+ label="Download Report as PDF",
132
+ data=file,
133
+ file_name=f"{candidate_name}_evaluation_report.pdf",
134
+ mime="application/octet-stream"
135
+ )