Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,59 @@
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
#
|
| 5 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
|
| 7 |
-
#
|
| 8 |
def summarize_text(text):
|
| 9 |
if not text.strip():
|
| 10 |
-
return "β οΈ Please enter some text."
|
| 11 |
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
|
| 12 |
return summary
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
description="Summarizes text using Hugging Face's facebook/bart-large-cnn model."
|
| 21 |
-
)
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
if __name__ == "__main__":
|
| 24 |
-
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# Load summarization pipeline
|
| 5 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
|
| 7 |
+
# Summarization function
|
| 8 |
def summarize_text(text):
|
| 9 |
if not text.strip():
|
| 10 |
+
return "β οΈ Please enter some text to summarize."
|
| 11 |
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
|
| 12 |
return summary
|
| 13 |
|
| 14 |
+
# Interface components
|
| 15 |
+
title = "π AI Text Summarizer"
|
| 16 |
+
description = """
|
| 17 |
+
This AI-powered tool summarizes articles, essays, or documents using Facebook's BART Large CNN model.
|
| 18 |
+
Just paste your content, and let the AI do the rest!
|
| 19 |
+
"""
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
examples = [
|
| 22 |
+
["India is a country with a rich cultural heritage..."],
|
| 23 |
+
["Climate change is one of the biggest challenges faced globally..."],
|
| 24 |
+
["The history of computing began in the early 20th century..."]
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
with gr.Blocks(css=".gradio-container {background-color: #f8f9fa;} textarea {font-size: 16px;}") as demo:
|
| 28 |
+
gr.Markdown(f"# {title}")
|
| 29 |
+
gr.Markdown(description)
|
| 30 |
+
|
| 31 |
+
with gr.Row():
|
| 32 |
+
with gr.Column():
|
| 33 |
+
input_text = gr.Textbox(
|
| 34 |
+
label="π Input Text",
|
| 35 |
+
placeholder="Paste your article, paragraph, or essay here...",
|
| 36 |
+
lines=15,
|
| 37 |
+
show_copy_button=True
|
| 38 |
+
)
|
| 39 |
+
submit_btn = gr.Button("β¨ Summarize Now", variant="primary")
|
| 40 |
+
with gr.Column():
|
| 41 |
+
output = gr.Textbox(
|
| 42 |
+
label="π Summary Output",
|
| 43 |
+
lines=12,
|
| 44 |
+
interactive=False
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
submit_btn.click(fn=summarize_text, inputs=input_text, outputs=output)
|
| 48 |
+
|
| 49 |
+
gr.Examples(
|
| 50 |
+
examples=examples,
|
| 51 |
+
inputs=input_text,
|
| 52 |
+
outputs=output,
|
| 53 |
+
fn=summarize_text,
|
| 54 |
+
label="π Try with Examples"
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
# Launch app
|
| 58 |
if __name__ == "__main__":
|
| 59 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|