pcasale commited on
Commit
4e4cd39
·
verified ·
1 Parent(s): 887c981

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -21
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 summarization pipeline with the BART-large-cnn model.
6
- # BART-large-cnn is fine-tuned for news summarization and is available on Hugging Face:contentReference[oaicite:8]{index=8}.
7
- summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
8
 
9
- # Define a function to perform summarization on the input text.
10
- def summarize_text(text):
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
- # Create Gradio interface components for input and output.
17
- input_text = gr.Textbox(lines=10, label="Input Text", placeholder="Enter or paste text to summarize...")
18
- output_summary = gr.Textbox(label="Summary")
 
 
 
 
19
 
20
- demo = gr.Interface(
21
- fn=summarize_text,
22
- inputs=input_text,
23
- outputs=output_summary,
24
- title="📝 Text Summarization with BART",
25
- description="**Description:** This app summarizes long text into a concise version. "
26
- "It uses a pre-trained BART-large-cnn model to generate an abstractive summary of the input text."
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