generated from streamlit/blank-app-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_app.py
38 lines (32 loc) · 1.2 KB
/
streamlit_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import streamlit as st
import boto3
st.title("Amazon Bedrock Integration with Streamlit")
bedrock = boto3.client(
service_name='bedrock',
region_name='us-west-2' # Make sure this is a supported Bedrock region
)
def query_bedrock(model_id, input_text):
response = bedrock.invoke_model(
modelId=model_id,
body={'text': input_text} # Replace with the correct input format for Bedrock
)
# Process response based on Bedrock's response format
output = response['body'].read().decode('utf-8')
return output
# Get user input
user_input = st.text_area("Enter your question or query:")
# Define model ID (make sure this is available in Bedrock)
model_id = "your-model-id"
# Button to trigger Bedrock API
if st.button("Get Answer"):
if user_input:
with st.spinner("Querying Amazon Bedrock..."):
# Get response from Bedrock
try:
bedrock_response = query_bedrock(model_id, user_input)
st.write("Response from Bedrock:")
st.write(bedrock_response)
except Exception as e:
st.error(f"Error querying Bedrock: {e}")
else:
st.warning("Please enter some text to query.")