File size: 1,480 Bytes
3315f36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import gradio as gr
from transformers import pipeline

# Initialize the summarization pipeline with facebook/bart-large-cnn
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")

def summarize_text(text, min_len, max_len):
    """
    Summarize the input text using the specified min_len and max_len.
    """
    # Convert slider values to integers
    min_len = int(min_len)
    max_len = int(max_len)
    
    # Run the summarizer with the given lengths
    summary = summarizer(text, min_length=min_len, max_length=max_len)
    return summary[0]['summary_text']

# Build the Gradio interface
demo = gr.Interface(
    fn=summarize_text,
    inputs=[
        gr.Textbox(
            lines=10, 
            placeholder="Enter a long piece of text here...",
            label="Input Text"
        ),
        gr.Slider(
            minimum=10, 
            maximum=50, 
            step=1, 
            value=25, 
            label="Minimum Summary Length (tokens)"
        ),
        gr.Slider(
            minimum=50, 
            maximum=150, 
            step=1, 
            value=100, 
            label="Maximum Summary Length (tokens)"
        )
    ],
    outputs=gr.Textbox(
        label="Summary"
    ),
    title="BART Text Summarizer with Adjustable Lengths",
    description="Enter a long piece of text, adjust the summary length settings using the sliders, and click 'Submit' to generate a summary."
)

if __name__ == "__main__":
    demo.launch()