Mairu10 commited on
Commit
b1775c7
·
verified ·
1 Parent(s): b74da4a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -0
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+
3
+ import base64
4
+ import streamlit as st
5
+ import os
6
+ import io
7
+ from PIL import Image
8
+ import pdf2image
9
+ import google.generativeai as genai
10
+
11
+ # Streamlit App
12
+ st.set_page_config(page_title="ATS Resume Expert")
13
+ st.sidebar.header("Configuration")
14
+
15
+ # Add a text box in the sidebar for the API key
16
+ api_key = st.sidebar.text_input("Enter your Google API Key", type="password")
17
+
18
+ # Load the API key and configure the Generative AI model if key is provided
19
+ if api_key:
20
+ os.environ["GOOGLE_API_KEY"] = api_key
21
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
22
+
23
+ st.header("ATS Tracking System")
24
+ input_text = st.text_area("Job Description", key="input")
25
+ uploaded_file = st.file_uploader("Upload your Resume(PDF)...", type=["pdf"])
26
+
27
+ def get_gemi_response(input_text, pdf_content, prompt):
28
+ model = genai.GenerativeModel('gemini-1.5-flash')
29
+ response = model.generate_content([input_text, pdf_content[0], prompt])
30
+ return response.text
31
+
32
+ def input_pdf_setup(uploaded_file):
33
+ if uploaded_file is not None:
34
+ # Convert pdf to image
35
+ images = pdf2image.convert_from_bytes(uploaded_file.read())
36
+ first_page = images[0]
37
+ # Convert to bytes
38
+ img_byte_arr = io.BytesIO()
39
+ first_page.save(img_byte_arr, format='JPEG')
40
+ img_byte_arr = img_byte_arr.getvalue()
41
+
42
+ pdf_parts = [
43
+ {
44
+ "mime_type": "image/jpeg",
45
+ "data": base64.b64encode(img_byte_arr).decode()
46
+ }
47
+ ]
48
+ return pdf_parts
49
+ else:
50
+ raise FileNotFoundError("No File Uploaded")
51
+
52
+ if uploaded_file is not None:
53
+ st.write("PDF Uploaded Successfully")
54
+
55
+ submit1 = st.button("Tell me about the Resume")
56
+ submit2 = st.button("Percentage Match %")
57
+
58
+ input_prompt1 = """
59
+ You are an experienced Technical Recruiter and Headhunter for candidates, your task is to review the provided resume against the job description.
60
+ Please share your professional evaluation on whether the candidate's profile aligns with the role.
61
+ Highlight the strengths and weaknesses of the applicant in relation to the specified job requirements.
62
+ """
63
+
64
+ input_prompt2 = """
65
+ You are a skilled ATS (Applicant Tracking System) scanner with a deep understanding of data science and ATS functionality.
66
+ Your task is to evaluate the resume against the provided job description. Give me the percentage of match if the resume matches
67
+ the job description. First the output should come as percentage and then keywords missing and last final thoughts.
68
+ """
69
+
70
+ if submit1:
71
+ if uploaded_file is not None:
72
+ pdf_content = input_pdf_setup(uploaded_file)
73
+ response = get_gemi_response(input_prompt1, pdf_content, input_text)
74
+ st.subheader("The Response is:")
75
+ st.write(response)
76
+ else:
77
+ st.write("Please upload the Resume")
78
+
79
+ elif submit2:
80
+ if uploaded_file is not None:
81
+ pdf_content = input_pdf_setup(uploaded_file)
82
+ response = get_gemi_response(input_prompt2, pdf_content, input_text)
83
+ st.subheader("The Response is:")
84
+ st.write(response)
85
+ else:
86
+ st.write("Please upload the Resume")