pcasale commited on
Commit
ca4f1a8
·
verified ·
1 Parent(s): 5fd7c3e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()