Commit ·
dbbe0f5
1
Parent(s): e5ec092
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import fitz
|
| 3 |
+
import os
|
| 4 |
+
import openai
|
| 5 |
+
import re
|
| 6 |
+
import PyPDF2
|
| 7 |
+
|
| 8 |
+
class ResumeAnalyser:
|
| 9 |
+
def __init__(self):
|
| 10 |
+
pass
|
| 11 |
+
def extract_text_from_file(self, file_path):
|
| 12 |
+
# Get the file extension
|
| 13 |
+
file_extension = os.path.splitext(file_path)[1]
|
| 14 |
+
|
| 15 |
+
if file_extension == '.pdf':
|
| 16 |
+
text = ""
|
| 17 |
+
try:
|
| 18 |
+
with open(file_path, "rb") as pdf_file:
|
| 19 |
+
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
| 20 |
+
num_pages = len(pdf_reader.pages)
|
| 21 |
+
|
| 22 |
+
for page_num in range(num_pages):
|
| 23 |
+
page = pdf_reader.pages[page_num]
|
| 24 |
+
text += page.extract_text()
|
| 25 |
+
|
| 26 |
+
return text
|
| 27 |
+
except Exception as e:
|
| 28 |
+
return str(e)
|
| 29 |
+
|
| 30 |
+
elif file_extension == '.txt':
|
| 31 |
+
with open(file_path, 'r') as file:
|
| 32 |
+
# Just read the entire contents of the text file
|
| 33 |
+
return file.read()
|
| 34 |
+
else:
|
| 35 |
+
return "Unsupported file type"
|
| 36 |
+
|
| 37 |
+
def responce_from_ai(self,job_description, resume):
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
response = openai.Completion.create(
|
| 42 |
+
engine = "text-davinci-003",
|
| 43 |
+
prompt = f"""
|
| 44 |
+
Given the job description and the resume, assess the matching percentage to 100 and if 100 percentage not matched mention the remaining percentage with reason. **Job Description:**{job_description}**Resume:**{resume}
|
| 45 |
+
**Detailed Analysis:**
|
| 46 |
+
Introduction to say we've assessment the resume
|
| 47 |
+
the result should be in this format:
|
| 48 |
+
Matched Percentage: Precisely [get matching percentage between job description and resume]%.
|
| 49 |
+
Qualification Matching Percentage: [matching percentage between job description and resume qualifications].
|
| 50 |
+
Skills Matching Percentage: [matching percentage between job description and resume skills].
|
| 51 |
+
Experience Matching Percentage: [matching percentage between job description and resume experience].
|
| 52 |
+
Reason : [Reasons for why this resume matched and not matched.].
|
| 53 |
+
Skills To Improve : [Mention the skills to improve for the candidate according to the given job description. If there are no matches, simply say N/A.].
|
| 54 |
+
Keywords : [Return the matched keywords from resume and job_description. If there are no matches, simply say N/A.]
|
| 55 |
+
Company : [Extracted company name from job description].
|
| 56 |
+
Irrevelant: [mention the Irrevelant skills and expericence]
|
| 57 |
+
Recommend Course: [mention specific course to recommend the candidate for job description needs].
|
| 58 |
+
Experience: [mention specific experience to recommend the candidate for job description needs].
|
| 59 |
+
Tailor Your Application: [Emphasize relevant areas].
|
| 60 |
+
Certifications: [Pursue certifications in mention area].
|
| 61 |
+
Feel free to contact us for further clarification.
|
| 62 |
+
Best wishes,
|
| 63 |
+
Your job is to write a proper E-Mail to the candidate from the organization with the job role, the candidate's name, organization name, and the body of this E-Mail should be in the above format.
|
| 64 |
+
""",
|
| 65 |
+
temperature=0,
|
| 66 |
+
max_tokens=1000,
|
| 67 |
+
stop=None,
|
| 68 |
+
)
|
| 69 |
+
generated_text = response.choices[0].text.strip()
|
| 70 |
+
# result += generated_text + "\n-------------------------------------------------------------------------------------\n"
|
| 71 |
+
lines = result.split('\n')
|
| 72 |
+
for line in lines:
|
| 73 |
+
matched_percentage = re.search(r"Matched Percentage: Precisely (\d+)%\.", result)
|
| 74 |
+
if matched_percentage:
|
| 75 |
+
matched_percentage = int(matched_percentage.group(1))
|
| 76 |
+
# Creating a pie chart with plotly
|
| 77 |
+
labels = ['Matched', 'Remaining']
|
| 78 |
+
values = [matched_percentage, 100 - matched_percentage]
|
| 79 |
+
|
| 80 |
+
fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
|
| 81 |
+
return generated_text, fig
|
| 82 |
+
|
| 83 |
+
def clear(self,jobDescription,resume,result_email):
|
| 84 |
+
jobDescription = None
|
| 85 |
+
resume = None
|
| 86 |
+
result_email = None
|
| 87 |
+
return jobDescription, resume, result_email
|
| 88 |
+
|
| 89 |
+
def main(self,job_description_path, resume_list_path):
|
| 90 |
+
|
| 91 |
+
tot_result = ""
|
| 92 |
+
print(tot_result)
|
| 93 |
+
job_description = self.extract_text_from_file(job_description_path.name)
|
| 94 |
+
for resume_path in resume_list_path:
|
| 95 |
+
resume = self.extract_text_from_file(resume_path.name)
|
| 96 |
+
result = self.responce_from_ai(job_description,resume)
|
| 97 |
+
tot_result = tot_result + result + "\n-------------------------------------------------------------------------------------\n"
|
| 98 |
+
return tot_result
|
| 99 |
+
|
| 100 |
+
def gradio_interface(self):
|
| 101 |
+
with gr.Blocks(css="style.css",theme='karthikeyan-adople/hudsonhayes-gray') as app:
|
| 102 |
+
gr.HTML("""<center class="darkblue" style='background-color:rgb(0,1,36); text-align:center;padding:25px;'><center><h1 class ="center">
|
| 103 |
+
<img src="file=logo.png" height="110px" width="280px"></h1></center>
|
| 104 |
+
<br><h1 style="color:#fff">Candidate Assessment and Communication</h1></center>""")
|
| 105 |
+
with gr.Row(elem_id="col-container"):
|
| 106 |
+
with gr.Column(scale=0.55, min_width=150, ):
|
| 107 |
+
jobDescription = gr.File(label="Job Description", file_types = [".pdf",".txt"])
|
| 108 |
+
with gr.Column(scale=0.55, min_width=150):
|
| 109 |
+
resume = gr.File(label="Resume", file_types = [".pdf",".txt"] , file_count="multiple")
|
| 110 |
+
with gr.Row(elem_id="col-container"):
|
| 111 |
+
with gr.Column(scale=0.80, min_width=150):
|
| 112 |
+
analyse = gr.Button("Analyse")
|
| 113 |
+
with gr.Column(scale=0.20, min_width=150):
|
| 114 |
+
clear_btn = gr.ClearButton()
|
| 115 |
+
with gr.Row(elem_id="col-container"):
|
| 116 |
+
with gr.Column(scale=1.0, min_width=150):
|
| 117 |
+
result_email = gr.Textbox(label="E-mail", lines=10)
|
| 118 |
+
with gr.Row():
|
| 119 |
+
with gr.Column(scale=0.50, min_width=150):
|
| 120 |
+
pychart = gr.Plot(label="Matching Percentage Chart")
|
| 121 |
+
analyse.click(self.main, [jobDescription, resume], [result_email,pychart])
|
| 122 |
+
clear_btn.click(self.clear,[jobDescription,resume,result_email],[jobDescription,resume,result_email] )
|
| 123 |
+
|
| 124 |
+
app.launch(debug = True)
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
resume = ResumeAnalyser()
|
| 128 |
+
answer = resume.gradio_interface()
|