File size: 864 Bytes
b7d8764
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import gradio as gr

tokenizer = AutoTokenizer.from_pretrained("facebook/bart-large-cnn")
model = AutoModelForSeq2SeqLM.from_pretrained("facebook/bart-large-cnn")

def text_summarize(article):

    inputs = tokenizer(article, return_tensors = 'pt')

    output = model.generate(inputs.input_ids,
                            max_new_tokens = 200,
                            do_sample = True,
                            top_p = 0.9,
                            top_k = 50)
    
    output_text = tokenizer.decode(output[0], skip_special_tokens=True)

    return output_text

iface = gr.Interface(
    fn = text_summarize,
    inputs = gr.Textbox(label = "Article", lines = 8, placeholder = "Paste your text here.."),
    outputs = gr.Textbox(label = "Summarized Text", lines = 5)
)

iface.launch()