ytrsoymr commited on
Commit
f7c3790
·
verified ·
1 Parent(s): f9495d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -74
app.py CHANGED
@@ -1,83 +1,81 @@
1
- import streamlit as st
2
- import google.generativeai as genai
3
- import os
4
- import PyPDF2 as pdf
5
  from dotenv import load_dotenv
6
- import json
7
 
8
- load_dotenv() ## Load all environment variables
 
 
 
 
 
 
 
9
 
10
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
11
 
12
- # Define the prompt template
13
- input_prompt = """
14
- Hey, act like a skilled and very experienced ATS (Application Tracking System)
15
- with a deep understanding of tech fields such as software engineering, data science,
16
- data analysis, and big data engineering. Your task is to evaluate the resume
17
- based on the given job description.
18
-
19
- You must consider that the job market is very competitive, and you should provide
20
- the best assistance for improving resumes. Assign the percentage match based on JD
21
- and identify the missing keywords with high accuracy.
22
-
23
- resume: {text}
24
- description: {jd}
25
-
26
- Return ONLY a JSON response in the following format:
27
- {{
28
- "JD Match": "xx%",
29
- "MissingKeywords": ["keyword1", "keyword2", ...],
30
- "Profile Summary": "A short summary here"
31
- }}
32
-
33
- DO NOT include any additional text, explanation, or greetings—only return the JSON object.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  """
35
 
36
- def get_gemini_response(resume_text, jd_text):
37
- """Generates a response from Gemini API based on the resume and job description."""
38
- formatted_prompt = input_prompt.format(text=resume_text, jd=jd_text) # Format the prompt
39
- model = genai.GenerativeModel('gemini-1.5-pro')
40
- response = model.generate_content(formatted_prompt)
41
-
42
- # Ensure we get only the text response
43
- response_text = response.text.strip()
44
-
45
- # Attempt to extract JSON from the response
46
- try:
47
- parsed_response = json.loads(response_text)
48
- return parsed_response # Return parsed JSON
49
- except json.JSONDecodeError:
50
- return None # Return None if response is not valid JSON
51
-
52
- def input_pdf_text(uploaded_file):
53
- """Extracts text from the uploaded PDF resume."""
54
- reader = pdf.PdfReader(uploaded_file)
55
- text = ""
56
- for page in range(len(reader.pages)):
57
- extracted_text = reader.pages[page].extract_text()
58
- if extracted_text:
59
- text += extracted_text
60
- return text
61
-
62
- # Streamlit app
63
- st.title("Smart ATS")
64
- st.text("Improve Your Resume for ATS Systems")
65
-
66
- jd = st.text_area("Paste the Job Description")
67
- uploaded_file = st.file_uploader("Upload Your Resume", type="pdf", help="Please upload a PDF file")
68
-
69
- submit = st.button("Submit")
70
-
71
- if submit:
72
- if uploaded_file is not None and jd:
73
- text = input_pdf_text(uploaded_file)
74
- response = get_gemini_response(text, jd) # Pass formatted resume & JD
75
 
76
- if response:
77
- st.subheader(f"Job Description Match: {response['JD Match']}")
78
- st.write("Missing Keywords: ", response["MissingKeywords"])
79
- st.write("Profile Summary: ", response["Profile Summary"])
80
- else:
81
- st.error("Error: Gemini did not return valid JSON. Please try again.")
 
 
 
 
 
 
 
 
 
82
  else:
83
- st.warning("Please upload a resume and enter a job description.")
 
 
 
 
 
1
  from dotenv import load_dotenv
 
2
 
3
+ load_dotenv()
4
+ import base64
5
+ import streamlit as st
6
+ import os
7
+ import io
8
+ from PIL import Image
9
+ import pdf2image
10
+ import google.generativeai as genai
11
 
12
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
13
 
14
+ def get_gemini_response(input_text, pdf_content, prompt):
15
+ model = genai.GenerativeModel('gemini-pro-vision')
16
+ response = model.generate_content([input_text, pdf_content, prompt])
17
+ return response.text
18
+
19
+ def input_pdf_setup(uploaded_file):
20
+ if not uploaded_file:
21
+ st.warning("Please upload a PDF file.")
22
+ st.stop()
23
+
24
+ # Convert PDF to images
25
+ images = pdf2image.convert_from_bytes(uploaded_file.read())
26
+ first_page = images[0]
27
+
28
+ # Convert first page to bytes
29
+ img_byte_arr = io.BytesIO()
30
+ first_page.save(img_byte_arr, format='JPEG')
31
+ img_byte_arr = img_byte_arr.getvalue()
32
+
33
+ # Encode as base64
34
+ pdf_parts = [{
35
+ "mime_type": "image/jpeg",
36
+ "data": base64.b64encode(img_byte_arr).decode()
37
+ }]
38
+ return pdf_parts
39
+
40
+ # Streamlit App
41
+ st.set_page_config(page_title="ATS Resume Expert")
42
+ st.header("ATS Tracking System")
43
+
44
+ input_text = st.text_area("Job Description:", key="input")
45
+ uploaded_file = st.file_uploader("Upload your resume (PDF)...", type=["pdf"])
46
+
47
+ if uploaded_file:
48
+ st.success("PDF Uploaded Successfully")
49
+
50
+ submit1 = st.button("Tell Me About the Resume")
51
+ submit3 = st.button("Percentage Match")
52
+
53
+ input_prompt1 = """
54
+ You are an experienced Technical Human Resource Manager. Your task is to review the provided resume against the job description.
55
+ Please share your professional evaluation on whether the candidate's profile aligns with the role.
56
+ Highlight the strengths and weaknesses of the applicant in relation to the specified job requirements.
57
  """
58
 
59
+ input_prompt3 = """
60
+ You are a skilled ATS (Applicant Tracking System) scanner with expertise in data science and ATS functionality.
61
+ Your task is to evaluate the resume against the provided job description. Provide a percentage match if the resume aligns with the job description.
62
+ First, output the percentage match. Then, list missing keywords, followed by final thoughts.
63
+ """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
+ if submit1 and not submit3:
66
+ if uploaded_file:
67
+ pdf_content = input_pdf_setup(uploaded_file)
68
+ response = get_gemini_response(input_prompt1, pdf_content, input_text)
69
+ st.subheader("Response:")
70
+ st.write(response)
71
+ else:
72
+ st.warning("Please upload the resume.")
73
+
74
+ elif submit3 and not submit1:
75
+ if uploaded_file:
76
+ pdf_content = input_pdf_setup(uploaded_file)
77
+ response = get_gemini_response(input_prompt3, pdf_content, input_text)
78
+ st.subheader("Response:")
79
+ st.write(response)
80
  else:
81
+ st.warning("Please upload the resume.")