Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,14 +4,14 @@ from transformers import pipeline
|
|
4 |
def main():
|
5 |
st.title("Text Summarization")
|
6 |
|
7 |
-
# Initialize the summarizer pipeline
|
8 |
summarizer = pipeline(
|
9 |
task="summarization",
|
10 |
-
model="facebook/bart-large-cnn", #
|
11 |
-
min_length=50,
|
12 |
-
max_length=150,
|
13 |
truncation=True,
|
14 |
-
)
|
15 |
|
16 |
# User input
|
17 |
input_text = st.text_area("Enter the text you want to summarize:", height=200)
|
@@ -19,15 +19,22 @@ def main():
|
|
19 |
# Summarize button
|
20 |
if st.button("Summarize"):
|
21 |
if input_text:
|
22 |
-
#
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
# Display the summary as bullet points
|
27 |
st.subheader("Summary:")
|
28 |
bullet_points = summary.split(". ")
|
29 |
for point in bullet_points:
|
30 |
-
|
|
|
31 |
else:
|
32 |
st.warning("Please enter text to summarize.")
|
33 |
|
|
|
4 |
def main():
|
5 |
st.title("Text Summarization")
|
6 |
|
7 |
+
# Initialize the summarizer pipeline with a more powerful model
|
8 |
summarizer = pipeline(
|
9 |
task="summarization",
|
10 |
+
model="facebook/bart-large-cnn", # Consider using a larger model
|
11 |
+
min_length=50,
|
12 |
+
max_length=150,
|
13 |
truncation=True,
|
14 |
+
)
|
15 |
|
16 |
# User input
|
17 |
input_text = st.text_area("Enter the text you want to summarize:", height=200)
|
|
|
19 |
# Summarize button
|
20 |
if st.button("Summarize"):
|
21 |
if input_text:
|
22 |
+
# Split the text into smaller chunks if it's too long
|
23 |
+
max_input_length = 1024 # BART can handle up to 1024 tokens
|
24 |
+
input_chunks = [input_text[i:i+max_input_length] for i in range(0, len(input_text), max_input_length)]
|
25 |
+
|
26 |
+
# Generate the summary for each chunk and combine them
|
27 |
+
summary = ""
|
28 |
+
for chunk in input_chunks:
|
29 |
+
output = summarizer(chunk, max_length=150, min_length=50, do_sample=False)
|
30 |
+
summary += output[0]['summary_text'] + " "
|
31 |
|
32 |
# Display the summary as bullet points
|
33 |
st.subheader("Summary:")
|
34 |
bullet_points = summary.split(". ")
|
35 |
for point in bullet_points:
|
36 |
+
if point: # Ensure that empty strings are not included
|
37 |
+
st.write(f"- {point.strip()}")
|
38 |
else:
|
39 |
st.warning("Please enter text to summarize.")
|
40 |
|