File size: 1,320 Bytes
1bb6412
 
e790906
1bb6412
e790906
 
1bb6412
e790906
 
 
51cf594
1bb6412
51cf594
 
 
 
 
 
e790906
 
51cf594
e790906
 
 
 
 
 
 
 
 
a356742
51cf594
e790906
 
b227ad0
e790906
 
 
 
 
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
import streamlit as st
from transformers import AutoTokenizer
from transformers import AutoModelForSeq2SeqLM

# Set up the Streamlit app
st.title("Text Summarization")

# Load the summarization model
@st.cache_resource
def load_summarizer():
    return AutoModelForSeq2SeqLM.from_pretrained("madanagrawal/summarization_model")

# Load the tokenizer
@st.cache_resource
def load_tokenizer():
    return AutoTokenizer.from_pretrained("madanagrawal/summarization_model")

tokenizer = load_tokenizer()
summarizer = load_summarizer()


# Create a text input for the user
text_input = st.text_area("Enter the text you want to summarize:", height=200)

# Create a slider for selecting the maximum length of the summary
max_length = st.slider("Select the maximum length of the summary:", min_value=50, max_value=500, value=150, step=10)

# Create a button to trigger the summarization
if st.button("Summarize"):
    if text_input:
        inputs = tokenizer(text_input, return_tensors="pt").input_ids

        # Generate the summary
        summary = summarizer.generate(inputs, max_new_tokens=max_length, do_sample=False)

        # Display the summary
        st.subheader("Summary:")
        st.write(tokenizer.decode(summary[0], skip_special_tokens=True))
    else:
        st.warning("Please enter some text to summarize.")