text-summarizer / app.py
RawadAlghamdi's picture
Create app.py
8458323 verified
raw
history blame contribute delete
880 Bytes
import gradio as gr
from transformers import pipeline
# Load the summarization pipeline with the facebook/bart-large-cnn model
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
# Define the summarization function
def summarize(text):
# Generate summary with min_length=10 and max_length=100 tokens
summary = summarizer(text, min_length=10, max_length=100)
# Extract and return the summarized text
return summary[0]['summary_text']
# Define input and output components with clear labels
inputs = gr.Textbox(label="Input Text", lines=10)
outputs = gr.Textbox(label="Summary")
# Create the Gradio interface
iface = gr.Interface(
fn=summarize,
inputs=inputs,
outputs=outputs,
title="Text Summarizer",
description="Enter a long piece of text and get a summary using the BART model."
)
# Launch the interface
iface.launch()