Spaces:
Sleeping
Sleeping
ysongsongj
commited on
Commit
โข
aec9137
1
Parent(s):
aeba4aa
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = toknizer.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,
|
16 |
+
min_length = 56,
|
17 |
+
num_beams=4 #beam search
|
18 |
+
)
|
19 |
+
return tokenizer.decode(summary_text_ids[0], skip_special_tokens=True)
|
20 |
+
|
21 |
+
|
22 |
+
interface = gr.Interface(summ,
|
23 |
+
[gr.Textbox(label="original text")],
|
24 |
+
[gr.Textbox(label="summary")]) #interface calss instance
|
25 |
+
|
26 |
+
interface.launch()
|