File size: 957 Bytes
9b76863
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29


#!pip install -q torch transformers gradio

import os
import io
from transformers import pipeline
import gradio as gr

get_completion = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")

def summarize(input):
    output = get_completion(input) #takes an input
    return output[0]['summary_text'] #returns an output as summarized text




gr.close_all()
#create an interface in Gradio
demo = gr.Interface(fn=summarize, #mentioning the function
                    inputs=[gr.Textbox(label="Text to summarize", lines=6)], #input interface Textbox
                    outputs=[gr.Textbox(label="Result", lines=3)],
                    title="Text summarization with distilbart-cnn",
                    description="Summarize any text using the `sshleifer/distilbart-cnn-12-6` model under the hood!"
                   )
demo.launch() #to luanch an app. share=True it creates a global link which can be used to access it without a localhost