File size: 1,265 Bytes
e57cedf
63be124
fec6ac6
4a7c728
fec6ac6
 
 
e57cedf
fec6ac6
 
e57cedf
fec6ac6
 
 
 
 
 
e57cedf
fec6ac6
 
 
 
 
 
e57cedf
fec6ac6
 
 
 
e57cedf
fec6ac6
 
e57cedf
fec6ac6
 
 
 
 
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
import streamlit as st
import transformers
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM

# Title
st.markdown("<h1 style='text-align: center; color: black;'>Text Summarization App</h1>", unsafe_allow_html=True)
st.markdown("---")

# Model Selection
model_choice = st.selectbox("Select a Summarization Model", ["BART", "T5", "PEGASUS"])

# Load model and tokenizer
@st.cache_resource
def load_model(model_name):
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
    return pipeline("summarization", model=model, tokenizer=tokenizer)

# Map choices to model names or paths
model_map = {
    "BART": "facebook/bart-large-cnn",
    "T5": "t5-small",
    "PEGASUS": "google/pegasus-cnn_dailymail"
}

# Text Input
text_input = st.text_area("Enter the text you want to summarize:", height=300)

# Button to generate summary
if st.button("Summarize"):
    if not text_input.strip():
        st.warning("Please enter some text!")
    else:
        summarizer = load_model(model_map[model_choice])
        summary = summarizer(text_input, max_length=150, min_length=40, do_sample=False)
        
        st.markdown("### Summary:")
        st.success(summary[0]['summary_text'])