Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
# Load the summarization pipeline
|
| 7 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 8 |
+
|
| 9 |
+
# Define summarization function
|
| 10 |
+
def summarize_text(text):
|
| 11 |
+
if not text or len(text.strip()) == 0:
|
| 12 |
+
return "⚠️ Please enter some text to summarize."
|
| 13 |
+
|
| 14 |
+
summary = summarizer(
|
| 15 |
+
text,
|
| 16 |
+
max_length=130,
|
| 17 |
+
min_length=30,
|
| 18 |
+
do_sample=False
|
| 19 |
+
)
|
| 20 |
+
return summary[0]['summary_text']
|
| 21 |
+
|
| 22 |
+
# Gradio Interface
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
fn=summarize_text,
|
| 25 |
+
inputs=gr.Textbox(
|
| 26 |
+
lines=12,
|
| 27 |
+
placeholder="✍️ Paste your article, paragraph, or research text here..."
|
| 28 |
+
),
|
| 29 |
+
outputs=gr.Textbox(label="🧠 Generated Summary"),
|
| 30 |
+
title="Text Summarizer using Hugging Face 🤗",
|
| 31 |
+
description="Enter any paragraph or document, and get a concise summary using the BART model.",
|
| 32 |
+
examples=[
|
| 33 |
+
["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."]
|
| 34 |
+
]
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Launch app
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
demo.launch()
|