Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import PreTrainedTokenizerFast, BartforConditionalGeneration
|
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(input_text, 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, #
|
16 |
+
min_length=56, #
|
17 |
+
num_beams=4) # beam search -> 가지 수 라고 생각하면 됨. 가지 4개를 펼치고 그 각가지에서 4개를 펼친 후 총 16개중 가장 적합한 4개를 고른 가지를 펼쳐 반복 과정
|
18 |
+
return tokenizer.decode(summary_text_ids[0], skip_special_tokens=True)
|
19 |
+
|
20 |
+
interface = gr.Interface(summ,
|
21 |
+
[gr.Textbox(label = "original text")],
|
22 |
+
[gr.Textbox(label = "summary")])
|
23 |
+
|
24 |
+
insterface.launch(share = True)
|