Spaces:
Sleeping
Sleeping
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", | |
] | |
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." | |
) |