Jaehan commited on
Commit
097e26e
1 Parent(s): 84ee2b1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PegasusForConditionalGeneration, PegasusTokenizer
2
+ import gradio as grad
3
+
4
+ model_name="google/pegasus-xsum"
5
+ pega_tokenizer = PegasusTokenizer.from_pretrained(model_name)
6
+ model = PegasusForConditionalGeneration.from_prtrained(model_name)
7
+
8
+ def summarize(text):
9
+ tokens = pega_tokenizer(text, truncation=True, padding="longest", return_tensors="pt")
10
+ trans_text = model.generate(**tokens, num_return_sequences=5, max_length=200, temperature=1.5, num_beams=10)
11
+ response = pega_tokenizer.batch_decode(trans_text, skip_special_tokens=True)
12
+ return response
13
+
14
+ in_text = grad.Textbox(lines=10, label="English", placeholder="English text here")
15
+ out_text = grad.Textbox(lines=10, label="Summary")
16
+ grad.Interface(summarize, inputs=in_text, outputs=out_text).launch()