# streamlit_app.py import streamlit as st from transformers import AutoTokenizer, AutoModelForSeq2SeqLM st.set_page_config(page_title="Text Summarizer", layout="centered") st.title("📝 Text Summarization App") input_text = st.text_area("Enter text to summarize", height=200) @st.cache_resource def load_model(): model = AutoModelForSeq2SeqLM.from_pretrained("google/pegasus-cnn_dailymail") tokenizer = AutoTokenizer.from_pretrained("google/pegasus-cnn_dailymail") return model, tokenizer if st.button("Summarize"): if input_text.strip() == "": st.warning("Please enter some text.") else: try: with st.spinner("Summarizing..."): model, tokenizer = load_model() inputs = tokenizer(input_text, return_tensors="pt", truncation=True) summary_ids = model.generate( inputs["input_ids"], max_length=100, min_length=30, length_penalty=2.0, num_beams=4, early_stopping=True ) summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True) st.subheader("Summary") st.success(summary) except Exception as e: st.error(f"Error: {e}")