Streamline Your Literature Review Process with Lyzr's AI-Powered Application

prajjwalsule21

Prajjwal Sule

Posted on March 25, 2024

Streamline Your Literature Review Process with Lyzr's AI-Powered Application

In the fast-paced world of academia and research, staying updated with the latest findings and insights is crucial. However, the process of reviewing numerous research papers to extract relevant information can be time-consuming and laborious.

Literature Review by Lyzr 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.


Welcome to Lyzr! | Lyzr Documentation

Explore the limitless possibilities of Generative AI with Lyzr, an enterprise alternative to popular Generative AI SaaS products. Lyzr offers a robust and secure solution for building and launching your own enterprise-grade Generative AI applications with speed and confidence.

favicon docs.lyzr.ai

In this article, we'll walk you through the process of building this GenAI application with Lyzr's QABot agent. We'll cover everything from setting up the project to implementing key functionalities using low code and minimal effort.

Setting up the Project

Clone the "Literature Review Assistant" app repository.

Set up a virtual environment

python3 -m venv venv
source venv/bin/activate

Enter fullscreen mode Exit fullscreen mode

Create an environment file named .env and add your OpenAI API key

OPENAI_API_KEY = "Your_OpenAI_API_Key"

Enter fullscreen mode Exit fullscreen mode

Install the required dependencies

pip install lyzr streamlit pdfminer.six

Enter fullscreen mode Exit fullscreen mode

Project Structure

Literature-Review


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

├── app.py

├── README.md

├── .env

├── .gitignore

└── requirements.txt
Enter fullscreen mode Exit fullscreen mode

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.

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


def get_files_in_directory(directory):
    # This function help us to get the file path along with filename.
    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

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")
Enter fullscreen mode Exit fullscreen mode

remove_existing_files: Removes existing files and directories within a specified directory.
get_files_in_directory: Retrieves a list of file paths within a specified directory.
save_uploaded_file: Saves an uploaded file to a specified directory.

Guidance for QABot Agent

The QABot agent facilitates the review process by generating prompts for summarizing research papers. Functions like reviewer and get_response handle interactions with the QABot agent and present the results to the user.

def reviewer(agent):
    results = {}
    prompts = {
        "Summary" : "Write a 2 lines of brief summary about this research paper in 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 Resarch":"Write down 5 research topic along with their titles based on in this research paper",
        "Prototype":"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("---")  
Enter fullscreen mode Exit fullscreen mode

Initiating the Application

The app.py file serves as the entry point for the application. It prompts users to upload PDF files for review and initiates the review process upon user interaction


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

Enter fullscreen mode Exit fullscreen mode

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() 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

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
Enter fullscreen mode Exit fullscreen mode

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')
Enter fullscreen mode Exit fullscreen mode

Conclusion

Literature Review by Lyzr revolutionizes the literature review process, empowering researchers to extract key insights from research papers efficiently. By combining AI capabilities with a user-friendly interface, Lyzr simplifies the task of summarizing and analyzing academic literature.

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

💖 💪 🙅 🚩
prajjwalsule21
Prajjwal Sule

Posted on March 25, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related