Spaces:
Running
Running
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=5, | |
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 | |
# add an example to gradio interface | |
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. Submit again for new titles!", | |
examples=[["Studies have shown that unobtanium oxide shows excellent mechanical and optical properties. However, the processing of unobtanium oxide is extremly difficult due to the high temperatures and pressures involved. Here we present a novel automagical synthesis of unobtanium oxide at room temperature and reduced pressure using a phlogiston catalyst. We believe this research will open up many potential applications of unobtanium oxide that were previously untested due to material scarcity."]]) | |
demo.launch() |