|
import gradio as gr |
|
import openai |
|
import PyPDF2 |
|
import os |
|
|
|
class JobListGenerator: |
|
def __init__(self): |
|
|
|
openai.api_key = os.getenv("OPENAI_API_KEY") |
|
self.engine = 'text-davinci-003' |
|
|
|
def _extract_text_from_pdf(self, file_path: str) -> str: |
|
with open(file_path, 'rb') as file: |
|
reader = PyPDF2.PdfReader(file) |
|
pdf_extract_text = "" |
|
for page in reader.pages: |
|
pdf_extract_text += page.extract_text() |
|
return pdf_extract_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=self.engine, |
|
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_pdf(file.name) |
|
job_list = self._generate_job_list(resume_text) |
|
return job_list |
|
|
|
def launch_gradio_interface(self, share: bool = True): |
|
with gr.Blocks(css="style.css", theme=gr.themes.Soft()) as app: |
|
gr.HTML("""<img class="leftimage" align="left" src="https://templates.images.credential.net/1612472097627370951721412474196.png" alt="Image" width="210" height="210"> |
|
<img class="rightimage" align="right" src="https://companieslogo.com/img/orig/RAND.AS_BIG-0f1935a4.png?t=1651813778" alt="Image" width="150" height="140">""") |
|
with gr.Row(): |
|
|
|
with gr.Column(elem_id="col-container"): |
|
gr.HTML("""<center><h1>Designation Finder</h1></center>""") |
|
input_file = gr.File(label="Upload Resume (PDF)") |
|
btn = gr.Button(value="Submit") |
|
output_text = gr.Textbox(label="Designation List") |
|
|
|
btn.click(self.job_list_interface, input_file, output_text) |
|
|
|
app.launch() |
|
job_list_generator = JobListGenerator() |
|
job_list_generator.launch_gradio_interface() |
|
|