File size: 784 Bytes
d41441c f8e9dd4 d41441c a588ac9 d41441c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # Code 4 - Let's create an UI using Gradio
from transformers import pipeline
import gradio as gr
summarizer = pipeline(task="summarization", model="facebook/bart-large-cnn")
# Code 5 - define a function to summarize text
def nlp(input_text):
summary = summarizer(
input_text,
repetition_penalty=5.0, # Increase this to discourage repetition
length_penalty=0.3, # Decrease this to generate longer summaries
min_length=20, max_length=100
)
return summary[0]["summary_text"]
# Code 6 - UI object
ui = gr.Interface(nlp,
inputs=gr.Textbox(label="Input Text"),
outputs=gr.Textbox(label="Summary"),
title="Text Summarizer",
description="Summarize your text using the BART model.")
# Code 7 - launch UI
ui.launch(share=True) |