Building an AI-powered Literature Review Application with Lyzr
Agent

Prajjwal Sule
GenAI Agents Unleashed
7 min readMar 25, 2024

In the dynamic world of research and academia, staying updated with the latest findings and insights is paramount. However, sifting through numerous research papers to extract relevant information can be a time-consuming and tedious task. To address this challenge, we introduce Literature Review by Lyzr, a powerful tool designed to streamline the process of summarizing and analyzing research papers.

Literature Review by Lyzr SDK

Literature Review by Lyzr’s QABot agent is a user-friendly web application, aimed at researchers, students, and anyone seeking to efficiently review academic literature. Leveraging advanced AI capabilities, Lyzr offers a seamless experience for extracting key insights from research papers with ease and precision. In this article, I will show you how can we build this GenAI application in low code with minimum effort because all the efforts are taken care of by the Lyzr Agent.

Lyzr provides an agentic way to build LLM applications in no time and low code, even if you are not familiar with the GenAI stack, and want to build your AI application so Lyzr is your go solution to build the GenAI apps without having a deep understanding of Generative AI.

Setting up the Project

Clone this app — Literature Review Assistant

python3 -m venv venv
source venv/bin/activate

Create an environment variable

# create .env file and paste this with your OpenAI API KEY

OPENAI_API_KEY = "Paste your openai api key here"

For creating OpenAI API key visit: openai.

Installing the required dependencies

pip install lyzr streamlit pdfminer.six

Project Structure

Literature-Review


├── utils/
│ ├── __init__.py
│ └── utils.py

├── app.py

├── README.md

├── .env

├── .gitignore

└── requirements.txt

Quick Glance of Literature Review Application

Try the Literature Review App

Setup the Utils file for common functions

utils.py file in the project serves as a utility module containing common functions that are utilized throughout the application

remove_existing_files()

Responsible for removing all existing files and directories within a specified directory. It iterates through each file in the directory and attempts to delete it using os.unlink() for files and shutil.rmtree() for directories.

import streamlit as st
import os
import shutil



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}")

This function is useful for clearing out existing files before performing new operations or updates in a specified directory, ensuring a clean slate for subsequent tasks.

get_file_in_directory()

get_files_in_directory(directory), retrieves a list of file paths within a specified directory. It initializes an empty list called files_list to store the file paths. It then checks if the provided directory exists and is indeed a directory using os.path.exists() and os.path.isdir(). If the directory exists and is valid, it iterates through each file in the directory using os.listdir().

def get_files_in_directory(directory):
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)

For each file, it constructs the full file path by joining the directory path with the file name using os.path.join(). If the constructed path corresponds to a file (i.e., it is not a directory), the file path is appended to the files_list. The function returns the list of file paths. This function is useful for obtaining a list of files within a directory for further processing or analysis.

save_upload_file()

save_uploaded_file(directory, uploaded_file), is responsible for saving an uploaded file to a specified directory. It first calls the remove_existing_files() function to ensure that the directory is empty before saving the new file. Then, it constructs the full file path by joining the specified directory path with the name of the uploaded file using os.path.join().

def save_uploaded_file(directory, uploaded_file):
remove_existing_files(directory=directory)
file_path = os.path.join(directory, uploaded_file.name)
with open(file_path, "wb") as file:
file.write(uploaded_file.read())
st.success("File uploaded successfully")

It opens the file in binary write mode using open(file_path, “wb”) and writes the contents of the uploaded file into the newly created file using file.write(uploaded_file.read()) and It displays a success message using st.success() to notify the user that the file has been uploaded successfully.

Guidance for QABot agent

Takes a QABot agent as input and generates a comprehensive review of a research paper using a series of predefined prompts. It iterates through a dictionary of prompts, where each prompt corresponds to a specific aspect of the research paper, such as the summary, research objectives, methodology, findings, discussion, related research, and prototype.

def reviewer(agent):
results = {}
prompts = {
"Summary": "Write 2 lines of summary about this research paper in a simplest manner",
"Research Objectives": "What is the main research question the paper investigates? What are the specific objectives or hypotheses outlined in the paper? Make a 4-5 line of response",
"Methodology": "What research methodology was used in the study (e.g., survey, experiment, case study)? What is the population or sample size used in the research? How was the data collected and analyzed? Use 3-5 bullet points to show the response",
"Findings and Results": "What are the key findings or results presented in the paper? Are there any specific statistics, figures, or tables that highlight the results? How do the findings relate to the research question and objectives? Use 3-5 bullet points to show the response",
"Discussion and Conclusions": "What are the main conclusions drawn by the authors based on the findings? What are the limitations of the study or areas for future research? How do the paper's conclusions contribute to the existing body of knowledge in the field? Make a 4-5 line of response",
"Related Research": "Write down 5 research topics along with their titles based on this research paper",
"Prototype": "The user wants to write an extended research paper on the provided research paper, so what are the key points I should take care of and how can I proceed with this?"
}


for heading, prompt in prompts.items():
response = agent.query(prompt)
results[heading] = response.response


return results



def get_response(response:dict):
for heading, response in response.items():
st.subheader(heading)
st.write(response)
st.markdown("---")

The function queries the QABot agent for each prompt, retrieves the response, and stores it in a dictionary with the corresponding heading. Finally, it returns a dictionary containing the responses for each section of the review. This function facilitates the automated generation of detailed research paper reviews, enabling researchers and students to quickly analyze and understand the key aspects of a paper.

get_response()

This function takes a dictionary of responses as input, where each key represents a section heading and its corresponding value is the response text. It iterates through the dictionary, displaying each section heading as a subheader followed by its respective response text.

Creating an Entry Point for the Application ‘app.py’

It ensures that the OpenAI API key is available either directly through an environment variable or by accessing it from a .env file using the load_dotenv() function.

import os
from PIL import Image
from pathlib import Path
from utils import utils
import streamlit as st
from urllib.parse import urlparse, parse_qs
from dotenv import load_dotenv; load_dotenv()
from lyzr import QABot


# Literature Review Application

# replace this with your openai api key or create an environment variable for storing the key.
os.environ["OPENAI_API_KEY"] = os.getenv('OPENAI_API_KEY')


data = "data"
os.makedirs(data, exist_ok=True)


def file_checker():
file = []
for filename in os.listdir(data):
file_path = os.path.join(data, filename)
file.append(file_path)


return file

A directory named “data” is created using os.makedirs() to store the uploaded research papers. If the directory already exists, it will not be recreated due to the exist_ok=True parameter.

file_checker()

Function is designed to check for the presence of files in the specified directory. This function is useful for verifying if there are any files present in the directory, which is helpful for subsequent operations or checks within the application.

Literature Review by QABot Agent

Function is responsible for setting up and initializing the Lyzr’s QABot Agent to review a research paper. It first calls the get_files_in_directory() function from the utils module to obtain the path of the uploaded research paper stored in the “data” directory.

def literature_review():
# "This function will implement the Lyzr's QA agent to review the Research Paper"
path = utils.get_files_in_directory(data)
path = path[0]

reviewer = QABot.pdf_qa(
input_files=[Path(path)]
)

return reviewer

Then, it extracts the path of the research paper from the list of file paths obtained and assigns it to the variable path. it initializes the Lyzr’s QA agent using the pdf_qa() method from the QABot class, passing the path of the research paper as an input file and it returns the initialized QA agent, which is ready to review the research paper.

Initiate the Application

This script serves as the main entry point for a Streamlit application designed to facilitate the review of research papers. It prompts users to upload PDF files, which are then processed by Lyzr’s QA agent for analysis. If a file is uploaded, the application displays a “Review” button, triggering the QA analysis upon clicking.

if __name__ == "__main__":
research_paper = st.file_uploader("Choose Research paper", type=["pdf"])

if research_paper is not None:
utils.save_uploaded_file(directory=data, uploaded_file=research_paper)
file = file_checker()
if len(file)>0:
if st.button("Review"):
research_review = literature_review()
responses = utils.reviewer(agent=research_review)
if responses is not None:
utils.get_response(response=responses)

else:
st.warning('Please upload a research paper in pdf')

The obtained insights, including summaries and key points, are then presented to the user. If no file is uploaded, a warning message prompts the user to provide a PDF file for review.

Literature Review by Lyzr offers a transformative solution for researchers seeking to enhance their literature review process. By harnessing the power of AI, the application simplifies the task of summarizing and analyzing research papers, empowering researchers to stay informed and make meaningful contributions to their respective fields.

References

For further exploration and engagement, refer to Lyzr’s website, book a demo, or join the community channels on Discord and Slack.

Literature Review : GitHub

Lyzr Website: https://www.lyzr.ai/

Book a Demo: https://www.lyzr.ai/book-demo/

Lyzr Community Channels: Discord, Slack

--

--