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