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)+10, max_length=int(nwords/5+10), framework="pt") summary=summarizer(input_text)[0]['summary_text'] return(summary) gr.Interface(fn=summarize,inputs=gr.inputs.Textbox(placeholder="Paste the text to be summarized here..."),outputs="textbox").launch();