Dhanush S Gowda
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load models and tokenizers using Hugging Face's pipeline
|
5 |
+
# @st.cache_data()
|
6 |
+
def load_pipelines():
|
7 |
+
bart_pipeline = pipeline("summarization", model="facebook/bart-large-cnn")
|
8 |
+
t5_pipeline = pipeline("summarization", model="t5-large")
|
9 |
+
pegasus_pipeline = pipeline("summarization", model="google/pegasus-cnn_dailymail")
|
10 |
+
|
11 |
+
return {
|
12 |
+
'BART': bart_pipeline,
|
13 |
+
'T5': t5_pipeline,
|
14 |
+
'Pegasus': pegasus_pipeline,
|
15 |
+
}
|
16 |
+
|
17 |
+
prompt = """
|
18 |
+
Summarize the below paragraph
|
19 |
+
"""
|
20 |
+
|
21 |
+
# Streamlit app layout
|
22 |
+
st.title("Text Summarization with Pre-trained Models (BART, T5, Pegasus)")
|
23 |
+
|
24 |
+
text_input = st.text_area("Enter text to summarize:")
|
25 |
+
|
26 |
+
if st.button("Generate Summary"):
|
27 |
+
if text_input:
|
28 |
+
pipelines = load_pipelines()
|
29 |
+
summaries = {}
|
30 |
+
for model_name, pipeline in pipelines.items():
|
31 |
+
summary = pipeline(f"{prompt}\n{text_input}", max_length=150, min_length=50, length_penalty=2.0, num_beams=4, early_stopping=True)[0]['summary_text']
|
32 |
+
summaries[model_name] = summary
|
33 |
+
|
34 |
+
st.subheader("Summaries")
|
35 |
+
for model_name, summary in summaries.items():
|
36 |
+
st.write(f"**{model_name}**")
|
37 |
+
st.write(summary.replace('<n>', ''))
|
38 |
+
st.write("---")
|
39 |
+
else:
|
40 |
+
st.error("Please enter text to summarize.")
|