Phaneendrabayi commited on
Commit
6547fc2
·
verified ·
1 Parent(s): fc8cab2

Upload 7 files

Browse files
Files changed (7) hide show
  1. ATS.py +126 -0
  2. PDF.py +94 -0
  3. chatbot.py +59 -0
  4. faiss_index/index.faiss +0 -0
  5. faiss_index/index.pkl +3 -0
  6. main.py +38 -0
  7. resume.py +74 -0
ATS.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64
2
+ import streamlit as st
3
+ import os
4
+ import io
5
+ import pdf2image
6
+ import google.generativeai as genai
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv()
10
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
11
+
12
+
13
+ def get_gemini_response(input, pdf_content, prompt):
14
+ model = genai.GenerativeModel('gemini-pro-vision')
15
+ response = model.generate_content([input, pdf_content[0], prompt])
16
+ return response.text
17
+
18
+
19
+ def input_pdf_setup(uploaded_file):
20
+ if uploaded_file is not None:
21
+ ## Convert the PDF to image
22
+ images = pdf2image.convert_from_bytes(uploaded_file.read())
23
+
24
+ first_page = images[0]
25
+
26
+ # Convert to bytes
27
+ img_byte_arr = io.BytesIO()
28
+ first_page.save(img_byte_arr, format='JPEG')
29
+ img_byte_arr = img_byte_arr.getvalue()
30
+
31
+ pdf_parts = [
32
+ {
33
+ "mime_type": "image/jpeg",
34
+ "data": base64.b64encode(img_byte_arr).decode() # encode to base64
35
+ }
36
+ ]
37
+ return pdf_parts
38
+ else:
39
+ raise FileNotFoundError("No file uploaded")
40
+
41
+
42
+ ## Streamlit App
43
+ def app():
44
+ #st.set_page_config(page_icon="img.png", page_title="ATS Resume Expert")
45
+ st.header("ATS Tracking System")
46
+ input_text = st.text_area("Job Description: ", key="input")
47
+ uploaded_file = st.file_uploader("Upload your resume(PDF)...", type="pdf")
48
+
49
+ if uploaded_file is not None:
50
+ st.write("PDF Uploaded Successfully")
51
+
52
+ submit1 = st.button("Tell Me About the Resume")
53
+
54
+ submit2 = st.button("How Can I Improvise my Skills")
55
+
56
+ submit3 = st.button("Percentage match")
57
+
58
+ submit4 = st.button("What are the keywords that are missing ")
59
+
60
+ input_prompt1 = """
61
+ You are an experienced Technical Human Resource Manager,your task is to review the provided resume against the job
62
+ description. Please share your professional evaluation on whether the candidate's profile aligns with the role.
63
+ Highlight the strengths and weaknesses of the applicant in relation to the specified job requirements.
64
+ """
65
+
66
+ input_prompt2 = """
67
+ You are an skilled ATS (Applicant Tracking System) scanner with a deep understanding of data science,machine learning ,
68
+ AI,Data analyist and ATS functionality,your task is to review the provided resume against the job description.Please
69
+ share your professional evaluation on how the candidate's Can Improve the skills with the role. Highlight the keypoints
70
+ how the candidate can improve the skills in relation to the specified job requirements
71
+ """
72
+
73
+ input_prompt3 = """
74
+ You are an skilled ATS (Applicant Tracking System) scanner with a deep understanding of data science
75
+ and ATS functionality, your task is to evaluate the resume against the provided job description. give me the percentage
76
+ of match if the resume matchesthe job description. First the output should come as percentage and then keywords missing
77
+ and last final thoughts.
78
+ """
79
+
80
+ input_prompt4 = """
81
+ You are an skilled ATS (Applicant Tracking System) scanner with a deep understanding of data science
82
+ and ATS functionality,your task is to evaluate the resume against the provided job description. give me the missing
83
+ keywords and matching keywords of resume and if the resume matchesappreciate the candidate in front of HR by explaining
84
+ the projects Candidate have done in the past.the job description.First the output should come as percentage and then
85
+ keywords missing and last final thoughts
86
+ """
87
+
88
+ if submit1:
89
+ if uploaded_file is not None:
90
+ pdf_content = input_pdf_setup(uploaded_file)
91
+ response = get_gemini_response(input_prompt1, pdf_content, input_text)
92
+ st.subheader("The Repsonse is")
93
+ st.write(response)
94
+ else:
95
+ st.write("Please uplaod the resume")
96
+
97
+ elif submit2:
98
+ if uploaded_file is not None:
99
+ pdf_content = input_pdf_setup(uploaded_file)
100
+ response = get_gemini_response(input_prompt2, pdf_content, input_text)
101
+ st.subheader("The Repsonse is")
102
+ st.write(response)
103
+ else:
104
+ st.write("Please uplaod the resume")
105
+
106
+ elif submit3:
107
+ if uploaded_file is not None:
108
+ pdf_content = input_pdf_setup(uploaded_file)
109
+ response = get_gemini_response(input_prompt3, pdf_content, input_text)
110
+ st.subheader("The Repsonse is")
111
+ st.write(response)
112
+ else:
113
+ st.write("Please uplaod the resume")
114
+
115
+
116
+ elif submit4:
117
+ if uploaded_file is not None:
118
+ pdf_content = input_pdf_setup(uploaded_file)
119
+ response = get_gemini_response(input_prompt4, pdf_content, input_text)
120
+ st.subheader("The Repsonse is")
121
+ st.write(response)
122
+ else:
123
+ st.write("Please uplaod the resume")
124
+
125
+ if __name__ == "__main__":
126
+ app()
PDF.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Importing all the necessary libraries
2
+ import streamlit as st
3
+ from PyPDF2 import PdfReader
4
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
5
+ import os
6
+ from langchain_google_genai import GoogleGenerativeAIEmbeddings, ChatGoogleGenerativeAI
7
+ import google.generativeai as genai
8
+ from langchain_community.vectorstores import FAISS
9
+ from langchain.chains.question_answering import load_qa_chain
10
+ from langchain.prompts import PromptTemplate
11
+ from dotenv import load_dotenv
12
+
13
+ # Load the API Key
14
+ load_dotenv()
15
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
16
+
17
+
18
+ # Creating a function for reading PDF File
19
+ def read_pdf(pdf):
20
+ text = ""
21
+ for file in pdf:
22
+ pdf_read = PdfReader(file)
23
+ for page in pdf_read.pages:
24
+ text += page.extract_text()
25
+ return text
26
+
27
+
28
+ # Document Chunking
29
+ def get_chunks(text):
30
+ text_splitter = RecursiveCharacterTextSplitter(chunk_size=100000, chunk_overlap=10000)
31
+ chunks = text_splitter.split_text(text)
32
+ return chunks
33
+
34
+
35
+ # Create Embedding Store
36
+ def get_vector_store(text_chunks):
37
+ embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
38
+ vector_store = FAISS.from_texts(text_chunks, embedding=embeddings)
39
+ vector_store.save_local("faiss_index")
40
+
41
+
42
+ # Create Conversation Chain
43
+ def get_conversation_chain_pdf():
44
+ prompt_template = """
45
+ Please meticulously research the question using only the information provided within the context. Provide a detailed
46
+ answer, ensuring to avoid unnecessary rambling. If the answer cannot be found within the context, simply state
47
+ 'answer is not available in the context.'
48
+
49
+ Context: \n{context}?\n
50
+ Question: \n{question}?\n
51
+
52
+ Answer:
53
+
54
+ """
55
+ model = ChatGoogleGenerativeAI(model="gemini-pro", temperature=0.9)
56
+ prompt = PromptTemplate(template=prompt_template, input_variables=["context", "question"])
57
+ chain = load_qa_chain(model, chain_type="stuff", prompt=prompt)
58
+ return chain
59
+
60
+
61
+ # Processing User Input
62
+ def user_input(user_query):
63
+ embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
64
+ load_vector_db = FAISS.load_local("faiss_index", embeddings, allow_dangerous_deserialization=True)
65
+ docs = load_vector_db.similarity_search(user_query)
66
+ chain = get_conversation_chain_pdf()
67
+
68
+ response = chain(
69
+ {"input_documents": docs, "question": user_query},
70
+ return_only_outputs=True
71
+ )
72
+ print(response)
73
+ st.write("AI Response : ", response["output_text"])
74
+
75
+
76
+ def app():
77
+ #st.set_page_config("PDF Chat App", page_icon="img.png")
78
+ st.header("Chat with your PDF files using Google Gemini Pro")
79
+ user_query = st.text_input("Ast question for the PDF File?")
80
+ if user_query:
81
+ user_input(user_query)
82
+
83
+ st.title("Upload PDF")
84
+ pdf_docs = st.file_uploader("Upload your PDF File, and click Submit!", accept_multiple_files=True)
85
+ if st.button("Submit!"):
86
+ with st.spinner('Processing...'):
87
+ raw_text = read_pdf(pdf_docs)
88
+ text_chunks = get_chunks(raw_text)
89
+ get_vector_store(text_chunks)
90
+ st.success("Processing Done!")
91
+
92
+
93
+ if __name__ == "__main__":
94
+ app()
chatbot.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+
3
+ load_dotenv()
4
+
5
+ import streamlit as st
6
+ import os
7
+ import pathlib
8
+ import textwrap
9
+ from PIL import Image
10
+ import google.generativeai as genai
11
+
12
+ def to_markdown(text):
13
+ text = text.replace('•', ' *')
14
+ return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))
15
+
16
+
17
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
18
+
19
+
20
+ def get_gemini_response(question):
21
+ model = genai.GenerativeModel('gemini-pro')
22
+ response = model.generate_content(question)
23
+ return response.text
24
+
25
+ def get_gemini_response_image(input,image):
26
+ model = genai.GenerativeModel('gemini-pro-vision')
27
+ if input!="":
28
+ response = model.generate_content([input,image])
29
+ else:
30
+ response = model.generate_content(image)
31
+ return response.text
32
+
33
+ def app():
34
+ with st.sidebar:
35
+ st.header("Text as input")
36
+ text_input_prompt = st.text_input("Enter the prompt: ",key="input")
37
+ st.markdown("<h1 style='text-align: center;'>(or)</h1>", unsafe_allow_html=True)
38
+ img_input_prompt = st.text_input("Enter the prompt: ",key="input1")
39
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
40
+ image = ""
41
+ submit=st.button("Generate response")
42
+
43
+
44
+ if submit:
45
+ if text_input_prompt:
46
+ response=get_gemini_response(text_input_prompt)
47
+ st.subheader("Generated response:")
48
+ st.write(response)
49
+ st.download_button(label='download text',data="response",file_name="pdf1.pdf")
50
+ elif uploaded_file:
51
+ if uploaded_file is not None:
52
+ image = Image.open(uploaded_file)
53
+ st.image(image, caption="Uploaded Image.", use_column_width=True)
54
+ st.subheader("Generated response:")
55
+ response=get_gemini_response_image(img_input_prompt,image)
56
+ st.write(response)
57
+
58
+ if __name__ == "__main__":
59
+ app()
faiss_index/index.faiss ADDED
Binary file (3.12 kB). View file
 
faiss_index/index.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:449653589cc2ba81b9c7b9c5a8c3a2b44acbb66b9a4af0a1d15b57019c25f4f1
3
+ size 95038
main.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from streamlit_option_menu import option_menu
3
+
4
+ import ATS ,chatbot ,PDF,resume
5
+
6
+ st.set_page_config(page_title='Student Interactor')
7
+
8
+ class MultiApp:
9
+ def __init__(self):
10
+ self.apps =[]
11
+
12
+
13
+ def add_app(self,title, function):
14
+ self.apps.append({
15
+ "title": title,
16
+ "function" : function
17
+ })
18
+
19
+ def run():
20
+ with st.sidebar:
21
+ app = option_menu(
22
+ menu_title= "Student Interactor using Generative ai",
23
+ options = ['Chatbot','ATS','PDF','Resume'],
24
+ menu_icon = 'chat-text-fill',
25
+ default_index = 1,
26
+ )
27
+
28
+ if app == 'Chatbot':
29
+ chatbot.app()
30
+ if app == 'ATS':
31
+ ATS.app()
32
+ if app == 'PDF':
33
+ PDF.app()
34
+ if app == 'Resume':
35
+ resume.app()
36
+
37
+ if __name__ == "__main__":
38
+ run()
resume.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import google.generativeai as genai
3
+ from dotenv import load_dotenv
4
+ import os
5
+ # Load Gemini API key from environment variable
6
+ load_dotenv()
7
+ gemini_api_key = os.getenv("GEMINI_API_KEY")
8
+
9
+ # Set up Gemini API client
10
+ genai.configure(api_key=gemini_api_key)
11
+
12
+ # Define a function to generate a resume based on a job description using Gemini API
13
+ def generate_resume(name, education, skills, projects, work_experience, address, linkedin, github, phone, email,
14
+ job_description):
15
+ prompt = '''
16
+ Act as a professional resume writer.
17
+ Create a resume for a job description: {job_description}
18
+ The candidate's name is {name}.
19
+ The candidate's education is: {education}
20
+ The candidate's skills are: {skills}
21
+ The candidate's projects are: {projects}
22
+ The candidate's work experience is: {work_experience}
23
+ The candidate's address is: {address}
24
+ The candidate's LinkedIn profile is: {linkedin}
25
+ The candidate's GitHub profile is: {github}
26
+ The candidate's phone number is: {phone}
27
+ The candidate's email ID is: {email}
28
+ Generate a well-formatted resume with the following sections: Summary, Education, Work Experience, Skills, Projects, Contact Information.
29
+ '''.format(
30
+ name=name,
31
+ address=address,
32
+ linkedin=linkedin,
33
+ github=github,
34
+ phone=phone,
35
+ email=email,
36
+ education=education,
37
+ skills=skills,
38
+ projects=projects,
39
+ work_experience=work_experience,
40
+ job_description=job_description
41
+ )
42
+ response = genai.GenerativeModel('gemini-pro').generate_content(prompt)
43
+ return response.text
44
+
45
+
46
+ # Create a Streamlit app
47
+ def app():
48
+ st.title("Resume Generator by Job Description")
49
+
50
+ # Get user input for job description
51
+ job_description = st.text_area("Enter the job description:")
52
+
53
+ # Get user input for candidate information
54
+ name = st.text_input("Enter your name:")
55
+ education = st.text_area("Enter your education qualification:")
56
+ skills = st.text_area("Enter your skills:")
57
+ projects = st.text_area("Enter your projects:")
58
+ work_experience = st.text_area("Enter your work experience:")
59
+ address = st.text_area("Enter your address:")
60
+ linkedin = st.text_input("Enter your LinkedIn profile link:")
61
+ github = st.text_input("Enter your GitHub profile link:")
62
+ phone = st.text_input("Enter your phone number:")
63
+ email = st.text_input("Enter your email ID:")
64
+
65
+ # Generate resume using Gemini API
66
+ if st.button("Generate Resume"):
67
+ resume_text = generate_resume(name, education, skills, projects, work_experience, address, linkedin, github, phone,
68
+ email, job_description)
69
+
70
+ st.text_area("Generated Resume:", value=resume_text, height=500)
71
+ st.download_button("Download Resume", resume_text, "generated_resume.txt", "text/plain")
72
+
73
+ if __name__ == "__main__":
74
+ app()