File size: 1,203 Bytes
342ef15
18e14ab
342ef15
 
 
18e14ab
342ef15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd714c3
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
import gradio as gr
from transformers import PreTrainedTokenizerFast, BartForConditionalGeneration

model_name = "ainize/kobart-news"
tokenizer = PreTrainedTokenizerFast.from_pretrained(model_name)
model = BartForConditionalGeneration.from_pretrained(model_name)

def summ(txt):
  input_ids = tokenizer.encode(input_text, return_tensors="pt")
  summary_text_ids = model.generate(
    input_ids=input_ids,
    bos_token_id=model.config.bos_token_id, # BOS는 Beginning of Sentence
    eos_token_id=model.config.eos_token_id, # EOS는 End Of Sentence
    length_penalty=2.0,                     # 요약을 얼마나 짧게 할지
    max_length=142,                         #
    min_length=56,                          #
    num_beams=4)                            # beam search -> 가지 수 라고 생각하면 됨. 가지 4개를 펼치고 그 각가지에서 4개를 펼친 후 총 16개중 가장 적합한 4개를 고른 가지를 펼쳐 반복 과정
  return tokenizer.decode(summary_text_ids[0], skip_special_tokens=True)

interface = gr.Interface(summ,
                        [gr.Textbox(label = "original text")],
                        [gr.Textbox(label = "summary")])

interface.launch()