import logging


def generate_transformers_summary(text, summarizer):
    """
    Given a transformer pipeline (BART or T5), generate a summary whose length
    is between min_length and max_length
    :param text: text to summarise
    :param summarizer: transformers pipeline to use for summarising text
    :return:
    """
    logging.info("generate_transformers_summary >>>")
    # Transform the text back into string
    text = "".join(text)
    # Compute the minimum and maximum length of a summary
    summary = summarizer(text, max_length=300, early_stopping=True, num_beams=1)
    summary = summary[0]['summary_text']
    logging.info("generate_transformers_summary <<<")
    return summary