Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,42 @@
|
|
| 1 |
-
# Import necessary libraries
|
| 2 |
from transformers import pipeline
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
# Load the
|
| 6 |
-
|
| 7 |
-
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
# Use the summarizer pipeline to generate a summary.
|
| 12 |
-
# We set min_length and max_length to control the size of the summary:contentReference[oaicite:9]{index=9}.
|
| 13 |
-
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
|
| 14 |
return summary
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
demo.launch()
|
|
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# Load the BART summarisation pipeline
|
| 5 |
+
summariser = pipeline("summarization", model="facebook/bart-large-cnn")
|
|
|
|
| 6 |
|
| 7 |
+
def summarise(text):
|
| 8 |
+
summary = summariser(text, max_length=150, min_length=40, do_sample=False)[0]["summary_text"]
|
|
|
|
|
|
|
|
|
|
| 9 |
return summary
|
| 10 |
|
| 11 |
+
# Two example passages for quick testing
|
| 12 |
+
example_texts = [
|
| 13 |
+
["Artificial intelligence has progressed rapidly over the past decade. "
|
| 14 |
+
"New methods in deep learning have made it possible to process vast amounts of data, "
|
| 15 |
+
"leading to significant advances in language modelling, computer vision, and reinforcement learning. "
|
| 16 |
+
"As organisations adopt these technologies, questions emerge regarding transparency, fairness, "
|
| 17 |
+
"and the wider societal impact of automated decision-making."],
|
| 18 |
|
| 19 |
+
["The Industrial Revolution transformed Europe’s economic landscape. "
|
| 20 |
+
"Mechanised production replaced traditional craft methods, enabling factories to produce goods at a scale "
|
| 21 |
+
"previously unimaginable. These developments shifted labour patterns, encouraged urban migration, "
|
| 22 |
+
"and laid the foundations for modern industrial capitalism."]
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
with gr.Blocks(title="BART Text Summariser") as demo:
|
| 26 |
+
|
| 27 |
+
gr.Markdown(
|
| 28 |
+
"""### BART Text Summariser
|
| 29 |
+
Paste a passage of text and receive a concise summary.
|
| 30 |
+
Two sample texts are provided below for immediate experimentation."""
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
input_box = gr.Textbox(
|
| 34 |
+
lines=12,
|
| 35 |
+
label="Input Text",
|
| 36 |
+
placeholder="Paste the text you wish to summarise…"
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
output_box = gr.Textbox(
|
| 40 |
+
lines=10, # Increased height for the summary output
|
| 41 |
+
label="Summary"
|
| 42 |
|
|
|