Spaces:
Runtime error
Runtime error
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() |