roundTAE commited on
Commit
a8136a9
โ€ข
1 Parent(s): 245a58c

Create app.py

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