HikmatUllah commited on
Commit
0f8d5fc
·
verified ·
1 Parent(s): 557c6a1

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +139 -0
  2. plan.txt +4 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ import streamlit as st
3
+ import os
4
+ from PIL import Image
5
+ import pdf2image
6
+ import google.generativeai as genai
7
+ import io
8
+ import base64
9
+ import fitz
10
+
11
+ load_dotenv()
12
+
13
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
14
+
15
+ def get_gemini_response(input, pdf_content, prompt):
16
+ model = genai.GenerativeModel('gemini-1.5-flash')
17
+ response=model.generate_content([input, pdf_content[0], prompt])
18
+ return response.text
19
+
20
+ # now to convert the uploaded pdf file into img that gemini pro can understant it and process it
21
+ # def input_pdf_setup(uploaded_pdf):
22
+ # if uploaded_pdf is not None:
23
+ # images = pdf2image.convert_from_bytes(uploaded_pdf.read()) # convet pdf to image
24
+ # first_page = images[0]
25
+
26
+ # # t convert into bytes
27
+ # img_byte_arr = io.BytesID()
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
+ # ]
38
+
39
+ # return pdf_parts
40
+ # else:
41
+ # raise FileNotFoundError("File not Uploaded")
42
+
43
+ def input_pdf_setup(uploaded_pdf):
44
+ if uploaded_pdf is not None:
45
+ doc = fitz.open(stream=uploaded_pdf.read(), filetype="pdf")
46
+
47
+ # Convert the first page to an image (0-indexed)
48
+ first_page = doc.load_page(0)
49
+ pix = first_page.get_pixmap()
50
+
51
+ # Convert pixmap to bytes (no need to save the image)
52
+ img_byte_arr = io.BytesIO()
53
+ img_byte_arr.write(pix.tobytes("jpeg"))
54
+ img_byte_arr.seek(0) # Go to the start of the byte stream
55
+
56
+ # Encode the image to base64
57
+ pdf_parts = [
58
+ {
59
+ "mime_type": "image/jpeg",
60
+ "data": base64.b64encode(img_byte_arr.read()).decode() # Encode to base64
61
+ }
62
+ ]
63
+ return pdf_parts
64
+ else:
65
+ raise FileNotFoundError("File not Uploaded")
66
+
67
+
68
+
69
+ #-------------- streamlit app -----------------
70
+
71
+ #-------------- Streamlit App -----------------
72
+
73
+ st.set_page_config(page_title="ATS System")
74
+
75
+ # Sidebar: Upload Resume, File Upload Success, and Buttons for Prompts
76
+ with st.sidebar:
77
+
78
+ field = st.text_input("Enter your job filed")
79
+
80
+ uploaded_file = st.file_uploader("Upload your Resume", type=["pdf"])
81
+
82
+ if uploaded_file is not None:
83
+ st.toast("File uploaded successfully!", icon="✅")
84
+
85
+
86
+ submit1 = st.button("Tell me about the resume")
87
+ submit4 = st.button("How much is the percentage match?")
88
+
89
+ # Main Area: Job Description and Bot Response
90
+ st.header("ATS System - Resume Evaluation")
91
+
92
+ input_text = st.text_area("Job Description:", key="input")
93
+
94
+
95
+ # Define Prompts
96
+ input_prompt1 = """
97
+ You are an experienced Technical Human Resource Manager and an expert in {field}, your task is to review the provided resume against the job description.
98
+ Please share your professional evaluation on whether the candidate's profile aligns with the role.
99
+ Highlight the strengths and weaknesses of the applicant in relation to the specified job requirements.
100
+ """
101
+
102
+ input_prompt4 = """
103
+ You are a skilled ATS (Applicant Tracking System) scanner with a deep understanding of {field} and ATS functionality,
104
+ your task is to evaluate the resume against the provided job description. Give me the percentage of match if the resume matches
105
+ the job description. First, the output should come as percentage, then keywords missing, and last final thoughts.
106
+ """
107
+
108
+ # Handle button clicks and generate responses
109
+ if submit1:
110
+ if uploaded_file is not None:
111
+ pdf_content = input_pdf_setup(uploaded_file)
112
+ response = get_gemini_response(input_prompt1, pdf_content, input_text)
113
+ st.markdown(
114
+ f"""
115
+ <div style="background-color:#f0f0f0; padding: 15px; border-radius: 8px; margin-top: 20px;">
116
+ <h3>Response:</h3>
117
+ <p>{response}</p>
118
+ </div>
119
+ """,
120
+ unsafe_allow_html=True
121
+ )
122
+ else:
123
+ st.write("Please upload your Resume.")
124
+
125
+ if submit4:
126
+ if uploaded_file is not None:
127
+ pdf_content = input_pdf_setup(uploaded_file)
128
+ response = get_gemini_response(input_prompt4, pdf_content, input_text)
129
+ st.markdown(
130
+ f"""
131
+ <div style="background-color:#f0f0f0; padding: 15px; border-radius: 8px; margin-top: 20px;">
132
+ <h3>Response:</h3>
133
+ <p>{response}</p>
134
+ </div>
135
+ """,
136
+ unsafe_allow_html=True
137
+ )
138
+ else:
139
+ st.write("Please upload your Resume.")
plan.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ 1. field to put my job discription
2
+ 2. upload pdf
3
+ 3. pdf to image --> processing --> google gemini processing
4
+ 4. Prompts Templates for execution [multiple prompts]
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv
4
+ pdf2image
5
+ pymupdf