File size: 1,160 Bytes
bead53b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline

# Title and description
st.title("Text Summarizer")
st.markdown("Summarize long paragraphs using the Hugging Face `facebook/bart-large-cnn` model.")

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

summarizer = load_summarizer()

# Input area for the long text
user_input = st.text_area("Enter text to summarize:", placeholder="Paste a long paragraph here...", height=200)

# Summarize button
if st.button("Summarize"):
    if user_input.strip():
        with st.spinner("Summarizing text..."):
            # Perform summarization
            summary = summarizer(user_input, max_length=130, min_length=30, do_sample=False)
            summarized_text = summary[0]["summary_text"]

        # Display the summarized text
        st.markdown("### Summarized Text:")
        st.write(summarized_text)
    else:
        st.warning("Please enter some text to summarize.")

# Footer
st.markdown("---")
st.markdown("Powered by [Hugging Face Transformers](https://huggingface.co/transformers/) and Streamlit.")