File size: 3,590 Bytes
60ca601
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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()