AIwithJobin/ATSResumeTracker_Using_GEMINI_PRO
2
1# 1. Field to put my JD2# 2. Upload PDF3# 3. PDF to image --- >processing -- > Google Gemini Pro4# 4. Prompts Template[Multiple Prompt]5 6from dotenv import load_dotenv7import streamlit as st8import os9import io10import base6411from PIL import Image12import pdf2image13import google.generativeai as genai14 15# Load environment variables16load_dotenv()17 18# Configure Google Gemini API19genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))20 21# Explicit Poppler path (Ensure it's installed in apt.txt)22POPPLER_PATH = "/usr/bin"23 24def get_gemini_response(input_text, pdf_content, prompt):25 """Generate a response using Google Gemini API."""26 try:27 model = genai.GenerativeModel("gemini-1.5-pro")28 response = model.generate_content([input_text, pdf_content[0], prompt])29 return response.text30 except Exception as e:31 return f"Error in generating response: {str(e)}"32 33def input_pdf_setup(upload_file):34 """Convert uploaded PDF to an image and encode it as base64."""35 if upload_file is not None:36 try:37 # Convert PDF to image using explicit Poppler path38 images = pdf2image.convert_from_bytes(upload_file.read(), poppler_path=POPPLER_PATH)39 40 # Get first page as an image41 first_page = images[0]42 43 # Convert image to bytes44 img_byte_arr = io.BytesIO()45 first_page.save(img_byte_arr, format="JPEG")46 img_byte_arr = img_byte_arr.getvalue()47 48 # Encode image to base6449 pdf_parts = [50 {51 "mime_type": "image/jpeg",52 "data": base64.b64encode(img_byte_arr).decode()53 }54 ]55 return pdf_parts56 except Exception as e:57 st.error(f"Error processing PDF: {str(e)}")58 return None59 else:60 st.error("No file uploaded.")61 return None62 63# Streamlit UI64st.set_page_config(page_title="ATS Resume Expert")65st.header("ATS Tracking System")66 67# Job Description Input68input_text = st.text_area("Job Description:", key="input")69 70# File Upload71uploaded_file = st.file_uploader("Upload your resume (PDF)", type=["pdf"])72 73if uploaded_file:74 st.success("PDF Uploaded Successfully!")75 76# Buttons77submit1 = st.button("Tell me about the Resume")78submit2 = st.button("Percentage Match")79 80# Prompt Templates81input_prompt1 = """82You are an experienced HR with technical expertise in Data Science, Full Stack Web Development, 83Big Data Engineering, DevOps, or Data Analysis. Your task is to review the provided resume against 84the job description for these roles. Please provide a professional evaluation, highlighting 85strengths and weaknesses in relation to the job requirements.86"""87 88input_prompt2 = """89You are an advanced ATS (Applicant Tracking System) scanner with expertise in evaluating resumes 90for roles like Data Science, Full Stack Web Development, Big Data Engineering, DevOps, and Data Analysis. 91Your task is to assess the resume against the job description and provide:921. **Percentage Match** between the resume and job description.932. **Missing Keywords** that are crucial for ATS.943. **Final Thoughts** on the resume's suitability for the job.95"""96 97# Process Requests98if submit1:99 if uploaded_file:100 pdf_content = input_pdf_setup(uploaded_file)101 if pdf_content:102 response = get_gemini_response(input_text, pdf_content, input_prompt1)103 st.subheader("Evaluation:")104 st.write(response)105 else:106 st.warning("Please upload a resume.")107 108elif submit2:109 if uploaded_file:110 pdf_content = input_pdf_setup(uploaded_file)111 if pdf_content:112 response = get_gemini_response(input_text, pdf_content, input_prompt2)113 st.subheader("Percentage Match & Analysis:")114 st.write(response)115 else:116 st.warning("Please upload a resume.")117 118 119 120 121 