File size: 1,123 Bytes
8ec5a92
 
 
 
 
 
807ebeb
 
 
 
 
720b6ab
8ec5a92
 
 
 
 
 
 
720b6ab
 
8ec5a92
 
 
807ebeb
8ec5a92
 
 
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
29
import gradio as gr
from transformers import pipeline

summarizer = pipeline("summarization", model="facebook/bart-large-cnn")

def summarize_text(text, min_len, max_len):
    word_count = len(text.split())  
    if word_count < min_len:
        return f"Error: The text should have at least {min_len} words."
    elif word_count > max_len:
        return f"Error: The text should have no more than {max_len} words."
    
    summary = summarizer(text, min_length=min_len, max_length=max_len)
    return summary[0]['summary_text']

interface = gr.Interface(
    fn=summarize_text,
    inputs=[
        gr.Textbox(label="Enter Text", lines=10, placeholder="Paste your long text here..."),
        gr.Slider(label="Min Length", minimum=10, maximum=50, step=1, value=10),
        gr.Slider(label="Max Length", minimum=50, maximum=150, step=1, value=100)
    ],
    outputs=gr.Textbox(label="Summarized Text"),
    title="Text Summarizer with Sliders",
    description="This app uses the BART model to summarize your text. The input text must be between the min and max length you set using the sliders."
)

interface.launch()