szurikata / app.py
fuelee's picture
update app.py
27ca22d
import gradio as gr
from transformers import MT5Tokenizer, MT5ForConditionalGeneration
def summary(text):
mt5_model = MT5ForConditionalGeneration.from_pretrained("google/mt5-large")
mt5_tokenizer = MT5Tokenizer.from_pretrained("google/mt5-large")
input_tokenized = mt5_tokenizer.encode(text, return_tensors='pt')
summary_ids = mt5_model.generate(input_tokenized,
length_penalty = 1,
min_length = 0,
max_length = 200,
num_beams = 1,
no_repeat_ngram_size = 2,
early_stopping = True)
output = mt5_tokenizer.batch_decode(summary_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)
return output[0]
iface = gr.Interface(fn=summary, inputs="text", outputs="text")
iface.launch()