BG98 commited on
Commit
854ea29
·
1 Parent(s): c71557c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import PreTrainedTokenizerFast, BartForConditionalGeneration
3
+
4
+ model_name = 'ainize/kobart-news'
5
+
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,
14
+ eos_token_id=model.config.eos_token_id,
15
+ length_penalty=2.0,
16
+ max_length=142,
17
+ min_length=56,
18
+ num_beams=4,
19
+ )
20
+ return tokenizer.decode(summary_text_ids[0], skip_special_tokens=True)
21
+
22
+ interface = gr.Interface(summ, [gr.Textbox(label = 'original text')],
23
+ [gr.Textbokx(label = 'summary')])
24
+
25
+ interface.launch(share = True)