suming-K commited on
Commit
42c9a25
โ€ข
1 Parent(s): ed90e29

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -1
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()