File size: 1,240 Bytes
847634c
 
214a767
 
58d943c
847634c
 
a424978
214a767
a424978
214a767
 
 
 
 
 
847634c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214a767
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import gradio as gr
from gradio.mix import Parallel, Series

def preprocess(inp):
    text = "vietnews: " + inp + " </s>"
    return text
 
def predict(input_ids, attention_mask):
    outputs = model.generate(
        input_ids=input_ids, attention_mask=attention_mask,
        max_length=256,
        early_stopping=True,
    )
    res = tokenizer.batch_decode(outputs, skip_special_tokens=True, clean_up_tokenization_spaces=True)[0]
    return res


extractor = gr.Interface(preprocess, 'text', 'text')
summarizer = gr.Interface.load("VietAI/vit5-large-vietnews-summarization")

sample_url = [['VietAI là tổ chức phi lợi nhuận với sứ mệnh ươm mầm tài năng về trí tuệ nhân tạo và xây dựng một cộng đồng các chuyên gia trong lĩnh vực trí tuệ nhân tạo đẳng cấp quốc tế tại Việt Nam.'],
]

desc =  '''
         Abstractive Summarization on Vietnamese News
        '''

iface = Series(extractor, summarizer, 
  inputs = gr.inputs.Textbox(
      lines = 5,
      label = 'Enter an article...'
  ),
  outputs = 'text',
  title = 'Vi(etnamese)T5 Abstractive Summarization',
  theme = 'grass',
  layout = 'horizontal',
  description = desc,
  examples=sample_url)

iface.launch()