Spaces:
Running
Running
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 | |
#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) | |