File size: 1,249 Bytes
6b672ec
 
3ca9914
0167289
 
 
 
 
 
7192351
0167289
 
 
 
 
7192351
0167289
7192351
0167289
 
 
f7687c4
5f8cfa2
0167289
 
 
 
 
 
5f8cfa2
 
0167289
 
 
 
 
 
 
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
from transformers import pipeline

# Available summarization models (you can expand this list)
available_models = [
    "facebook/t5-small",
    "google/pegasus-xsum",
    "sshleifer/distilbart-cnn-12-6",
]

@st.cache_resource
def load_summarizer(model_name):
    """Loads the summarization pipeline for a given model."""
    summarizer = pipeline("summarization", model=model_name)
    return summarizer

st.title("Text Summarization App")

text_to_summarize = st.text_area("Enter text to summarize:", height=300)

selected_model = st.selectbox("Choose a summarization model:", available_models)

if st.button("Summarize"):
    if text_to_summarize:
        with st.spinner(f"Summarizing using {selected_model}..."):
            summarizer = load_summarizer(selected_model)
            summary = summarizer(text_to_summarize, max_length=150, min_length=30, do_sample=False)[0]['summary_text']
        st.subheader("Summary:")
        st.write(summary)
    else:
        st.warning("Please enter some text to summarize.")

st.sidebar.header("About")
st.sidebar.info(
    "This app uses the `transformers` library from Hugging Face "
    "to perform text summarization. You can select from various "
    "pre-trained models."
)