Now we’re ready to run the Streamlit web application for our question answering bot.
SageMaker Studio provides a convenient platform to host the Streamlit web application. The following steps describe how to run the Streamlit app on JupyterLab in SageMaker Studio. Alternatively, you could also follow the same procedure to run the app on Amazon EC2 instance or Cloud9 in your AWS Account.
-
Open JupyterLab and then open a new Terminal.
-
Run the following commands on the terminal to clone the code repository for this post and install the Python packages needed by the application:
git clone --depth=1 https://github.com/aws-samples/rag-with-amazon-bedrock-and-documentdb.git cd rag-with-amazon-bedrock-and-documentdb/app python -m venv .env source .env/bin/activate pip install -U -r requirements.txt
-
Download the Amazon DocumentDB Certificate Authority (CA) certificate required to authenticate to your instance
curl -o global-bundle.pem https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem
-
In the shell, set the following environment variables with the values that are available from the CloudFormation stack output.
export AWS_REGION="us-east-1" export DOCDB_SECRET_NAME="{DocumentDB-Secret-Name}" export DOCDB_HOST="{docdb-cluster-name}.cluster-{random-id}.{region}.docdb.amazonaws.com" export DB_NAME="ragdemo" export COLLECTION_NAME="rag" export BEDROCK_MODEL_ID="anthropic.claude-v2:1"
ℹ️
COLLECTION_NAME
can be found in data ingestion to vectordb step. -
When the application runs successfully, you’ll see an output similar to the following (the IP addresses you will see will be different from the ones shown in this example). Note the port number (typically
8501
) from the output to use as part of the URL for app in the next step.sagemaker-user@studio$ streamlit run app.py Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False. You can now view your Streamlit app in your browser. Network URL: http://169.255.255.2:8501 External URL: http://52.4.240.77:8501
-
You can access the app in a new browser tab using a URL that is similar to your Studio domain URL. For example, if your Studio URL is
https://d-randomidentifier.studio.us-east-1.sagemaker.aws/jupyter/default/lab?
then the URL for your Streamlit app will behttps://d-randomidentifier.studio.us-east-1.sagemaker.aws/jupyter/default/proxy/8501/app
(notice thatlab
is replaced withproxy/8501/app
). If the port number noted in the previous step is different from 8501 then use that instead of 8501 in the URL for the Streamlit app.The following screenshot shows the app with a couple of user questions. (e.g.,
What are some reasons a highly regulated industry should pick DocumentDB?
)
- Vector search for Amazon DocumentDB
- Build Streamlit apps in Amazon SageMaker Studio (2023-04-11)
- Connecting Programmatically to Amazon DocumentDB
- Amazon Bedrock - Inference parameters for foundation models
- LangChain - A framework for developing applications powered by language models.
- LangChain Providers - AWS - The
LangChain
integrations related toAmazon AWS
platform. - Streamlit - A faster way to build and share data apps
- PyMongo - A Python distribution containing tools for working with MongoDB.