Spaces:
Sleeping
Sleeping
File size: 3,256 Bytes
c1ae082 91ec250 c1ae082 91ec250 09b79a1 91ec250 c1ae082 09b79a1 c693b05 91ec250 c1ae082 c20b0a2 c1ae082 c693b05 09b79a1 740775e 91ec250 c1ae082 c20b0a2 c1ae082 c693b05 3256b49 33290c4 c693b05 c1ae082 c693b05 33290c4 c693b05 33290c4 c693b05 33290c4 91ec250 5e45ce5 91ec250 204508e 91ec250 33290c4 91ec250 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
import io
import os
from typing import Union
import gradio as gr
from gradio_pdf import PDF
from dotenv import load_dotenv
load_dotenv()
from resume_parser import ResumeParser, StructuredResumeParser, pdf_to_string
from resume_template import Resume
from pathlib import Path
def parse_resume(resume_data:Union[bytes, str], use_openai=False, openai_key=""):
p = StructuredResumeParser(use_openai, openai_key)
resume_text = pdf_to_string(resume_data)
resume = p.extract_resume_fields(resume_text)
if isinstance(resume, Resume):
resume = resume.json()
return resume
def match_resume_job(resume_data:Union[bytes, str], job_text, use_openai=False, openai_key=""):
p = StructuredResumeParser(use_openai, openai_key)
resume_text = pdf_to_string(resume_data)
res = p.match_resume_with_job_description(resume_text, job_text)
return res
def change_openai_checkbox(openai_key:str):
if openai_key.startswith("sk-") or "OPENAI_API_KEY" in os.environ:
return gr.Checkbox(label="Use OpenAI", interactive=True)
else:
return gr.Checkbox(label="Use OpenAI", interactive=False, value=False)
with gr.Blocks() as demo:
with gr.Tab(label="Parser"):
with gr.Row():
with gr.Column():
#pdf_file_txt = PDF(label="Resume File (pdf)", interactive=True)
pdf_file_txt = gr.File(label="Resume File (pdf)", type='binary', interactive=True)
use_openai_chk = change_openai_checkbox("")
openai_key_txt = gr.Text(label="OpenAI Token", placeholder="openAI token or env[OPENAI_API_KEY]")
parse_btn = gr.Button("Parse Resume")
with gr.Column():
parse_out_txt = gr.JSON(label="Structured Output")
examples0 = gr.Examples(examples=[[f"samples/{fname}"] for fname in os.listdir("samples") if fname.endswith(".pdf")],
inputs=[pdf_file_txt])
with gr.Tab(label="Job Matcher"):
with gr.Row():
with gr.Column():
job_file_txt = gr.Text(label="Job Description", interactive=True)
match_btn = gr.Button("Match Resume")
with gr.Column():
match_out_txt = gr.Text(label="Match Output")
examples1 = gr.Examples(
examples=[[Path(f"samples/jobs/{fname}").read_text()] for fname in os.listdir("samples/jobs") if fname.endswith(".txt")],
inputs=[job_file_txt])
clear_btn = gr.ClearButton(components=[pdf_file_txt, use_openai_chk, openai_key_txt, parse_out_txt, job_file_txt, match_out_txt])
openai_key_txt.change(change_openai_checkbox, inputs=openai_key_txt, outputs=use_openai_chk)
parse_btn.click(parse_resume, inputs=[pdf_file_txt, use_openai_chk, openai_key_txt], outputs=[parse_out_txt])
match_btn.click(match_resume_job, inputs=[pdf_file_txt, job_file_txt, use_openai_chk, openai_key_txt], outputs=[match_out_txt])
'''
demo = gr.Interface(
fn=parse_resume,
inputs=[PDF(label="Upload a PDF", interactive=True), gr.Checkbox(label="Use OpenAI"), gr.Text(label="OpenAI Token")],
outputs=[gr.JSON()],
examples=[[f"samples/{fname}"] for fname in os.listdir("samples") if fname.endswith(".pdf")]
)
'''
demo.launch() |