Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from transformers import PreTrainedTokenizerFast, BartForConditionalGeneration
|
4 |
+
# from transformers import๋ก ์์ํ๋ import ๋ฌธ์ ๋ณด๋ฉด
|
5 |
+
# ๋ง์ ๊ฒฝ์ฐ AutoTokenizer, AutoModel
|
6 |
+
# tokenizer = AutoTokenizer.from_pretrained("model ์ด๋ฆ ์ด์ฉ๊ณ ์ ์ฉ๊ณ ")
|
7 |
+
# PreTrainedTokenizerFast : https://huggingface.co/docs/transformers/main_classes/tokenizer
|
8 |
+
# BART๋ encoder-decoder ๋ชจ๋ธ์ ์์
|
9 |
+
|
10 |
+
model_name = "ainize/kobart-news"
|
11 |
+
tokenizer = PreTrainedTokenizerFast.from_pretrained(model_name)
|
12 |
+
model = BartForConditionalGeneration.from_pretrained(model_name)
|
13 |
+
|
14 |
+
# ์๋ฌธ์ ๋ฐ์์ ์์ฝ๋ฌธ์ ๋ฐํ
|
15 |
+
def summ(txt):
|
16 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
17 |
+
summary_text_ids = model.generate(
|
18 |
+
input_ids=input_ids,
|
19 |
+
bos_token_id=model.config.bos_token_id,
|
20 |
+
eos_token_id=model.config.eos_token_id,
|
21 |
+
length_penalty=2.0,
|
22 |
+
max_length=142,
|
23 |
+
min_length=56,
|
24 |
+
num_beams=4)
|
25 |
+
return tokenizer.decode(summary_text_ids[0], skip_special_tokens=True)
|
26 |
+
|
27 |
+
interface = gr.Interface(summ,
|
28 |
+
[gr.Textbox(label="original text")],
|
29 |
+
[gr.Textbox(label="summary")])
|
30 |
+
|
31 |
+
interface.launch(share=True)
|