Skip to content

This is sample code demonstrating the use of Amazon Bedrock and Generative AI to implement a long document summarization use case. The application is constructed with a simple streamlit frontend where users can upload large documents and get them summarized.

License

Notifications You must be signed in to change notification settings

ryanadoty/Amazon-Bedrock-Summarization-Long-Document-POC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Amazon-Bedrock-Summarization-Long-Document-POC

This is sample code demonstrating the use of Amazon Bedrock and Generative AI to implement a long document summarization use case. The application is constructed with a simple streamlit frontend where users can upload large documents and get them summarized.

Goal of this Repo:

The goal of this repo is to provide users the ability to use Amazon Bedrock and generative AI to create summaries of large PDF files with chunking logic. This repo comes with a basic frontend to help users stand up a proof of concept in just a few minutes.

The architecture and flow of the sample application will be:

Alt text

When a user interacts with the GenAI app, the flow is as follows:

  1. The user uploads a PDF file to the streamlit app. (app.py).
  2. The streamlit app, takes the PDF document, saves it, and chunks the document (doc_summarizer.py).
  3. Each chunk of the document is passed into Amazon Bedrock, which summarizes each chunk, and then performs a summarization of all chunks (doc_summarizer.py).
  4. After the final summarization is completed, the final summary is presented on the streamlit app (app.py).

How to use this Repo:

Prerequisites:

  1. Amazon Bedrock Access and CLI Credentials.
  2. Ensure Python 3.9 installed on your machine, it is the most stable version of Python for the packages we will be using, it can be downloaded here.

Step 1:

The first step of utilizing this repo is performing a git clone of the repository.

git clone https://github.com/aws-rdoty/Amazon-Bedrock-Summarization-Long-Document-POC.git

After cloning the repo onto your local machine, open it up in your favorite code editor. The file structure of this repo is broken into 3 key files, the app.py file, the doc_summarizer.py file, and the requirements.txt. The app.py file houses the frontend application (a streamlit app). The doc_summarizer.py file houses the logic of the application, including the document chunking logic and Amazon Bedrock API invocations. The requirements.txt file contains all necessary dependencies for this sample application to work.

Step 2:

Set up a python virtual environment in the root directory of the repository and ensure that you are using Python 3.9. This can be done by running the following commands:

pip install virtualenv
python3.9 -m venv venv

The virtual environment will be extremely useful when you begin installing the requirements. If you need more clarification on the creation of the virtual environment please refer to this blog. After the virtual environment is created, ensure that it is activated, following the activation steps of the virtual environment tool you are using. Likely:

cd venv
cd bin
source activate
cd ../../ 

After your virtual environment has been created and activated, you can install all the requirements found in the requirements.txt file by running this command in the root of this repos directory in your terminal:

pip install -r requirements.txt

Step 3:

Now that the requirements have been successfully installed in your virtual environment we can begin configuring environment variables. You will first need to create a .env file in the root of this repo. Within the .env file you just created you will need to configure the .env to contain:

profile_name=<AWS_CLI_PROFILE_NAME>
save_folder=<PATH_TO_ROOT_OF_THIS_REPO>

Please ensure that your AWS CLI Profile has access to Amazon Bedrock, and your Amazon Kendra Index has been created within your AWS account!

Depending on the region and model that you are planning to use Amazon Bedrock in, you may need to reconfigure line 15 & 33 in the doc_summarizer.py file:

bedrock = boto3.client('bedrock-runtime', 'us-east-1', endpoint_url='https://bedrock-runtime.us-east-1.amazonaws.com')

modelId = 'anthropic.claude-v2'

Step 4:

As soon as you have successfully cloned the repo, created a virtual environment, activated it, installed the requirements.txt, and created a .env file, your application should be ready to go. To start up the application with its basic frontend you simply need to run the following command in your terminal while in the root of the repositories' directory:

streamlit run app.py

As soon as the application is up and running in your browser of choice you can begin uploading PDF documents and generating summaries.

The contents of this repository represent my viewpoints and not of my past or current employers, including Amazon Web Services (AWS). All third-party libraries, modules, plugins, and SDKs are the property of their respective owners.

About

This is sample code demonstrating the use of Amazon Bedrock and Generative AI to implement a long document summarization use case. The application is constructed with a simple streamlit frontend where users can upload large documents and get them summarized.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages