File size: 1,117 Bytes
76f7e74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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()