DEV Community

Cover image for Building a Resume QA Bot with Lyzr Agent
Prajjwal Sule
Prajjwal Sule

Posted on • Updated on

Building a Resume QA Bot with Lyzr Agent

In this article, we'll walk through building a Resume QA (Question-Answering) Bot using Streamlit and Lyzr SDK's. This bot allows users to upload a resume in PDF format, ask questions about the resume, and receive answers in real-time.

In case If you don't want to read it all

Introduction

With the rise of AI-powered tools, automating tasks like resume analysis has become more accessible. By leveraging Lyzr SDK's which gave us functionality of RAG, and Streamlit for the frontend, we can create an interactive web application for resume analysis in not time.

Lyzr

Lyzr provides an agentic way to build Gen-AI applications with very little effort and in less time.
For more details: Lyzr

Let's Build Together

Have a look!

Lyzr Open Source SDKs πŸš€ | Lyzr Documentation

Welcome to the Lyzr Open Source Software Development Kit (SDK)!

favicon docs.lyzr.ai

Setting Up the Environment and Installing Dependencies

We'll start by setting up our development environment. Install Streamlit, Lyzr, openai and pdfminer.six library.

python3 -m venv venv
source venv/bin/activate
pip install streamlit lyzr openai pdfminer.six
Enter fullscreen mode Exit fullscreen mode

Building the Application

Create on script called as QAbotapp.py

api_key = st.sidebar.text_input("API Key", type="password")
if api_key:
    os.environ["OPENAI_API_KEY"] = api_key
else:
    st.sidebar.warning("Please enter your API key to proceed.")
Enter fullscreen mode Exit fullscreen mode

This code creates a text input in the Streamlit sidebar for users to input their OpenAI API key. If provided, it sets the API key in the environment variables.

def remove_existing_files(directory):
    for filename in os.listdir(directory):
        file_path = os.path.join(directory, filename)
        try:
            if os.path.isfile(file_path) or os.path.islink(file_path):
                os.unlink(file_path)
            elif os.path.isdir(file_path):
                shutil.rmtree(file_path)
        except Exception as e:
            st.error(f"Error while removing existing files: {e}")
Enter fullscreen mode Exit fullscreen mode

This function iterates through files in a directory and removes them.

data_directory = "data"
os.makedirs(data_directory, exist_ok=True)
remove_existing_files(data_directory)
Enter fullscreen mode Exit fullscreen mode

Sets up a directory named "data" for storing uploaded files. If it doesn't exist, it creates one. Then, it removes any existing files in this directory.

uploaded_file = st.file_uploader("Choose PDF file", type=["pdf"])

if uploaded_file is not None:
    file_path = os.path.join(data_directory, uploaded_file.name)
    with open(file_path, "wb") as file:
        file.write(uploaded_file.getvalue())


    st.success(f"File successfully saved")
Enter fullscreen mode Exit fullscreen mode

This creates a file uploader widget in the Streamlit app, allowing users to upload PDF files. Once the file has been uploaded it will be save inside the data directory.

def get_files_in_directory(directory="data"):
    files_list = []

    if os.path.exists(directory) and os.path.isdir(directory):
        for filename in os.listdir(directory):
            file_path = os.path.join(directory, filename)
            if os.path.isfile(file_path):
                files_list.append(file_path)

    return files_list
Enter fullscreen mode Exit fullscreen mode

This function retrieves file paths in a specified directory.

Implementation of CV QABot along with RAG

def rag_implementation():
    # This function will implement RAG Lyzr QA bot
    path = get_files_in_directory()
    path = path[0]

    rag = QABot.pdf_qa(
        input_files=[str(path)],
        llm_params={"model": "gpt-3.5-turbo"},

    )

    return rag
Enter fullscreen mode Exit fullscreen mode

The function rag_implementation is designed to set up and return an instance of the Lyzr QA bot using the RAG (Retrieval-Augmented Generation) approach.

It calls the previously defined _get_files_in_directory _ function to get a list of file paths in the β€œdata” directory.

if uploaded_file is not None:
    question = st.text_input("Ask a question about the resume:")

    if st.button("Get Answer"):
        rag = rag_implementation()
        response = rag.query(question)
        st.markdown(f"""{response.response}""")

Enter fullscreen mode Exit fullscreen mode

Allows users to input questions about the resume and retrieves answers using the Lyzr QABot when the "Get Answer" button is clicked.

Conclusion

Building a Resume QA Bot with Streamlit and Lyzr SDK's allows for quick and efficient resume analysis. Users can upload their resumes, ask questions, and receive instant responses, for fine tune their resumes to specific job role.

Clone the repository using this app and do some permutation and combination with this resume QABot as well as with the Lyzr SDK.

For more information explore the website: Lyzr

Resume QA Bot β€” Github

Top comments (0)