File size: 904 Bytes
2789d98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f85fe5e
3000a73
491e3a3
2789d98
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
import gradio as gr
from transformers import AutoTokenizer, T5ForConditionalGeneration

tokenizer = AutoTokenizer.from_pretrained("yuewu/T5_title2abstract")
model = T5ForConditionalGeneration.from_pretrained("yuewu/T5_title2abstract")

def title2abstract(text):
    
    input_ids = tokenizer(
        text, 
        padding='max_length',
        max_length=128,
        return_tensors="pt").input_ids

    generated_ids = model.generate(
        input_ids, 
        max_length=512, 
        no_repeat_ngram_size=2,
        early_stopping=True)

    generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)

    return generated_text[0]

demo = gr.Interface(fn=title2abstract, inputs="text", outputs="text",
                    title="Title to abstract generator",
                    description="Give a chemistry paper title and the model will write an abstract.")
demo.launch()