File size: 1,267 Bytes
bd131f0
774a024
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline


# Load the summarization pipeline
@st.cache_resource
def load_summarizer():
    return pipeline("summarization", model="facebook/bart-large-cnn")


summarizer = load_summarizer()

# Streamlit app title and description
st.title("Text Summarization with BART")
st.write("Enter the text you want to summarize below:")

# Text input
text = st.text_area("Input Text", height=300)

# Summarization parameters
st.sidebar.header("Summarization Parameters")
max_length = st.sidebar.slider("Max Length", 50, 500, 150, 10)
min_length = st.sidebar.slider("Min Length", 10, 100, 50, 5)
do_sample = st.sidebar.checkbox("Use Sampling", value=False)

# Summarize button
if st.button("Summarize"):
    if text:
        with st.spinner("Summarizing..."):
            try:
                summary = summarizer(
                    text,
                    max_length=max_length,
                    min_length=min_length,
                    do_sample=do_sample,
                )
                st.subheader("Summary:")
                st.write(summary[0]["summary_text"])
            except Exception as e:
                st.error(f"An error occurred: {e}")
    else:
        st.warning("Please input text to summarize.")