Spaces:
Sleeping
Sleeping
from transformers import pipeline | |
class Summary: | |
def __init__(self, text_to_summarise): | |
""" | |
The Constructor for the Summary class. | |
:param text_to_summarise: The text to summarise | |
""" | |
if text_to_summarise is None or len(text_to_summarise.strip()) == 0: | |
raise ValueError("Text to summarise cannot be empty") | |
self.text_to_summarise = text_to_summarise | |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
self.source_text_length = len(text_to_summarise.split(' ')) | |
max = int(self.source_text_length * 0.8) | |
min = int(self.source_text_length * 0.6) | |
result = summarizer(text_to_summarise, max_length=max, min_length=min, do_sample=False) | |
self.result = result[0]['summary_text'] | |
self.summary_text_length = len(self.result.split(' ')) |