import gradio as gr import os import openai import re import PyPDF2 import plotly.graph_objects as go class ResumeAnalyser: def __init__(self): pass def extract_text_from_file(self, file_path): # Get the file extension file_extension = os.path.splitext(file_path)[1] if file_extension == '.pdf': text = "" try: with open(file_path, "rb") as pdf_file: pdf_reader = PyPDF2.PdfReader(pdf_file) num_pages = len(pdf_reader.pages) for page_num in range(num_pages): page = pdf_reader.pages[page_num] text += page.extract_text() return text except Exception as e: return str(e) elif file_extension == '.txt': with open(file_path, 'r') as file: # Just read the entire contents of the text file return file.read() else: return "Unsupported file type" def responce_from_ai(self,job_description, resume): response = openai.Completion.create( engine = "text-davinci-003", prompt = f""" 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} **Detailed Analysis:** Introduction to say we've assessment the resume the result should be in this format: Matched Percentage: Precisely [get matching percentage between job description and resume]%. Qualification Matching Percentage: [matching percentage between job description and resume qualifications]. Skills Matching Percentage: [matching percentage between job description and resume skills]. Experience Matching Percentage: [matching percentage between job description and resume experience]. Reason : [Reasons for why this resume matched and not matched.]. 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.]. Keywords : [Return the matched keywords from resume and job_description. If there are no matches, simply say N/A.] Company : [Extracted company name from job description]. Irrevelant: [mention the Irrevelant skills and expericence] Recommend Course: [mention specific course to recommend the candidate for job description needs]. Experience: [mention specific experience to recommend the candidate for job description needs]. Tailor Your Application: [Emphasize relevant areas]. Certifications: [Pursue certifications in mention area]. Feel free to contact us for further clarification. Best wishes, 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. """, temperature=0, max_tokens=1000, stop=None, ) generated_text = response.choices[0].text.strip() # result += generated_text + "\n-------------------------------------------------------------------------------------\n" return generated_text def clear(self,jobDescription,resume,result_email): jobDescription = None resume = None result_email = None return jobDescription, resume, result_email def main(self,job_description_path, resume_list_path): tot_result = "" print(tot_result) job_description = self.extract_text_from_file(job_description_path.name) for resume_path in resume_list_path: resume = self.extract_text_from_file(resume_path.name) result = self.responce_from_ai(job_description,resume) tot_result = tot_result + result + "\n-------------------------------------------------------------------------------------\n" # lines = tot_result.split('\n') # for line in lines: # matched_percentage = re.search(r"Matched Percentage: Precisely (\d+)%\.", result) # if matched_percentage: # matched_percentage = int(matched_percentage.group(1)) # # Creating a pie chart with plotly # labels = ['Matched', 'Remaining'] # values = [matched_percentage, 100 - matched_percentage] # fig = go.Figure(data=[go.Pie(labels=labels, values=values)]) return tot_result def gradio_interface(self): with gr.Blocks(css="style.css",theme='karthikeyan-adople/hudsonhayes-gray') as app: gr.HTML("""


Candidate Assessment and Communication

""") with gr.Row(elem_id="col-container"): with gr.Column(scale=0.55, min_width=150, ): jobDescription = gr.File(label="Job Description", file_types = [".pdf",".txt"]) with gr.Column(scale=0.55, min_width=150): resume = gr.File(label="Resume", file_types = [".pdf",".txt"] , file_count="multiple") with gr.Row(elem_id="col-container"): with gr.Column(scale=0.80, min_width=150): analyse = gr.Button("Analyse") with gr.Column(scale=0.20, min_width=150): clear_btn = gr.ClearButton() with gr.Row(elem_id="col-container"): with gr.Column(scale=1.0, min_width=150): result_email = gr.Textbox(label="E-mail", lines=10) # with gr.Row(elem_id="col-container"): # with gr.Column(scale=0.50, min_width=150): # pychart = gr.Plot(label="Matching Percentage Chart") analyse.click(self.main, [jobDescription, resume], [result_email]) clear_btn.click(self.clear,[jobDescription,resume,result_email],[jobDescription,resume,result_email] ) app.launch(debug = True) if __name__ == "__main__": resume = ResumeAnalyser() answer = resume.gradio_interface()