|
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(" ")) |
|
|
|
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(); |