orangeinpark commited on
Commit
885803d
·
1 Parent(s): 224ffa9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transforemrs import PretrainedTokenizerFast, BartForCondtionalGeneration
3
+
4
+ model_name = 'ainize/kobart-news'
5
+ tokenizer = PreTrainedTokenizerFast.from_pretrained(model_name)
6
+ model = BartForConditionalGeneration.from_pretrained(model_name)
7
+
8
+ def summ(txt):
9
+ input_ids = tokenizer.encode(txt, return_tensors="pt")
10
+ summary_text_ids = model.generate(
11
+ input_ids=input_ids,
12
+ bos_token_id=model.config.bos_token_id, # BOS는 Beginning of Sentence
13
+ eos_token_id=model.config.eos_token_id, # EOS는 End of Sentence
14
+ length_penalty=2.0, # 요약을 얼마나 짧게 할지
15
+ max_length=142, # 최대 142 토큰으로 요약
16
+ min_length=56, # 최소 56 토큰보다는 더 나옴
17
+ num_beams=4 # beam search
18
+ )
19
+ return tokenizer.decode(summary_text_ids[0], skip_special_tokens=True)
20
+
21
+ interface = gr.Interface(summ,
22
+ [gr.Textbox(label="original text")], # gradio를 이용해서 gui
23
+ [gr.Textbox(label="summary")])
24
+
25
+ interface.launch() # share가 True일 경우, link가 하나 나옴