Spaces:
Runtime error
Runtime error
from dotenv import load_dotenv | |
load_dotenv() | |
import streamlit as st | |
import os | |
import io | |
import base64 | |
from PIL import Image | |
import pdf2image | |
from PyPDF2 import PdfReader | |
import google.generativeai as genai | |
from langchain.text_splitter import RecursiveCharacterTextSplitter | |
from langchain.vectorstores import FAISS, Chroma | |
from langchain.chains.question_answering import load_qa_chain | |
from langchain.embeddings.openai import OpenAIEmbeddings | |
from langchain.prompts import PromptTemplate | |
from openai import OpenAI | |
client = OpenAI() | |
#read pdf | |
def get_pdf_text(pdf_docs): | |
text="" | |
for pdf in pdf_docs: | |
pdf_reader= PdfReader(pdf) | |
for page in pdf_reader.pages: | |
text+= page.extract_text() | |
return text | |
#divide pdf text into overlapping chunks | |
def get_text_chunks(text): | |
text_splitter = RecursiveCharacterTextSplitter(chunk_size = 30, chunk_overlap=5) | |
chunks = text_splitter.split_text(text) | |
return chunks | |
#convert chunks to embeddings | |
def get_vector_store(text_chunks): | |
embeddings = OpenAIEmbeddings() | |
vector_store = FAISS.from_texts(text_chunks, embedding=embeddings) | |
#vector stores can be stored locally or even in a database | |
vector_store.save_local("faiss_index") | |
def get_openai_response(prompt): | |
completion = client.chat.completions.create( | |
model="gpt-3.5-turbo", # or other available engines | |
messages=[ | |
{"role": "user", "content": prompt} | |
] | |
) | |
return completion.choices[0].message.content | |
def main(): | |
st.set_page_config(page_title="Personal ATS") | |
st.header("ATS Keyword Matching") | |
input_text_title = st.text_area("Job Title: ", key="inpu_title") | |
input_text_jd = st.text_area("Job Description: ", key="input_jd") | |
pdf_docs = st.file_uploader("Upload Resume (pdf)", accept_multiple_files=True) | |
submit1 = st.button("Tell me about the resume") | |
submit2 = st.button("Percentage Match") | |
input_prompt1 = """ | |
You are an experienced Technical Human Resource Manager experienced in the field of {}, your task is to review the provided resume against the job description. | |
Please share your professional evaluation on whether the candidate's profile aligns with the role. | |
Highlight the strengths and weaknesses of the applicant in relation to the specified job requirements. | |
Resume: {} | |
Job Description: {} | |
""" | |
input_prompt2 = """ | |
You are an skilled ATS (Applicant Tracking System) scanner with a deep understanding in the field of {}, | |
your task is to evaluate the resume against the provided job description. You should output first the percentage of match between the resume and | |
the job description, followed by keywords matching, keywords missing and lastly your final thoughts. | |
Resume: {} | |
Job Description: {} | |
""" | |
if submit1: | |
if pdf_docs is not None: | |
pdf_content = get_pdf_text(pdf_docs) | |
prompt = input_prompt1.format(input_text_title, pdf_content, input_text_jd) | |
response = get_openai_response(prompt) | |
st.subheader("Response: ") | |
st.write(response) | |
else: | |
st.write("Please upload resume") | |
elif submit2: | |
if pdf_docs is not None: | |
pdf_content = get_pdf_text(pdf_docs) | |
prompt = input_prompt2.format(input_text_title, pdf_content, input_text_jd) | |
response = get_openai_response(prompt) | |
st.subheader("Response: ") | |
st.write(response) | |
else: | |
st.write("Please upload resume") | |
if __name__ == "__main__": | |
main() |