Spaces:
Runtime error
Runtime error
Update summarizer.py
Browse files- summarizer.py +20 -6
summarizer.py
CHANGED
@@ -1,10 +1,24 @@
|
|
1 |
from transformers import pipeline
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
def summarize_text(text, max_length=100):
|
6 |
-
"""
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from transformers import pipeline
|
2 |
|
3 |
+
# Use distilled summarization model
|
4 |
+
summarizer = pipeline(
|
5 |
+
"summarization",
|
6 |
+
model="sshleifer/distilbart-cnn-12-6",
|
7 |
+
tokenizer="sshleifer/distilbart-cnn-12-6"
|
8 |
+
)
|
9 |
|
10 |
def summarize_text(text, max_length=100):
|
11 |
+
"""Efficient CPU summarization"""
|
12 |
+
if len(text) < 200:
|
13 |
+
return text
|
14 |
+
|
15 |
+
# Truncate to model's max capacity
|
16 |
+
truncated = text[:1024]
|
17 |
+
|
18 |
+
return summarizer(
|
19 |
+
truncated,
|
20 |
+
max_length=max_length,
|
21 |
+
min_length=30,
|
22 |
+
do_sample=False, # Faster without sampling
|
23 |
+
truncation=True
|
24 |
+
)[0]['summary_text']
|