Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Title and description
|
| 5 |
+
st.title("Text Summarizer")
|
| 6 |
+
st.markdown("Summarize long paragraphs using the Hugging Face `facebook/bart-large-cnn` model.")
|
| 7 |
+
|
| 8 |
+
# Load the summarization pipeline
|
| 9 |
+
@st.cache_resource
|
| 10 |
+
def load_summarizer():
|
| 11 |
+
return pipeline("summarization", model="facebook/bart-large-cnn")
|
| 12 |
+
|
| 13 |
+
summarizer = load_summarizer()
|
| 14 |
+
|
| 15 |
+
# Input area for the long text
|
| 16 |
+
user_input = st.text_area("Enter text to summarize:", placeholder="Paste a long paragraph here...", height=200)
|
| 17 |
+
|
| 18 |
+
# Summarize button
|
| 19 |
+
if st.button("Summarize"):
|
| 20 |
+
if user_input.strip():
|
| 21 |
+
with st.spinner("Summarizing text..."):
|
| 22 |
+
# Perform summarization
|
| 23 |
+
summary = summarizer(user_input, max_length=130, min_length=30, do_sample=False)
|
| 24 |
+
summarized_text = summary[0]["summary_text"]
|
| 25 |
+
|
| 26 |
+
# Display the summarized text
|
| 27 |
+
st.markdown("### Summarized Text:")
|
| 28 |
+
st.write(summarized_text)
|
| 29 |
+
else:
|
| 30 |
+
st.warning("Please enter some text to summarize.")
|
| 31 |
+
|
| 32 |
+
# Footer
|
| 33 |
+
st.markdown("---")
|
| 34 |
+
st.markdown("Powered by [Hugging Face Transformers](https://huggingface.co/transformers/) and Streamlit.")
|