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("""