HikmatUllah commited on
Commit
11eee82
·
verified ·
1 Parent(s): 59cf909

Upload 2 files

Browse files
Files changed (2) hide show
  1. app2.py +150 -0
  2. requirements.txt +5 -0
app2.py ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import re
11
+
12
+ load_dotenv()
13
+
14
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
15
+
16
+ def get_gemini_response(input, pdf_content, prompt):
17
+ try:
18
+ model = genai.GenerativeModel('gemini-1.5-flash')
19
+ response = model.generate_content([input, pdf_content[0], prompt])
20
+ return response.text
21
+ except Exception as e:
22
+ st.error(f"Error in generating response: {str(e)}")
23
+ return ""
24
+
25
+ def input_pdf_setup(uploaded_pdf):
26
+ try:
27
+ if uploaded_pdf is not None:
28
+ doc = fitz.open(stream=uploaded_pdf.read(), filetype="pdf")
29
+
30
+ # Convert the first page to an image (0-indexed)
31
+ first_page = doc.load_page(0)
32
+ pix = first_page.get_pixmap()
33
+
34
+ # Convert pixmap to bytes
35
+ img_byte_arr = io.BytesIO()
36
+ img_byte_arr.write(pix.tobytes("jpeg"))
37
+ img_byte_arr.seek(0) # Go to the start of the byte stream
38
+
39
+ # Encode the image to base64
40
+ pdf_parts = [
41
+ {
42
+ "mime_type": "image/jpeg",
43
+ "data": base64.b64encode(img_byte_arr.read()).decode() # Encode to base64
44
+ }
45
+ ]
46
+ return pdf_parts
47
+ else:
48
+ raise FileNotFoundError("No file uploaded")
49
+ except Exception as e:
50
+ st.error(f"Error processing PDF file: {str(e)}")
51
+ return []
52
+
53
+ def extract_percentage(response):
54
+ try:
55
+ match = re.search(r'(\d+(\.\d+)?)%', response)
56
+ if match:
57
+ return float(match.group(1))
58
+ return 0.0
59
+ except Exception as e:
60
+ st.error(f"Error extracting percentage: {str(e)}")
61
+ return 0.0
62
+
63
+ #-------------- Streamlit App -----------------
64
+
65
+ st.set_page_config(page_title="ATS System")
66
+
67
+ with st.sidebar:
68
+ field = st.text_input("Enter your job field")
69
+
70
+ # Upload multiple resumes
71
+ uploaded_files = st.file_uploader("Upload Resumes (multiple)", type=["pdf"], accept_multiple_files=True)
72
+
73
+ if uploaded_files:
74
+ st.toast(f"{len(uploaded_files)} files uploaded successfully!", icon="✅")
75
+
76
+ submit1 = st.button("Tell me about the resumes")
77
+ submit4 = st.button("How much is the percentage match?")
78
+
79
+ st.header("ATS System - Resume Evaluation")
80
+
81
+ input_text = st.text_area("Job Description:", key="input")
82
+
83
+ input_prompt1 = f"""
84
+ 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.
85
+ Please share your professional evaluation on whether the candidate's profile aligns with the role.
86
+ Highlight the strengths and weaknesses of the applicant in relation to the specified job requirements.
87
+ """
88
+
89
+ input_prompt4 = f"""
90
+ You are a skilled ATS (Applicant Tracking System) scanner with a deep understanding of {field} and ATS functionality,
91
+ your task is to evaluate the resume against the provided job description. Give me the percentage of match if the resume matches
92
+ the job description. First, the output should come as percentage, then keywords missing, and last final thoughts.
93
+ """
94
+
95
+ comparison_results = []
96
+
97
+ if submit1 or submit4:
98
+ if uploaded_files:
99
+ if not input_text:
100
+ st.error("Please! provide the job description")
101
+ if not field:
102
+ st.error("Please! Enter your field of job")
103
+ for uploaded_file in uploaded_files:
104
+ pdf_content = input_pdf_setup(uploaded_file)
105
+
106
+ if pdf_content: # Only proceed if PDF content is valid
107
+ if submit1:
108
+ response = get_gemini_response(input_prompt1, pdf_content, input_text)
109
+ elif submit4:
110
+ response = get_gemini_response(input_prompt4, pdf_content, input_text)
111
+
112
+ if response:
113
+ comparison_results.append({
114
+ "file_name": uploaded_file.name,
115
+ "response": response
116
+ })
117
+
118
+ if comparison_results:
119
+ for result in comparison_results:
120
+ st.markdown(
121
+ f"""
122
+ <div style="background-color:#f0f0f0; padding: 15px; border-radius: 8px; margin-top: 20px;">
123
+ <h3>{result['file_name']}</h3>
124
+ <p>{result['response']}</p>
125
+ </div>
126
+ """,
127
+ unsafe_allow_html=True
128
+ )
129
+
130
+ if submit4:
131
+ try:
132
+ best_match = max(
133
+ comparison_results,
134
+ key=lambda x: extract_percentage(x['response'])
135
+ )
136
+ st.markdown(
137
+ f"""
138
+ <div style="background-color: #d3f8d3; padding: 15px; border-radius: 8px; margin-top: 20px; color: black;">
139
+ <h3><strong>Best Match:</strong> {best_match['file_name']}</h3>
140
+ <p>{best_match['response']}</p>
141
+ </div>
142
+ """,
143
+ unsafe_allow_html=True
144
+ )
145
+ except ValueError:
146
+ st.error("Could not extract a valid percentage match.")
147
+ else:
148
+ st.write("No valid responses generated.")
149
+ else:
150
+ st.write("Please upload at least one resume.")
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv
4
+ pdf2image
5
+ pymupdf