task2 / app.py
renad0's picture
Create app.py
76f7e74 verified
raw
history blame
1.12 kB
import gradio as gr
from transformers import pipeline
# Load the BART model for summarization
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
# Function to summarize text based on the min and max length
def summarize_text(text, min_length, max_length):
# Summarize the input text with the specified min and max length
summary = summarizer(text, min_length=min_length, max_length=max_length)
return summary[0]['summary_text']
# Create Gradio Interface
iface = gr.Interface(
fn=summarize_text, # Function to call for summarization
inputs=[
gr.Textbox(label="Enter Text", placeholder="Type or paste a long text here...", lines=10),
gr.Slider(minimum=10, maximum=50, step=1, label="Minimum Length", value=10),
gr.Slider(minimum=50, maximum=150, step=1, label="Maximum Length", value=100),
],
outputs=gr.Textbox(label="Summarized Text"),
live=False, # Disable live preview while typing
description="Text Summarization using BART model. Set minimum and maximum token lengths for the summary."
)
# Launch the interface
iface.launch()