Spaces:
Sleeping
Sleeping
File size: 2,146 Bytes
92b59a8 37575e8 92b59a8 83600df 92b59a8 83600df 92b59a8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
from transformers import pipeline
import gradio as gr
import spaces
import os
from threading import Thread
from typing import Iterator
import torch
from transformers import (
AutoTokenizer,
AutoModelForSeq2SeqLM,
TextIteratorStreamer
)
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
tokenizer = AutoTokenizer.from_pretrained("dascim/greekbart-news24-abstract")
model = AutoModelForSeq2SeqLM.from_pretrained("dascim/greekbart-news24-abstract")
model.eval()
@spaces.GPU(duration=90)
def get_input(text) -> Iterator[str]:
streamer = TextIteratorStreamer(tokenizer, timeout=20.0, skip_special_tokens=True)
input_ids = tokenizer.encode(text, add_special_tokens=True, return_tensors='pt')
generate_kwargs = dict(
input_ids=input_ids,
tokenizer=tokenizer,
streamer=streamer,
max_new_tokens=120,
do_sample=False,
num_beams=1,
early_stopping=False
)
t = Thread(target=model.generate, kwargs=generate_kwargs)
t.start()
outputs = []
for text in streamer:
outputs.append(text)
yield "".join(outputs)
desc = f'''
This is a demo for Greek News summarization using greekbart-news24-abstract, a finetuned version of GreekBART
GreekBART is the first Greek sequence to sequence pretrained model. It is pretrained on 77GB of Greek raw text using the CNRS Jean Zay supercomputer. Our model is based on BART. Unlike already existing BERT-based Greek language models such as GreekBERT and Electra, GreekBART is particularly well-suited for generative tasks, since not only its encoder but also its decoder is pretrained. Our models are competitive to GreekBERT and XLM-R in discriminative tasks and it is the first BART BASE model that can generative tasks such as abstractive summarization for the Greek language.
Paper: [GreekBART: The First Pretrained Greek Sequence-to-Sequence Model](https://arxiv.org/abs/2304.00869)
Enter your text (maximum of 1024 tokens of Greek news article) to get a summary.
'''
iface = gr.Interface(fn=get_input,inputs="text",outputs="text",title = "Greek News Summarizer",description=desc)
iface.launch() |