File size: 971 Bytes
f0e9fc5
 
 
9c8b074
 
 
f0e9fc5
 
 
 
9c8b074
 
f0e9fc5
9c8b074
f0e9fc5
 
 
9c8b074
 
 
 
 
 
 
 
 
 
 
 
 
f0e9fc5
 
 
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
import streamlit as st
from transformers import pipeline, set_seed

def generate_summary(text):
    # Load the summarization model
    summarizer = pipeline("summarization", model="t5-base", max_length=1024, min_length=40)

    # Set a random seed for reproducibility
    set_seed(1)

    # Generate summary
    summary = summarizer(text, num_beams=4, no_repeat_ngram_size=2, length_penalty=2.0, early_stopping=True)[0]['summary_text']

    return summary

def main():
    # Set the app title
    st.title("Text Summarizer")

    # Create a text box for user input
    input_text = st.text_area("Enter text to summarize", "")

    # Create a button to generate the summary
    if st.button("Summarize"):
        # Generate summary based on user input
        if input_text:
            summary = generate_summary(input_text)
            st.write(summary)
        else:
            st.warning("Please enter some text to summarize.")

if __name__ == "__main__":
    main()