File size: 1,510 Bytes
1d5d9de
 
 
 
 
 
94456cb
1d5d9de
 
94456cb
 
 
1d5d9de
94456cb
1d5d9de
 
 
 
 
 
 
94456cb
 
 
 
 
 
 
 
 
1d5d9de
 
 
 
 
94456cb
 
1d5d9de
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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()