Spaces:
Sleeping
Sleeping
import streamlit as st | |
from transformers import pipeline | |
st.set_page_config(page_title="LLM Text Summarizer", layout="centered") | |
#st.title("LLM-Powered Text Summarizer") | |
#st.markdown("This app summarizes long texts using a Hugging Face transformer model (`facebook/bart-large-cnn`).") | |
def load_model(): | |
return pipeline("summarization", model="facebook/bart-large-cnn") | |
summarizer = load_model() | |
st.markdown("<h1 style='text-align: center;'>🧠 Smart Document Summarizer using BART</h1>", unsafe_allow_html=True) | |
st.markdown("<p style='text-align: center; color: gray;'>This app splits long text into chunks and summarizes each part individually for better results.</p>", unsafe_allow_html=True) | |
# Two columns: Input and Output | |
col1, col2 = st.columns(2) | |
with col1: | |
st.markdown("### 📝 Enter Document") | |
text = st.text_area("Paste your long document here...", height=400, label_visibility="collapsed") | |
with col2: | |
st.markdown("### 🧾 Combined Summary") | |
summary_box = st.empty() | |
#text = st.text_area("Enter text to summarize", height=300) | |
text = " ".join(text.split()[:700]) # Truncate input to ~700 words | |
if st.button("Summarize"): | |
if len(text.strip()) == 0: | |
st.warning("Please enter some text first.") | |
else: | |
word_count = len(text.split()) | |
if word_count > 1300: | |
max_tokens = 1300 | |
elif word_count > 300: | |
max_tokens = 350 | |
else: | |
max_tokens = 100 | |
with st.spinner("Generating summary..."): | |
summary = summarizer( | |
text, | |
max_length=max_tokens, | |
min_length=int(max_tokens * 0.5), | |
do_sample=False | |
) | |
st.subheader("Summary:") | |
st.success(summary[0]['summary_text']) | |