File size: 992 Bytes
fb238e8
 
 
 
 
 
 
 
 
 
 
f329bf4
 
fb238e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import gradio as gr
from transformers import PegasusForConditionalGeneration
from tokenizers_pegasus import PegasusTokenizer

def summary(text):
    model = PegasusForConditionalGeneration.from_pretrained("IDEA-CCNL/Randeng-Pegasus-238M-Summary-Chinese")
    tokenizer = PegasusTokenizer.from_pretrained("IDEA-CCNL/Randeng-Pegasus-238M-Summary-Chinese")
    inputs = tokenizer(text, max_length=1024, return_tensors="pt")
    # Generate Summary
    summary_ids = model.generate(inputs["input_ids"])
    return tokenizer.batch_decode(summary_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
examples = ["电力数据是反映经济运行的“晴雨表”和“风向标”。今年以来,随着消费信心逐步回暖、企业复工开足马力生产,多地用电量整体呈现出积极信号。一起透过各地的用电量,来看看中国经济的发展态势。"]
iface = gr.Interface(fn=summary, inputs="text", outputs="text",examples=examples)
iface.launch()