Spaces:
Build error
Build error
Updated
Browse files
app.py
CHANGED
|
@@ -1,25 +1,38 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
st.title("Text Summarizer")
|
| 13 |
-
st.write("This app uses Hugging Face's transformers to summarize any text you provide.")
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
if st.button("Summarize"):
|
| 19 |
-
if
|
| 20 |
-
with st.spinner("Summarizing..."):
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
else:
|
| 25 |
st.warning("Please enter some text to summarize.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Available summarization models (you can expand this list)
|
| 5 |
+
available_models = [
|
| 6 |
+
"facebook/t5-small",
|
| 7 |
+
"google/pegasus-xsum",
|
| 8 |
+
"sshleifer/distilbart-cnn-12-6",
|
| 9 |
+
]
|
| 10 |
|
| 11 |
+
@st.cache_resource
|
| 12 |
+
def load_summarizer(model_name):
|
| 13 |
+
"""Loads the summarization pipeline for a given model."""
|
| 14 |
+
summarizer = pipeline("summarization", model=model_name)
|
| 15 |
+
return summarizer
|
| 16 |
|
| 17 |
+
st.title("Text Summarization App")
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
text_to_summarize = st.text_area("Enter text to summarize:", height=300)
|
| 20 |
+
|
| 21 |
+
selected_model = st.selectbox("Choose a summarization model:", available_models)
|
| 22 |
|
| 23 |
if st.button("Summarize"):
|
| 24 |
+
if text_to_summarize:
|
| 25 |
+
with st.spinner(f"Summarizing using {selected_model}..."):
|
| 26 |
+
summarizer = load_summarizer(selected_model)
|
| 27 |
+
summary = summarizer(text_to_summarize, max_length=150, min_length=30, do_sample=False)[0]['summary_text']
|
| 28 |
+
st.subheader("Summary:")
|
| 29 |
+
st.write(summary)
|
| 30 |
else:
|
| 31 |
st.warning("Please enter some text to summarize.")
|
| 32 |
+
|
| 33 |
+
st.sidebar.header("About")
|
| 34 |
+
st.sidebar.info(
|
| 35 |
+
"This app uses the `transformers` library from Hugging Face "
|
| 36 |
+
"to perform text summarization. You can select from various "
|
| 37 |
+
"pre-trained models."
|
| 38 |
+
)
|