File size: 1,351 Bytes
1ae33d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

def summarize_text(text, min_length, max_length):
    summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
    summary = summarizer(
        text,
        min_length=min_length,
        max_length=max_length,
        do_sample=False
    )
    return summary[0]['summary_text']

with gr.Blocks() as demo:
    gr.Markdown("## Adjustable Text Summarization")
    with gr.Row():
        input_text = gr.Textbox(
            label="Enter your text here",
            placeholder="Paste your text here...",
            lines=5
        )
    with gr.Row():
        min_length = gr.Slider(
            label="Minimum Length (Tokens)",
            minimum=10,
            maximum=50,
            value=10
        )
        max_length = gr.Slider(
            label="Maximum Length (Tokens)",
            minimum=50,
            maximum=150,
            value=100
        )
    with gr.Row():
        summarize_button = gr.Button("Generate Summary", variant="primary")
    with gr.Row():
        output_text = gr.Textbox(
            label="Generated Summary",
            lines=4
        )
        
    summarize_button.click(
        fn=summarize_text,
        inputs=[input_text, min_length, max_length],
        outputs=output_text
    )

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