text-summarizer / app.py
KomalDahiya's picture
Update app.py
00bb000 verified
import streamlit as st
from transformers import pipeline
# 🧠 Set up the page
st.set_page_config(page_title="Text Summarizer", layout="wide")
# πŸ”„ Load summarizer model
@st.cache_resource
#def load_model():
#return pipeline(
#"summarization",
#model="knkarthick/MEETING_SUMMARY",
#tokenizer="knkarthick/MEETING_SUMMARY",
#truncation=True
#)
def load_model():
return pipeline("summarization", model="facebook/bart-large-cnn")
summarizer = load_model()
# 🎨 Title and Subtitle
st.markdown("<h1 style='text-align: center;'>LLM- Powered Text Summarizer</h1>", unsafe_allow_html=True)
#st.markdown("<p style='text-align: center; color: gray;'>This app summarizes large texts efficiently using a lightweight model suited for Hugging Face CPU Spaces.</p>", unsafe_allow_html=True)
# πŸ”² Two-column layout
col1, col2 = st.columns(2)
with col1:
st.markdown("### Enter Text here...")
text = st.text_area("Enter your long text here...", height=400, label_visibility="collapsed")
with col2:
st.markdown("### Summary:")
summary_output = st.empty()
# πŸ›‘ Prevent crash from large input
text = " ".join(text.split()[:700]) # ~500–700 words safe for token limits
# ▢️ Generate summary
if st.button("πŸ” Summarize Now"):
if text.strip() == "":
st.warning("Please enter some text to summarize.")
else:
with st.spinner("Generating summary..."):
try:
output = summarizer(
text,
max_length=120,
min_length=40,
do_sample=False
)
result = output[0]['summary_text']
summary_output.text_area("Summary Result", value=result, height=400, label_visibility="collapsed")
except Exception as e:
st.error(f"Error generating summary: {e}")
# πŸ‘£ Footer
#st.markdown("""
# <hr style="margin-top: 2em;">
# <p style='text-align: center; color: gray;'>Made with ❀️ by Komal Dahiya | Powered by Hugging Face & Streamlit</p>
#""", unsafe_allow_html=True)