Nomantariq's picture
Upload summary.py
232fde4 verified
import streamlit as st
from transformers import pipeline
# Page config
st.set_page_config(page_title="Text Summarizer", page_icon="πŸ“", layout="centered")
# Header
st.markdown("<h1 style='text-align: center; color: #008080;'>πŸ“ Text Summarizer</h1>", unsafe_allow_html=True)
st.markdown("<p style='text-align: center;'>Summarize long text into a few key lines using a Hugging Face model!</p>", unsafe_allow_html=True)
# Input
text = st.text_area("πŸ“„ Enter long text here:", height=200, placeholder="Paste or type a long article or paragraph...")
# Button
if st.button("πŸ“Œ Summarize"):
if len(text.strip()) < 30:
st.warning("⚠️ Please enter at least a few meaningful sentences.")
else:
# Use a faster model
summarizer = pipeline("summarization", model="t5-small")
summary = summarizer(text, max_length=120, min_length=30, do_sample=False)[0]['summary_text']
st.success("βœ… Summary:")
st.write(summary)
# Display original text
st.write("πŸ“„ Original Text:")
st.write(text)
# Display word count
word_count = len(text.split())
st.write(f"πŸ“š Word Count: {word_count}")
# Display character count
char_count = len(text)
st.write(f"πŸ“ Character Count: {char_count}")