-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext_summarization_llm_app.py
61 lines (48 loc) · 1.86 KB
/
text_summarization_llm_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import json
import boto3
import streamlit as st
bedrock = boto3.client(service_name="bedrock-runtime", region_name='us-east-1')
PROMPT = """
{Composition}
[INST]You are a summarization system that can provide a summary with a confidence score. In clear and concise language 600 words or less provide a short summary of the following text, along with a confidence score. Do not provide explanations.[/INST]
"""
MODELID = "mistral.mistral-large-2402-v1:0"
def streamlit_ui():
st.set_page_config("Text Summarization LLM Application")
st.markdown("""
<style>
.reportview-container {
margin-top: -2em;
}
#MainMenu {visibility: hidden;}
.stDeployButton {display:none;}
footer {visibility: hidden;}
#stDecoration {display:none;}
</style>
""", unsafe_allow_html=True)
st.header("Text Summarization LLM Application")
user_input = st.text_area("Text to summarize.", height=300)
if st.button("Summarize Now") or user_input:
if not user_input:
st.error("Please provide text to summarize.")
return
with st.spinner("Summarizing..."):
completed_prompt = PROMPT.format(Composition=user_input)
body = json.dumps({
"prompt": completed_prompt,
"max_tokens": 3072,
"top_p": 0.8,
"temperature": 0.5,
})
response = bedrock.invoke_model(
body=body,
modelId=MODELID,
accept="application/json",
contentType="application/json"
)
response_json = json.loads(response["body"].read())
text = response_json['outputs'][0]['text']
st.write(text)
st.success('Summary Completed!')
if __name__ == "__main__":
streamlit_ui()