import gradio as gr
import PyPDF2
import os
import openai
import re
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':
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()
else:
return "Unsupported file type"
def responce_from_ai(self,textjd, textcv):
resume = self.extract_text_from_file(textjd)
job_description = self.extract_text_from_file(textcv)
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:**
the result should be in this format:
Matched Percentage: [matching percentage].
Reason : [reason for Matched Percentage].
Skills To Improve : [Mention the skills to improve and get 100 percentage matching].
Keywords : [matched key words from {job_description} and {resume}].
""",
temperature=0,
max_tokens=100,
n=1,
stop=None,
)
generated_text = response.choices[0].text.strip()
print(generated_text)
return generated_text
def matching_percentage(self,job_description_path, resume_path):
job_description_path = job_description_path.name
resume_path = resume_path.name
generated_text = self.responce_from_ai(job_description_path, resume_path)
result = generated_text
match = re.search(r"(Matched Percentage: (.+))", result)
percentage = match.group(1)
match = re.search(r"(Reason: (.+))", result)
reason = match.group(1)
match = re.search(r"(Skills To Improve: (.+))", result)
skills = match.group(1)
match = re.search(r"(Keywords: (.+))", result)
keywords = match.group(1)
# Extract the matched percentage using regular expression
match1 = re.search(r"Matched Percentage: (\d+)%", percentage)
matched_percentage = int(match1.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)])
# fig.update_layout(title='Matched Percentage')
return percentage,reason, skills, keywords,fig
def gradio_interface(self):
with gr.Blocks(css="style.css",theme=gr.themes.Soft()) as app:
gr.HTML("""
""")
with gr.Row():
with gr.Column(elem_id="col-container"):
gr.HTML(
"""
"""
)
gr.HTML(
"""