tensorboy0101's picture
Create app.py
f574cc3 verified
from dotenv import load_dotenv
import fitz
import base64
import os
import io
from PIL import Image
import gradio as gr
import google.generativeai as genai
load_dotenv()
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
def get_gemini_response(input_text, pdf_content, prompt):
model = genai.GenerativeModel('gemini-1.5-flash')
response = model.generate_content([input_text, pdf_content[0], prompt])
return response.text
def input_pdf_setup(uploaded_file):
if uploaded_file is not None:
pdf_bytes = uploaded_file.read()
pdf_doc = fitz.open(stream=pdf_bytes, filetype="pdf")
first_page = pdf_doc[0]
pix = first_page.get_pixmap()
img_byte_arr = io.BytesIO()
img_byte_arr.write(pix.tobytes("jpeg"))
img_byte_arr = img_byte_arr.getvalue()
pdf_parts = [
{
"mime_type": "image/jpeg",
"data": base64.b64encode(img_byte_arr).decode()
}
]
return pdf_parts
else:
return None
# Prompts
input_prompt1 = """
You are an experienced Technical Human Resource Manager, your task is to review the provided resume against the job description.
Please share your professional evaluation on whether the candidate's profile aligns with the role.
Highlight the strengths and weaknesses of the applicant in relation to the specified job requirements.
"""
input_prompt3 = """
You are a skilled ATS (Applicant Tracking System) scanner with a deep understanding of data science and ATS functionality.
Evaluate the resume against the job description. Give a match percentage, missing keywords, and final thoughts.
"""
# Gradio functions
def analyze_resume(job_description, resume_file, analysis_type):
if resume_file is None:
return "Please upload your resume."
pdf_content = input_pdf_setup(resume_file)
if pdf_content is None:
return "Failed to process resume."
if analysis_type == "Professional Evaluation":
return get_gemini_response(job_description, pdf_content, input_prompt1)
elif analysis_type == "ATS Match Percentage":
return get_gemini_response(job_description, pdf_content, input_prompt3)
else:
return "Invalid analysis type selected."
# Gradio Interface
iface = gr.Interface(
fn=analyze_resume,
inputs=[
gr.Textbox(label="Job Description", lines=8, placeholder="Paste job description here..."),
gr.File(label="Upload Resume (PDF)", file_types=[".pdf"]),
gr.Radio(label="Analysis Type", choices=["Professional Evaluation", "ATS Match Percentage"], value="Professional Evaluation")
],
outputs=gr.Textbox(label="Result"),
title="ATS Resume Expert",
description="Analyze your resume against a job description using Gemini LLM."
)
iface.launch()