Spaces:
Sleeping
Sleeping
import gradio as gr | |
import PyPDF2 | |
import os | |
import openai | |
def extract_text_from_file(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(textjd, textcv): | |
resume = extract_text_from_file(textjd) | |
job_description = 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 and approximate percentage of the resume for the job.**Job Description:**{job_description}**Resume:**{resume}**Matching Assessment:**Based on an analysis of the resume and the job description, | |
the overall matching percentage is estimated to be approximately [insert approximate percentage here]. | |
**Detailed Analysis:** | |
the result should be in this format: | |
matched percentage: [matching percentage] | |
reason : [reason for this result] | |
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() | |
return generated_text | |
def matching_percentage(job_description_path, resume_path): | |
job_description_path = job_description_path.name | |
resume_path = resume_path.name | |
generated_text = responce_from_ai(job_description_path, resume_path) | |
return generated_text | |
title = """<br><br><br><div style="text-align: center;max-width: 700px;"> | |
<h1><a style="display:inline-block; margin-left: 1em; text-decoration:none; font-weight:bold;" >Syngenta </a> - Resume Matching</h1> | |
</p>""" | |
with gr.Blocks(css="style.css",theme=gr.themes.Soft()) as app: | |
gr.HTML("""<center><img class="image" align="center" src="https://logos-download.com/wp-content/uploads/2016/06/Syngenta_logo.png" alt="Image" width="200" height="200"></center>""") | |
with gr.Row(): | |
with gr.Column(elem_id="col-container"): | |
gr.HTML(title) | |
with gr.Row(): | |
with gr.Column(scale=0.45, min_width=150, ): | |
jobDescription = gr.inputs.File(label="Job Description") | |
with gr.Column(scale=0.45, min_width=150): | |
resume = gr.inputs.File(label="Resume") | |
with gr.Column(scale=0.10, min_width=150): | |
find = gr.Button("Find") | |
with gr.Row(): | |
with gr.Column(scale=1.0, min_width=150): | |
output = gr.outputs.Textbox(label="Matching Percentage") | |
find.click(matching_percentage, [jobDescription, resume], [output]) | |
app.launch() | |