Dhanush S Gowda
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,40 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
-
# Load
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
'Pegasus': pegasus_pipeline,
|
14 |
-
}
|
15 |
-
|
16 |
-
prompt = """
|
17 |
-
Summarize the below paragraph
|
18 |
-
"""
|
19 |
|
20 |
# Streamlit app layout
|
21 |
st.title("Text Summarization with Pre-trained Models (BART, T5, Pegasus)")
|
22 |
|
23 |
text_input = st.text_area("Enter text to summarize:")
|
24 |
|
25 |
-
if
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
st.subheader("
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
st.error("Please enter text to summarize.")
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
+
import time
|
4 |
|
5 |
+
# Load selected model's pipeline
|
6 |
+
@st.cache_resource
|
7 |
+
def load_pipeline(model_name):
|
8 |
+
if model_name == 'BART':
|
9 |
+
return pipeline("summarization", model="facebook/bart-large-cnn")
|
10 |
+
elif model_name == 'T5':
|
11 |
+
return pipeline("summarization", model="t5-large")
|
12 |
+
elif model_name == 'Pegasus':
|
13 |
+
return pipeline("summarization", model="google/pegasus-cnn_dailymail")
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
# Streamlit app layout
|
16 |
st.title("Text Summarization with Pre-trained Models (BART, T5, Pegasus)")
|
17 |
|
18 |
text_input = st.text_area("Enter text to summarize:")
|
19 |
|
20 |
+
if text_input:
|
21 |
+
# Display word count of input text
|
22 |
+
word_count = len(text_input.split())
|
23 |
+
st.write(f"**Word Count:** {word_count}")
|
24 |
+
|
25 |
+
model_choice = st.selectbox("Choose a model:", ['BART', 'T5', 'Pegasus'])
|
26 |
+
|
27 |
+
if st.button("Generate Summary"):
|
28 |
+
with st.spinner(f"Generating summary using {model_choice}..."):
|
29 |
+
start_time = time.time()
|
30 |
+
summarizer = load_pipeline(model_choice)
|
31 |
+
summary = summarizer(text_input, max_length=150, min_length=50, length_penalty=2.0, num_beams=4, early_stopping=True)[0]['summary_text']
|
32 |
+
end_time = time.time()
|
33 |
+
summary_word_count = len(summary.split())
|
34 |
|
35 |
+
st.subheader(f"Summary using {model_choice}")
|
36 |
+
st.write(summary.replace('<n>', ''))
|
37 |
+
st.write(f"**Summary Word Count:** {summary_word_count}")
|
38 |
+
st.write(f"**Time Taken:** {end_time - start_time:.2f} seconds")
|
39 |
+
else:
|
40 |
+
st.error("Please enter text to summarize.")
|
|