Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,2 +1,24 @@
|
|
1 |
# app.py ์ด๋ฆ์ ๊ฐ์ง ํ์ผ์ด ๊ผญ ํ์ํ๋ค
|
2 |
-
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# app.py ์ด๋ฆ์ ๊ฐ์ง ํ์ผ์ด ๊ผญ ํ์ํ๋ค
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import PreTrainedTokenizerFast, BartForConditionalGeneration
|
4 |
+
|
5 |
+
model_name = "ainize/kobart-news"
|
6 |
+
tokenizer = PreTrainedTokenizerFast.from_pretrained(model_name)
|
7 |
+
model = BartForConditionalGeneration.from_pretrained(model_name)
|
8 |
+
|
9 |
+
def summ(txt):
|
10 |
+
input_ids = tokenizer.encode(txt, return_tensors="pt")
|
11 |
+
summary_text_ids = model.generate(
|
12 |
+
input_ids=input_ids,
|
13 |
+
bos_token_id=model.config.bos_token_id, # BOS๋ Beginning Of Sentence
|
14 |
+
eos_token_id=model.config.eos_token_id, # EOS๋ End Of Sentence
|
15 |
+
length_penalty=2.0, # ์์ฝ์ ์ผ๋ง๋ ์งง๊ฒ ํ ์ง
|
16 |
+
max_length=142,
|
17 |
+
min_length=56,
|
18 |
+
num_beams=4) # beam search
|
19 |
+
return tokenizer.decode(summary_text_ids[0], skip_special_tokens=True)
|
20 |
+
|
21 |
+
interface = gr.Interface(summ,
|
22 |
+
[gr.Textbox(label="original text")],
|
23 |
+
[gr.Textbox(label="summary")])
|
24 |
+
interface.launch()
|