fclong commited on
Commit
bfcac2a
·
1 Parent(s): 1c1ae0a

Update app.py

Browse files

update summary

Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -1,7 +1,14 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
1
  import gradio as gr
2
+ from transformers import PegasusForConditionalGeneration
3
+ from tokenizers_pegasus import PegasusTokenizer
4
 
5
+ def summary(name):
6
+ model = PegasusForConditionalGeneration.from_pretrained("IDEA-CCNL/Randeng-Pegasus-238M-Summary-Chinese")
7
+ tokenizer = PegasusTokenizer.from_pretrained("IDEA-CCNL/Randeng-Pegasus-238M-Summary-Chinese")
8
+ inputs = tokenizer(text, max_length=1024, return_tensors="pt")
9
+ # Generate Summary
10
+ summary_ids = model.generate(inputs["input_ids"])
11
+ return tokenizer.batch_decode(summary_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
12
 
13
+ iface = gr.Interface(fn=summary, inputs="text", outputs="text")
14
+ iface.launch()