abstract2title / app.py
yue-here
first commit
726f186
raw
history blame
1.13 kB
import gradio as gr
from transformers import AutoTokenizer, T5ForConditionalGeneration
tokenizer = AutoTokenizer.from_pretrained("yuewu/T5_abstract2title")
model = T5ForConditionalGeneration.from_pretrained("yuewu/T5_abstract2title")
def title2abstract(text):
input_ids = tokenizer(
text,
padding='max_length',
max_length=512,
return_tensors="pt").input_ids
generated_ids = model.generate(
input_ids,
max_length=128,
# num_beams=3,
# no_repeat_ngram_size=2,
num_return_sequences=3,
do_sample=True,
top_k=50,
top_p=0.95,
early_stopping=True)
generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
output = f'1. {generated_text[0]}\n\n2. {generated_text[1]}\n\n3. {generated_text[2]}'
# output = generated_text
return output
demo = gr.Interface(fn=title2abstract, inputs="text", outputs="text",
title="Abstract to title generator",
description="Give a chemistry paper abstract and the model will suggest 3 titles.")
demo.launch()