DreamStream-1 commited on
Commit
bfb0909
·
verified ·
1 Parent(s): 095d5d9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +91 -0
app.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ import streamlit as st
4
+ from PIL import Image
5
+ import pdf2image
6
+ import google.generativeai as genai
7
+ import base64
8
+ import io
9
+
10
+ # Load environment variables from .env file
11
+ load_dotenv()
12
+
13
+ # Set the Google API key
14
+ genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
15
+
16
+ # Function to extract the content from the uploaded PDF
17
+ def input_pdf_setup(uploaded_file):
18
+ # Check if file is uploaded
19
+ if not uploaded_file:
20
+ raise FileNotFoundError("No file uploaded")
21
+
22
+ # Convert the PDF to images using pdf2image
23
+ images = pdf2image.convert_from_bytes(uploaded_file.read(), poppler_path=r"C:\Program Files (x86)\poppler\library\bin")
24
+
25
+ first_page = images[0]
26
+
27
+ # Convert the first page image to bytes
28
+ img_byte_arr = io.BytesIO()
29
+ first_page.save(img_byte_arr, format='JPEG')
30
+ img_byte_arr = img_byte_arr.getvalue()
31
+
32
+ pdf_parts = [
33
+ {
34
+ "mime_type": "image/jpeg",
35
+ "data": base64.b64encode(img_byte_arr).decode() # encode to base64
36
+ }
37
+ ]
38
+ return pdf_parts
39
+
40
+ # Function to interact with Google's Gemini AI model
41
+ def get_gemini_response(input_text, pdf_content, prompt):
42
+ model = genai.GenerativeModel('gemini-1.5-flash')
43
+ response = model.generate_content([input_text, pdf_content[0], prompt])
44
+ return response.text
45
+
46
+ # Streamlit app setup
47
+ st.set_page_config(page_title="ATS")
48
+ st.header("ATS Tracking System")
49
+
50
+ # User inputs
51
+ input_text = st.text_area("Job Description: ", key="input")
52
+ uploaded_file = st.file_uploader("Upload PDF File", type=["pdf"])
53
+
54
+ if uploaded_file is not None:
55
+ st.write("PDF Uploaded Successfully")
56
+
57
+ # Submission buttons
58
+ submit1 = st.button("Tell Me About the Resume")
59
+ submit3 = st.button("Percentage Match")
60
+
61
+ # Prompts for the AI model
62
+ input_prompt1 = """
63
+ You are an experienced Technical Human Resource Manager focused on hiring team leads and managers. Your task is to review the provided resume against the job description for the uploaded resume.
64
+ Please share your professional evaluation on whether the candidate's profile aligns with the role.
65
+ Highlight the strengths and weaknesses of the applicant in relation to the specified job requirements.
66
+ """
67
+
68
+ input_prompt3 = """
69
+ You are a skilled ATS (Applicant Tracking System) scanner with a deep understanding of Management and Team Leadership roles and the years of experience required for the mentioned roles regarding the uploaded resume and ATS functionality.
70
+ Your task is to evaluate the resume against the provided job description. Provide a match percentage, followed by missing keywords, and conclude with final thoughts.
71
+ """
72
+
73
+ # Handle button submissions
74
+ if submit1:
75
+ if uploaded_file is not None:
76
+ pdf_content = input_pdf_setup(uploaded_file)
77
+ response = get_gemini_response(input_prompt1, pdf_content, input_text)
78
+ st.subheader("Response:")
79
+ st.write(response)
80
+ else:
81
+ st.warning("Please upload the resume")
82
+
83
+ elif submit3:
84
+ if uploaded_file is not None:
85
+ pdf_content = input_pdf_setup(uploaded_file)
86
+ response = get_gemini_response(input_prompt3, pdf_content, input_text)
87
+ st.subheader("Response:")
88
+ st.write(response)
89
+ else:
90
+ st.warning("Please upload the resume")
91
+