Spaces:
Paused
Paused
File size: 1,360 Bytes
9e5c5bb 7d93f13 9e5c5bb e6eb31e 9e5c5bb 7d93f13 9e5c5bb 17409ce 7d93f13 17409ce 7d93f13 17409ce 9e5c5bb |
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 |
import gradio as gr
import re
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
MODEL_NAME = "csebuetnlp/mT5_multilingual_XLSum"
WHITESPACE_HANDLER = lambda k: re.sub('\s+', ' ', re.sub('\n+', ' ', k.strip()))
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
def summarize(text):
text = WHITESPACE_HANDLER(text)
inputs = tokenizer(text,
max_length=1024,
truncation=True,
return_tensors="pt")
summary_ids = model.generate(inputs["input_ids"])
summary = tokenizer.batch_decode(summary_ids,
skip_special_tokens=True,
clean_up_tokenization_spaces=False)
return summary
demo = gr.Interface(fn = summarize,
inputs = [gr.inputs.Textbox(lines=10,
placeholder="Inpuy something...",
label='Text here !!')],
outputs = [gr.outputs.Textbox(
label="Summary")],
title = "π Summarizer π",
enable_queue=True)
demo.launch() |