Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load model (cached)
|
| 5 |
+
@st.cache_resource
|
| 6 |
+
def load_summarizer():
|
| 7 |
+
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
| 8 |
+
return summarizer
|
| 9 |
+
|
| 10 |
+
summarizer = load_summarizer()
|
| 11 |
+
|
| 12 |
+
# Streamlit UI
|
| 13 |
+
st.set_page_config(page_title="Text Summarizer", layout="centered")
|
| 14 |
+
st.title("📝 Text Summarizer")
|
| 15 |
+
st.markdown("Enter a long piece of text, and this app will summarize it using a Hugging Face transformer model.")
|
| 16 |
+
|
| 17 |
+
# Input box
|
| 18 |
+
text_input = st.text_area("Enter your text here", height=300)
|
| 19 |
+
|
| 20 |
+
# Button to summarize
|
| 21 |
+
if st.button("Summarize"):
|
| 22 |
+
if not text_input.strip():
|
| 23 |
+
st.warning("⚠️ Please enter some text first.")
|
| 24 |
+
else:
|
| 25 |
+
with st.spinner("Summarizing..."):
|
| 26 |
+
try:
|
| 27 |
+
summary = summarizer(text_input, max_length=130, min_length=30, do_sample=False)
|
| 28 |
+
st.subheader("Summary:")
|
| 29 |
+
st.success(summary[0]['summary_text'])
|
| 30 |
+
except Exception as e:
|
| 31 |
+
st.error(f"❌ Error during summarization: {e}")
|