File size: 871 Bytes
52546d1
 
5a17398
52546d1
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from transformers import pipeline
import gradio as gr
summarization=pipeline(task="summarization", model="sshleifer/distilbart-cnn-12-6")
def summarize(text:str, max_length:int):
    if max_length<10:
        raise gr.Error()
    if text=="":
        raise gr.Error("Text field is empty. Please enter some text")
    summary=summarization(text,min_length=10,max_length=max_length)
    return summary[0]['summary_text']

demo = gr.Interface(fn=summarize, inputs=[gr.TextArea(label="Text",placeholder="Enter any long text to be summarized"),
                                      gr.Number(label="Words",info="Enter the max word of the summary. Min 10",minimum=10)], 
                    outputs=gr.TextArea(label="Summary"), title="Summarization App using AI", description="This app uses AI to summarize long text into your given number of words.")
demo.launch(share=True)