import gradio as gr import os import fitz from openai import AzureOpenAI import re # client = AzureOpenAI(api_key=os.getenv("AZURE_OPENAI_KEY"), # api_version="2023-07-01-preview", # azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT") # ) client = AzureOpenAI() 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': # Use PyMuPDF (fitz) for PDF text extraction doc = fitz.open(file_path) extracted_text = "" for page in doc: extracted_text += page.get_text() doc.close() return extracted_text 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_path, resume_list_path): 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) # Create a conversation for the OpenAI chat API conversation = [ {"role": "system", "content": "You are a Mental Healthcare Chatbot."}, {"role": "user", "content": 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]%.\n Qualification Matching Percentage: [matching percentage between job description and resume qualifications].\n Skills Matching Percentage: [matching percentage between job description and resume skills].\n Experience Matching Percentage: [matching percentage between job description and resume experience].\n Reason : [Reasons for why this resume matched and not matched.].\n 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.].\n Keywords : [Return the matched keywords from resume and job_description. If there are no matches, simply say N/A.]\n Company : [Extracted company name from job description].\n Irrevelant: [mention the irrevelant skills and expericence]\n Recommend Course: [mention specific course to recommend the candidate for job description needs].\n Experience: [mention specific experience to recommend the candidate for job description needs].\n Tailor Your Application: [Emphasize relevant areas].\n Certifications: [Pursue certifications in mention area].\n Feel free to contact us for further clarification.\n 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."""} ] # Call OpenAI GPT-3.5-turbo chat_completion = client.chat.completions.create( model = "GPT-3", messages = conversation, max_tokens=700, temperature=0 ) response = chat_completion.choices[0].message.content result += response + "\n-------------------------------------------------------------------------------------\n" return result def clear(self,jobDescription,resume,result_email): jobDescription = None resume = None result_email = None return jobDescription, resume, result_email def gradio_interface(self): with gr.Blocks(css="style.css",theme='freddyaboulton/test-blue') 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) analyse.click(self.responce_from_ai, [jobDescription, resume], [result_email]) clear_btn.click(self.clear,[jobDescription,resume,result_email],[jobDescription,resume,result_email] ) app.launch() if __name__ == "__main__": resume = ResumeAnalyser() answer = resume.gradio_interface()