Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,38 @@
|
|
1 |
import streamlit as st
|
2 |
import transformers
|
|
|
3 |
|
4 |
-
|
|
|
|
|
5 |
|
6 |
-
|
|
|
7 |
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
11 |
|
|
|
|
|
|
|
|
|
12 |
if st.button("Summarize"):
|
13 |
-
if
|
14 |
-
|
15 |
-
elif model_choice == "T5":
|
16 |
-
summarizer = pipeline("summarization", model="T5")
|
17 |
else:
|
18 |
-
summarizer =
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
1 |
import streamlit as st
|
2 |
import transformers
|
3 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
|
5 |
+
# Title
|
6 |
+
st.markdown("<h1 style='text-align: center; color: black;'>Text Summarization App</h1>", unsafe_allow_html=True)
|
7 |
+
st.markdown("---")
|
8 |
|
9 |
+
# Model Selection
|
10 |
+
model_choice = st.selectbox("Select a Summarization Model", ["BART", "T5", "PEGASUS"])
|
11 |
|
12 |
+
# Load model and tokenizer
|
13 |
+
@st.cache_resource
|
14 |
+
def load_model(model_name):
|
15 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
16 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
17 |
+
return pipeline("summarization", model=model, tokenizer=tokenizer)
|
18 |
|
19 |
+
# Map choices to model names or paths
|
20 |
+
model_map = {
|
21 |
+
"BART": "facebook/bart-large-cnn",
|
22 |
+
"T5": "t5-small",
|
23 |
+
"PEGASUS": "google/pegasus-cnn_dailymail"
|
24 |
+
}
|
25 |
|
26 |
+
# Text Input
|
27 |
+
text_input = st.text_area("Enter the text you want to summarize:", height=300)
|
28 |
+
|
29 |
+
# Button to generate summary
|
30 |
if st.button("Summarize"):
|
31 |
+
if not text_input.strip():
|
32 |
+
st.warning("Please enter some text!")
|
|
|
|
|
33 |
else:
|
34 |
+
summarizer = load_model(model_map[model_choice])
|
35 |
+
summary = summarizer(text_input, max_length=150, min_length=40, do_sample=False)
|
36 |
+
|
37 |
+
st.markdown("### Summary:")
|
38 |
+
st.success(summary[0]['summary_text'])
|