Have you ever struggled to craft the perfect interview questions based on a job description and resume? You’re not alone. Matching qualifications to targeted questions can be time-consuming. But what if there was a tool that could automate this process?
In this project, I’ve utilized Gemini API, to develop a question generator specifically designed to bridge the gap between job descriptions and resumes. This innovative tool analyzes both documents to identify key skills and experiences, then generates a set of insightful questions that get right to the heart of a candidate’s suitability for the role.
We are going to utilize Pythons PyPDF2 library to access and extract textual data of resume pdf files and feed that data to our model to generate personalized questions relevant to the role in real-time.
Let's begin to code our model:
Installing necessary Libraries
!pip install PyPDF2
!pip install -q -U google-generativeai
PyPDF2: It’s a Python library specifically designed to work with PDF files. In this case, we’ll use it to extract information from a resume that is in PDF format.
GenerativeAI: The google-generativeai
library allows you to send this extracted information to Google's GenerativeAI technology, likely including the Gemini model. This powerful AI model will then analyze the information and generate a set of interview questions that are specifically tailored to the candidate's profile.
Generating the API key
Generate your personal API key by visiting this link: https://ai.google.dev/
For secure storage of your API key, consider utilizing Colab Secrets. This built-in feature allows you to manage sensitive information within your notebook without compromising security.
Importing necessary tools
import google.generativeai as genai
from PyPDF2 import PdfReader
# Used to securely store your API key
from google.colab import userdata
# Or use `os.getenv('GOOGLE_API_KEY')` to fetch an environment variable.
GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')
genai.configure(api_key=GOOGLE_API_KEY)
from google.colab import userdata: Imagine a secret notebook where sensitive information is stored securely. This line gives us access to that notebook, ensuring important details stay private.
GOOGLE_API_KEY = userdata.get(‘GOOGLE_API_KEY’): Here, we’re cautiously retrieving a secret code, the Google API key, which is like a special password to unlock Generative AI’s abilities. We’re keeping this key under wraps to protect it.
genai.configure(api_key=GOOGLE_API_KEY): This line gently introduces our two friends, genai
(the Generative AI) and the API key. It links them together, allowing them to communicate and work as a team. It's like giving genai
a special password to unlock its full potential!
Model Building
def model(input_text):
model = genai.GenerativeModel('gemini-pro')
response = model.generate_content(input_text)
return response.text
(‘gemini-pro’): This part specifies which Generative AI model we want to use. In our case, it’s “gemini-pro,” which is a powerful model capable of creative text generation.
response = model.generate_content(input_text): Now that we have the model
(Generative AI tool), we're putting it to work. We're giving it the input_text
. Think of it as feeding input_text
to the model
is like giving instructions to a machine.
return response.text: Finally, the model
generates a response based on the input_text
. This response is stored in a variable called response
. Here, we're specifically interested in the textual content of the response, so we use .text
to extract just the text portion.
Text extraction from Resume
Function to extract textual data from various pdf files.
def get_pdf_text(pdf_docs):
text = ""
for pdf in pdf_docs:
pdf_reader = PdfReader(open(pdf, "rb"))
for page in pdf_reader.pages:
text += page.extract_text()
return text
Prompting the model
The accuracy and relevance of the response highly depend on what input_text
we provide to the model. Working and generating the relevant prompt to feed is like a whole new skill set.
def question(resume_text, job_description_text):
input_text = f"""
Title: Real-time Interview Question Generation based on Job Description and Resume
Prompt:
Given the provided job description and resume, generate a series of interview questions that probe the candidate's suitability for the position. Your questions should cover a range of topics, including technical skills, relevant experience, problem-solving abilities, teamwork, and communication skills.
Sample Interview Questions:
1. Based on your experience listed in the resume, can you provide examples of projects or tasks that demonstrate your proficiency in [relevant skill]?
2. How would you approach [specific responsibility mentioned in the job description] based on your previous experience?
3. Can you discuss a challenging situation you encountered in a previous role and how you resolved it?
4. The job description mentions [specific technology or tool]. Can you describe your experience with this technology and how you've used it in past projects?
5. How do you prioritize tasks and manage your time effectively when faced with multiple deadlines?
6. Communication skills are essential for this role. Can you provide examples of how you've effectively communicated complex ideas or technical concepts to non-technical stakeholders?
7. The job requires collaborating with cross-functional teams. Can you discuss a successful collaboration experience and your role in achieving the team's goals?
8. How do you stay updated on industry trends and advancements relevant to this position?
9. Describe a situation where you had to quickly learn a new skill or technology to complete a project.
10. Can you provide examples of your leadership abilities and how you've motivated or mentored team members in the past?
Instructions:
Using the provided prompt, generate interview questions tailored to the candidate's background and the requirements of the job description. Focus on creating questions that prompt detailed responses and provide insights into the candidate's qualifications and fit for the role. Once generated, review the questions for relevance, clarity, and effectiveness in evaluating the candidate's suitability for the position.
resume: {resume_text}
job_description: {job_description_text}
"""
response = model(input_text)
return response
You can also try using the prompt:
“‘As an experienced Technical Human Resource Manager, your task is to generate a set of questions that align with the job description and resume. These questions should probe the candidate’s strengths, weaknesses, and salary expectations about the specified job requirements. Additionally, if relevant, please include coding problems to assess the candidate’s technical skills. Please generate questions that effectively evaluate the candidate’s suitability for the role.’”
Analyze on your own which prompt is working efficiently. You can also develop your personal prompt.
Final Step
Providing the resume and job description to your model and generating the questions.
#Sample input
pdf_texts = ["Software_Engineer_Resume.pdf", "VY_Resume.pdf"]
combined_text = get_pdf_text(pdf_texts)
job_description_text = """
Technical Human Resource Manager Job Description:
- Minimum of 5 years of experience in technical recruiting.
- Strong knowledge of software engineering principles.
- Experience in developing and implementing HR strategies.
- Excellent communication and interpersonal skills.
"""
questions = question(combined_text, job_description_text)
print(questions)
Note: Remember to upload the PDF files in Colab Notebook.
Provide a job description as per you wish to and test the model.
CONCLUSION
This exploration has hopefully sparked your curiosity about the exciting possibilities of Generative AI. As you’ve seen, it can be a powerful tool for creative text generation, but its applications extend far beyond this blog. From composing music to generating different writing styles, Generative AI is constantly evolving and pushing the boundaries of what’s possible.
Remember, experimentation and exploration are key! Don’t be afraid to try new things and see what creative text formats you can generate.
Here is the link for the GitHub code: https://github.com/Vaishnavi-cyber-blip/Question-generation