Spaces:
Sleeping
Sleeping
Update Summary.py
Browse files- Summary.py +23 -0
Summary.py
CHANGED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
|
3 |
+
|
4 |
+
class Summary:
|
5 |
+
|
6 |
+
def __init__(self, text_to_summarise):
|
7 |
+
"""
|
8 |
+
The Constructor for the Summary class.
|
9 |
+
:param text_to_summarise: The text to summarise
|
10 |
+
"""
|
11 |
+
if text_to_summarise is None or len(text_to_summarise.strip()) == 0:
|
12 |
+
raise ValueError("Text to summarise cannot be empty")
|
13 |
+
|
14 |
+
self.text_to_summarise = text_to_summarise
|
15 |
+
|
16 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
17 |
+
|
18 |
+
self.source_text_length = len(text_to_summarise.split(' '))
|
19 |
+
max = int(self.source_text_length * 0.8)
|
20 |
+
min = int(self.source_text_length * 0.6)
|
21 |
+
result = summarizer(text_to_summarise, max_length=max, min_length=min, do_sample=False)
|
22 |
+
self.result = result[0]['summary_text']
|
23 |
+
self.summary_text_length = len(self.result.split(' '))
|