SummarizerApp / app.py
Maram-almasary's picture
Create app.py
04fc75c verified
import gradio as gr
from transformers import pipeline
import torch
# Load the BART model for summarization
summarizer = pipeline("summarization",
model="facebook/bart-large-cnn")
# Function to summarize the input text
def summarize_text(input_text):
# Ensure the text is not too short for summarization
if len(input_text.split()) < 10:
return "Please provide a longer text for summarization."
# Summarize the text using BART
summarized_output = summarizer(input_text,
min_length=10,
max_length=100,
do_sample=False)
return summarized_output[0]['summary_text']
# Create the Gradio interface
interface = gr.Interface(
fn=summarize_text, # Function that summarizes the input
inputs=gr.Textbox(label="Input Text",
lines=10,
placeholder="Enter a long piece of text here..."), # Text input field
outputs=gr.Textbox(label="Summarized Text"), # Output field for the summarized text
title="Text Summarizer", # Title of the app
description="Enter a text, and this app will summarize it using the BART model. The summary will be between 10 and 100 tokens.", # Description
live=False, # Disable live updates while typing
)
# Launch the interface
interface.launch()