HR-GPT / app.py
waloneai's picture
Update app.py
5a4a17c verified
import openai
import os
from paperqa import Docs
import gradio as gr
from langchain.document_loaders import PyPDFLoader
from langchain.vectorstores import Chroma
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.document_loaders import UnstructuredPDFLoader
from langchain.llms import OpenAI
from langchain.chains.question_answering import load_qa_chain
from langchain.chat_models import ChatOpenAI
# Set your OpenAI API key here
OPENAI_API_KEY = 'sk-proj-'
os.environ['OPENAI_API_KEY'] = OPENAI_API_KEY
css_style = """
.gradio-container {
font-family: "IBM Plex Mono";
}
.answerText p {
font-size: 24px !important;
color: #8dbcfe !important;
}
"""
def run(uploaded_files):
all_files = []
if uploaded_files is None:
return all_files
for file in uploaded_files:
if file.name.endswith('.pdf'):
all_files.append(file.name)
print(f"File uploaded: {file.name}, Size: {file.size} bytes")
return all_files
def createAnswer(files, designation):
# Initialize the Docs object with the OpenAI API key
docs = Docs(llm='gpt-3.5-turbo')
# Add the uploaded files to the Docs object
for d in files:
try:
docs.add(d.name)
print(f"Successfully added file: {d.name}")
except Exception as e:
print(f"Error adding file {d.name}: {e}")
return f"Error reading file {d.name}. Please ensure the file is not empty or corrupted."
# Query the documents to find the best candidate for the given designation
answer = docs.query(
f"Who is the best candidate to hire for {designation}. Provide a list with the candidate name. If you don't know, simply say None of the candidates are suited for the Job role."
)
print(answer.formatted_answer)
print(type(answer))
return answer.answer
with gr.Blocks(css=css_style) as demo:
gr.Markdown(f"""
# HR-GPT - Filter & Find The Best Candidate for the Job using AI
*By Amin Memon ([@AminMemon](https://twitter.com/AminMemon))*
This tool will enable asking questions of your uploaded text, PDF documents,.
It uses OpenAI's ChatGPT model & OpenAI Embeddings and thus you must enter your API key below.
This tool is under active development and currently uses many tokens - up to 10,000
for a single query. That is $0.10-0.20 per query, so please be careful!
Porting it to Llama.cpp soon for saved cost.
1. Upload your Resumes (Try a few resumes/cv to try < 5)
2. Provide Designation for which you are hiring
""")
position = gr.Text(
label='Position/Designation for which you are hiring for', value="")
with gr.Tab('File Upload'):
uploaded_files = gr.File(
label="Resume Upload - ONLY PDF. (Doc File Support Coming Soon)", file_count="multiple", show_progress=True)
uploaded_files.change(
fn=run, inputs=[uploaded_files], outputs=[uploaded_files])
ask = gr.Button("Find Top Candidate")
answer = gr.Markdown(label="Result", elem_classes='answerText')
ask.click(fn=createAnswer, inputs=[
uploaded_files, position], outputs=[answer])
demo.queue(concurrency_count=20)
demo.launch(show_error=True)