-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
129 lines (113 loc) · 4.92 KB
/
Copy pathmain.py
File metadata and controls
129 lines (113 loc) · 4.92 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from dotenv import load_dotenv
load_dotenv()
import streamlit as st
import os
import base64
import io
from PIL import Image
import pdf2image
import google.generativeai as genai
# Place st.set_page_config() at the very top
st.set_page_config(page_title="AI-Powered-Resume-Analyser")
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
# ... (rest of your code, including functions and Streamlit elements)
def get_gemini_response(input_text, pdf_content, prompt, chat_history=None):
"""
Generates a response from the Gemini Pro Vision model, considering chat history.
"""
model = genai.GenerativeModel('gemini-1.5-flash')
messages = []
if chat_history:
messages.extend(chat_history)
messages.extend([input_text, pdf_content, prompt])
response = model.generate_content(messages)
return response.text
def input_pdf_setup(uploaded_file):
"""
Converts a PDF file to a base64 encoded JPEG image.
"""
if uploaded_file is not None:
images = pdf2image.convert_from_bytes(uploaded_file.read())
first_page = images[0]
img_byte_arr = io.BytesIO()
first_page.save(img_byte_arr, format='JPEG')
img_byte_arr = img_byte_arr.getvalue()
pdf_parts = [
{
"mime_type": "image/jpeg",
"data": base64.b64encode(img_byte_arr).decode()
}
]
return pdf_parts
else:
raise FileNotFoundError("File not uploaded")
# Streamlit App
st.header("ATS Tracking System")
if 'chat_history' not in st.session_state:
st.session_state.chat_history = []
input_text = st.text_area("Job Description: ", key="input")
uploaded_file = st.file_uploader("Upload Resume(PDF)", type=["pdf"])
if uploaded_file is not None:
st.write("Resume Uploaded Successfully")
submit1 = st.button("Analyse my Resume")
submit2 = st.button("Skill Gap Analysis")
submit3 = st.button("Interview Preparation Insights")
input_prompt1 = """
You are an experienced HR with Tech Experience in the field of any one job role from Data Science, Full Stack web-development,Big Data
Engineering, DevOps, Data Analyst. Your task is to review the provided resume against the job description for these profiles.
Please share your professional evaluation on wether the candidate's profile aligns with the role.
Highlight the strengths and weaknesses of the applicant in relation to the specified job role
"""
input_prompt3 = """
You are an skilled ATS (Applicant Tracking System) scanner with a deep understanding in any one job role of Data Science, Full Stack web-development,Big Data
Engineering, DevOps, Data Analyst.Your task is to review the provided resume against the job description for these profiles.
your task is to evaluate the resume against the provided job description. give me the percentage of match if the resume matches
the job description. First the output should come as percentage and then keywords missing and last final thoughts.
"""
if submit1:
if uploaded_file is not None:
pdf_content = input_pdf_setup(uploaded_file)
response = get_gemini_response(input_text, pdf_content, input_prompt1)
st.subheader("The response is:")
st.write(response)
else:
st.write("Please upload a file")
elif submit2:
if uploaded_file is not None:
pdf_content = input_pdf_setup(uploaded_file)
response = get_gemini_response(input_text, pdf_content, input_prompt1)
st.subheader("The response is:")
st.write(response)
else:
st.write("Please upload a file")
elif submit3:
if uploaded_file is not None:
pdf_content = input_pdf_setup(uploaded_file)
response = get_gemini_response(input_text, pdf_content, input_prompt3)
st.subheader("The response is:")
st.write(response)
else:
st.write("Please upload a file")
# Chatbot Interface
st.subheader("Chat with the Resume Analyzer")
user_message = st.text_input("Your message:", key="chat_input")
send_button = st.button("Send")
if send_button:
if uploaded_file is not None:
pdf_content = input_pdf_setup(uploaded_file)
user_input = user_message
st.session_state.chat_history.append({"role": "user", "parts": [user_input]})
response = get_gemini_response(user_input, pdf_content, "Continue the conversation.", st.session_state.chat_history)
st.session_state.chat_history.append({"role": "model", "parts": [response]})
# Correctly append image data
st.session_state.chat_history.append({"role": "image", "parts": pdf_content})
for message in st.session_state.chat_history:
if message['role'] == 'user':
st.write(f"**You:** {message['parts']}")
elif message['role'] == 'model':
st.write(f"**Bot:** {message['parts']}")
elif message['role'] == 'image':
# you can add a display of the image here
pass
else:
st.write("Please upload a file first.")