Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the summarization pipeline
|
5 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
6 |
+
|
7 |
+
def summarize_text(text, min_length, max_length):
|
8 |
+
if not text.strip():
|
9 |
+
return "Please enter some text to summarize."
|
10 |
+
|
11 |
+
summary = summarizer(text, min_length=min_length, max_length=max_length, do_sample=False)
|
12 |
+
return summary[0]['summary_text']
|
13 |
+
|
14 |
+
# Define the Gradio interface
|
15 |
+
with gr.Blocks() as demo:
|
16 |
+
gr.Markdown("# Text Summarization using BART Model")
|
17 |
+
gr.Markdown("Enter a long piece of text below and adjust the sliders to set summary length, then click 'Summarize' to generate a concise summary.")
|
18 |
+
|
19 |
+
text_input = gr.Textbox(label="Input Text", placeholder="Enter your text here...", lines=10)
|
20 |
+
min_length_slider = gr.Slider(10, 50, value=10, label="Minimum Summary Length")
|
21 |
+
max_length_slider = gr.Slider(50, 150, value=100, label="Maximum Summary Length")
|
22 |
+
summarize_button = gr.Button("Summarize")
|
23 |
+
output_text = gr.Textbox(label="Summarized Text", lines=5, interactive=False)
|
24 |
+
|
25 |
+
summarize_button.click(summarize_text, inputs=[text_input, min_length_slider, max_length_slider], outputs=output_text)
|
26 |
+
|
27 |
+
# Launch the Gradio app
|
28 |
+
demo.launch()
|