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("
This app summarizes large texts efficiently using a lightweight model suited for Hugging Face CPU Spaces.
", 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(""" #Made with ❤️ by Komal Dahiya | Powered by Hugging Face & Streamlit
#""", unsafe_allow_html=True)