File size: 1,280 Bytes
6730add
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# app.py

from transformers import pipeline
import gradio as gr

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

# Define summarization function
def summarize_text(text):
    if not text or len(text.strip()) == 0:
        return "⚠️ Please enter some text to summarize."

    summary = summarizer(
        text,
        max_length=130,
        min_length=30,
        do_sample=False
    )
    return summary[0]['summary_text']

# Gradio Interface
demo = gr.Interface(
    fn=summarize_text,
    inputs=gr.Textbox(
        lines=12,
        placeholder="✍️ Paste your article, paragraph, or research text here..."
    ),
    outputs=gr.Textbox(label="🧠 Generated Summary"),
    title="Text Summarizer using Hugging Face 🤗",
    description="Enter any paragraph or document, and get a concise summary using the BART model.",
    examples=[
        ["The Hugging Face Transformers library provides general-purpose architectures for NLP tasks such as text classification, information extraction, question answering, summarization, translation, and text generation. It allows easy use of pre-trained models and fine-tuning for custom datasets."]
    ]
)

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