|
import os |
|
import openai |
|
import PyPDF2 |
|
import gradio as gr |
|
import docx |
|
import re |
|
import plotly.graph_objects as go |
|
|
|
class Resume_Overall: |
|
def __init__(self): |
|
pass |
|
|
|
def extract_text_from_file(self,file_path): |
|
|
|
file_extension = os.path.splitext(file_path)[1] |
|
|
|
if file_extension == '.pdf': |
|
with open(file_path, 'rb') as file: |
|
|
|
reader = PyPDF2.PdfFileReader(file) |
|
|
|
|
|
extracted_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: |
|
|
|
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) |
|
|
|
|
|
|
|
prompt = 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}``` |
|
""" |
|
|
|
|
|
response = openai.Completion.create( |
|
engine='text-davinci-003', |
|
prompt=prompt, |
|
max_tokens=200, |
|
temperature=0, |
|
n=1, |
|
stop=None, |
|
) |
|
|
|
|
|
generated_text = response.choices[0].text.strip() |
|
|
|
return generated_text |
|
def summary_response(self,resume_path): |
|
resume_path = resume_path.name |
|
resume = self.extract_text_from_file(resume_path) |
|
|
|
|
|
|
|
prompt = f"""Analyze the resume to write the summary for following resume delimitted by triple backticks. |
|
```{resume}``` |
|
""" |
|
|
|
|
|
response = openai.Completion.create( |
|
engine='text-davinci-003', |
|
prompt=prompt, |
|
max_tokens=200, |
|
temperature=0, |
|
n=1, |
|
stop=None, |
|
) |
|
|
|
|
|
generated_text = response.choices[0].text.strip() |
|
|
|
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) |
|
|
|
|
|
|
|
prompt = f"""Find Education Gaps in given resume. Find Skills in resume. |
|
```{resume}``` |
|
""" |
|
|
|
|
|
response = openai.Completion.create( |
|
engine='text-davinci-003', |
|
prompt=prompt, |
|
max_tokens=100, |
|
temperature=0, |
|
n=1, |
|
stop=None, |
|
) |
|
|
|
|
|
generated_text = response.choices[0].text.strip() |
|
|
|
return generated_text |
|
|
|
def _generate_job_list(self, resume: str) -> str: |
|
prompt = f"List out perfect job roles for based on resume informations:{resume}" |
|
response = openai.Completion.create( |
|
engine='text-davinci-003', |
|
prompt=prompt, |
|
max_tokens=100, |
|
temperature=0, |
|
n=1, |
|
stop=None, |
|
) |
|
generated_text = response.choices[0].text.strip() |
|
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 show_file(self,file_path): |
|
return file_path.name |
|
|
|
def launch_gradio_interface(self, share: bool = True): |
|
with gr.Blocks(css="style.css",theme='karthikeyan-adople/hudsonhayes-gray') as app: |
|
with gr.Tabs("Resume"): |
|
with gr.Row(): |
|
with gr.Column(elem_id="col-container"): |
|
gr.HTML("""<center><h1>Resume</h1></center>""") |
|
file_output = gr.File(elem_classes="filenameshow") |
|
upload_button = gr.UploadButton( |
|
"Browse File",file_types=[".txt", ".pdf", ".doc", ".docx",".json",".csv"], |
|
elem_classes="filenameshow") |
|
with gr.TabItem("Designation"): |
|
btn = gr.Button(value="Submit") |
|
output_text = gr.Textbox(label="Designation List") |
|
with gr.TabItem("Summarized"): |
|
analyse = gr.Button("Analyze") |
|
summary_result = gr.Textbox(label="Summarized",lines=8) |
|
with gr.TabItem("Skills and Education Gaps"): |
|
analyse_resume = gr.Button("Analyze Resume") |
|
result = gr.Textbox(label="Skills and Education Gaps",lines=8) |
|
with gr.TabItem("Course"): |
|
course_analyse = gr.Button("Find Courses") |
|
course_result = gr.Textbox(label="Suggested Cources",lines=8) |
|
|
|
upload_button.upload(self.show_file,upload_button,file_output) |
|
course_analyse.click(self.course_response, [upload_button], course_result) |
|
analyse_resume.click(self.skill_response, [upload_button], result) |
|
btn.click(self.job_list_interface, upload_button, output_text) |
|
analyse.click(self.summary_response, [upload_button], summary_result) |
|
with gr.Tabs("Job Description"): |
|
with gr.Row(): |
|
with gr.Column(elem_id="col-container"): |
|
gr.HTML("""<center><h1>Resume</h1></center>""") |
|
file_output = gr.File(elem_classes="filenameshow") |
|
upload_button = gr.UploadButton( |
|
"Browse File",file_types=[".txt", ".pdf", ".doc", ".docx",".json",".csv"], |
|
elem_classes="filenameshow") |
|
with gr.TabItem("Designation"): |
|
btn = gr.Button(value="Submit") |
|
output_text = gr.Textbox(label="Designation List") |
|
|
|
app.launch(debug=True) |
|
|
|
if __name__ == "__main__": |
|
resume_overall = Resume_Overall() |
|
resume_overall.launch_gradio_interface() |