Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Interface๋ผ๋ ํด๋์ค๋ก ์
์ถ๋ ฅ ์์๋ฅผ ์น ์๋ฆฌ๋จผํธ๋ก ์๋ ์์ฑํด์ค
|
2 |
+
from transformers import PreTrainedTokenizerFast, BartForConditionalGeneration
|
3 |
+
# from transformers import๋ก ์์ํ๋ import ๋ฌธ์ ๋ณด๋ฉด
|
4 |
+
# ๋ง์ ๊ฒฝ์ฐ AutoTokenizer, AutoModel
|
5 |
+
# tokenizer = AutoTokenizer.from_pretrained("model ์ด๋ฆ ์ด์ฉ๊ณ ์ ์ฉ๊ณ ")
|
6 |
+
# BART๋ encoder-decoder ๋ชจ๋ธ์ ์์
|
7 |
+
|
8 |
+
model_name = "ainize/kobart-news"
|
9 |
+
tokenizer = PreTrainedTokenizerFast.from_pretrained(model_name)
|
10 |
+
model = BartForConditionalGeneration.from_pretrained(model_name)
|
11 |
+
def summ(txt):
|
12 |
+
input_ids = tokenizer.encode(txt, return_tensors="pt")
|
13 |
+
summary_text_ids = model.generate(
|
14 |
+
input_ids=input_ids,
|
15 |
+
bos_token_id=model.config.bos_token_id, # BOS๋ Beginning Of Sentence
|
16 |
+
eos_token_id=model.config.eos_token_id, # EOS๋ End Of Sentence
|
17 |
+
length_penalty=2.0, # ์์ฝ์ ์ผ๋ง๋ ์งง๊ฒ ํ ์ง
|
18 |
+
max_length=142,
|
19 |
+
min_length=56,
|
20 |
+
num_beams=4) # beam search
|
21 |
+
return tokenizer.decode(summary_text_ids[0], skip_special_tokens=True)
|
22 |
+
|
23 |
+
interface = gr.Interface(summ,
|
24 |
+
[gr.Textbox(label="original text")],
|
25 |
+
[gr.Textbox(label= "summary")])
|
26 |
+
interface.launch()
|