import os from openai import AzureOpenAI import PyPDF2 import gradio as gr import docx import re class Resume_Overall: def __init__(self): self.client = AzureOpenAI(api_key=os.getenv("AZURE_OPENAI_KEY"), api_version="2023-07-01-preview", azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT") ) def extract_text_from_file(self,file_path): # Get the file extension file_extension = os.path.splitext(file_path)[1] if file_extension == '.pdf': with open(file_path, 'rb') as file: # Create a PDF file reader object reader = PyPDF2.PdfFileReader(file) # Create an empty string to hold the extracted text extracted_text = "" # Loop through each page in the PDF and extract the text for page_number in range(reader.getNumPages()): page = reader.getPage(page_number) extracted_text += page.extractText() 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() elif file_extension == '.docx': doc = docx.Document(file_path) text = [] for paragraph in doc.paragraphs: text.append(paragraph.text) return '\n'.join(text) else: return "Unsupported file type" def course_response(self,resume_path): resume_path = resume_path.name resume = self.extract_text_from_file(resume_path) # Define the prompt or input for the model conversation = [ {"role": "system", "content": "You are a Resume Assistant."}, {"role": "user", "content": f"""Analyze the resume to generate online courses with website links to improve skills following resume delimitted by triple backticks. Generate atmost five courses. result format should be: course:[course]. website link:[website link] ```{resume}``` """} ] # Generate a response from the GPT-3 model chat_completion = self.client.chat.completions.create( model = "GPT-3", messages = conversation, max_tokens=200, temperature=0, n=1, stop=None, ) # Extract the generated text from the API response generated_text = chat_completion.choices[0].message.content return generated_text def summary_response(self,resume_path): resume_path = resume_path.name resume = self.extract_text_from_file(resume_path) # Define the prompt or input for the model conversation = [ {"role": "system", "content": "You are a Resume Summarizer."}, {"role": "user", "content": f"""Analyze the resume to write the summary for following resume delimitted by triple backticks. ```{resume}``` """} ] # Generate a response from the GPT-3 model chat_completion = self.client.chat.completions.create( model = "GPT-3", messages = conversation, max_tokens=200, temperature=0, n=1, stop=None, ) # Extract the generated text from the API response generated_text = chat_completion.choices[0].message.content return generated_text def skill_response(self,job_description_path): job_description_path = job_description_path.name resume = self.extract_text_from_file(job_description_path) # Define the prompt or input for the model conversation = [ {"role": "system", "content": "You are a Resume Assistant."}, {"role": "user", "content": f"""Find Education Gaps in given resume. Find Skills in resume. ```{resume}``` """} ] # Generate a response from the GPT-3 model chat_completion = self.client.chat.completions.create( model = "GPT-3", # Choose the GPT-3 engine you want to use messages = conversation, max_tokens=100, # Set the maximum number of tokens in the generated response temperature=0, # Controls the randomness of the output. Higher values = more random, lower values = more focused n=1, # Generate a single response stop=None, # Specify an optional stop sequence to limit the length of the response ) # Extract the generated text from the API response generated_text = chat_completion.choices[0].message.content return generated_text def _generate_job_list(self, resume: str) -> str: conversation = [ {"role": "system", "content": "You are a Resume Assistant."}, {"role": "user", "content": f"List out perfect job roles for based on resume informations:{resume}"} ] chat_completion = self.client.chat.completions.create( model = "GPT-3", messages = conversation, max_tokens=100, temperature=0, n=1, stop=None, ) generated_text = chat_completion.choices[0].message.content return generated_text def job_list_interface(self, file) -> str: resume_text = self.extract_text_from_file(file.name) job_list = self._generate_job_list(resume_text) return job_list def generate_job_description(self, role, experience): # Generate a response from the GPT-3 model conversation = [ {"role": "system", "content": "You are a Resume Assistant."}, {"role": "user", "content": f"""Your task is generate Job description for this {role} with {experience} years of experience. Job Description Must have 1. Job Title 2. Job Summary : [200 words] 3. Responsibilities : Five Responsibilities in five lines 4. Required Skills : Six Skills 5. Qualifications These topics must have in that Generated Job Description. """} ] chat_completion = self.client.chat.completions.create( model = "GPT-3", # Choose the GPT-3 engine you want to use messages = conversation, max_tokens=500, # Set the maximum number of tokens in the generated response temperature=0.5, # Controls the randomness of the output. Higher values = more random, lower values = more focused ) # Extract the generated text from the API response generated_text = chat_completion.choices[0].message.content return generated_text def response(self,job_description_path): job_description_path = job_description_path.name job_description = self.extract_text_from_file(job_description_path) # Define the prompt or input for the model conversation = [ {"role": "system", "content": "You are a Resume Assistant."}, {"role": "user", "content": f"""Generate interview questions for screening following job_description delimitted by triple backticks. Generate atmost ten questions. ```{job_description}``` """} ] # Generate a response from the GPT-3 model chat_completion = self.client.chat.completions.create( model = "GPT-3", # Choose the GPT-3 engine you want to use messages = conversation, max_tokens=200, # Set the maximum number of tokens in the generated response temperature=0, # Controls the randomness of the output. Higher values = more random, lower values = more focused n=1, # Generate a single response stop=None, # Specify an optional stop sequence to limit the length of the response ) # Extract the generated text from the API response generated_text = chat_completion.choices[0].message.content return generated_text def show_file(self,file_path): return file_path.name def launch_gradio_interface(self, share: bool = True): with gr.Blocks(css="style.css",theme='freddyaboulton/test-blue') as app: gr.HTML("""