File size: 836 Bytes
6838503
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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):
    # Generate summary with a minimum of 10 tokens and a maximum of 100 tokens
    summary = summarizer(text, min_length=10, max_length=100)
    return summary[0]['summary_text']

# Create 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"
    ),
    outputs=gr.Textbox(label="Summary"),
    title="BART Text Summarizer",
    description="Enter a long piece of text and get a concise summary using facebook/bart-large-cnn."
)

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