import streamlit as st from transformers import pipeline def main(): st.title("Text Summarization") # Initialize the summarizer pipeline with a more powerful model summarizer = pipeline( task="summarization", model="facebook/bart-large-cnn", # Consider using a larger model min_length=50, max_length=150, truncation=True, ) # User input input_text = st.text_area("Enter the text you want to summarize:", height=200) # Summarize button if st.button("Summarize"): if input_text: # Split the text into smaller chunks if it's too long max_input_length = 1024 # BART can handle up to 1024 tokens input_chunks = [input_text[i:i+max_input_length] for i in range(0, len(input_text), max_input_length)] # Generate the summary for each chunk and combine them summary = "" for chunk in input_chunks: output = summarizer(chunk, max_length=150, min_length=50, do_sample=False) summary += output[0]['summary_text'] + " " # Display the summary as bullet points st.subheader("Summary:") bullet_points = summary.split(". ") for point in bullet_points: if point: # Ensure that empty strings are not included st.write(f"- {point.strip()}") else: st.warning("Please enter text to summarize.") if __name__ == "__main__": main()