File size: 1,680 Bytes
ea424b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import gradio as gr
from transformers import pipeline

# Load the summarization pipeline
pipe = pipeline("summarization", model="facebook/bart-large-cnn")

# Define the summarization function
def summarize_text(text, max_length=130, min_length=30, length_penalty=2.0):
    response = pipe(
        text,
        max_length=max_length,
        min_length=min_length,
        length_penalty=length_penalty,
        truncation=True
    )
    return response[0]['summary_text']

# Create the Gradio app interface
with gr.Blocks() as app:
    gr.Markdown("## Text Summarization App")
    gr.Markdown(
        "Enter a long text below, and the model will generate a concise summary. "
        "This app uses the `facebook/bart-large-cnn` model."
    )

    with gr.Row():
        input_text = gr.Textbox(
            label="Input Text",
            placeholder="Paste your text here...",
            lines=10
        )
        output_summary = gr.Textbox(label="Summary", lines=5)

    max_length = gr.Slider(
        label="Max Length", 
        minimum=50, 
        maximum=200, 
        step=10, 
        value=130
    )
    min_length = gr.Slider(
        label="Min Length", 
        minimum=10, 
        maximum=100, 
        step=10, 
        value=30
    )
    length_penalty = gr.Slider(
        label="Length Penalty", 
        minimum=0.5, 
        maximum=3.0, 
        step=0.1, 
        value=2.0
    )

    submit_button = gr.Button("Summarize")
    
    submit_button.click(
        fn=summarize_text,
        inputs=[input_text, max_length, min_length, length_penalty],
        outputs=output_summary
    )

# Launch the app
if __name__ == "__main__":
    app.launch()