File size: 667 Bytes
dd76183
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import gradio as gr
from transformers import PegasusForConditionalGeneration
from transformers import PegasusTokenizer
from transformers import pipeline

model_name = "google/pegasus-xsum"
pegasus_tokenizer = PegasusTokenizer.from_pretrained(model_name)
def summarize(input_text):
  nwords=len(input_text.split(" "))
  # Define summarization pipeline 
  summarizer = pipeline("summarization", model=model_name, tokenizer=pegasus_tokenizer,min_length=int(nwords/10)+20, max_length=int(nwords/5+20), framework="pt")
  summary=summarizer(input_text)[0]['summary_text']
  return(summary)
gr.Interface(fn=summarize,inputs="textbox",outputs="textbox").launch(share="True");