File size: 887 Bytes
d43753a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

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

# Define the summarization function
def summarize_text(input_text):
    if not input_text.strip():
        return "Please provide some text to summarize."
    try:
        summary = summarizer(input_text, max_length=130, min_length=30, do_sample=False)
        return summary[0]["summary_text"]
    except Exception as e:
        return f"Error: {str(e)}"

# Create the Gradio interface
demo = gr.Interface(
    fn=summarize_text,
    inputs=gr.Textbox(lines=5, label="Input Text"),
    outputs=gr.Textbox(label="Summarized Text"),
    title="Text Summarizer",
    description="Summarize long articles or paragraphs using the `facebook/bart-large-cnn` model."
)

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