Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
+
|
| 7 |
+
def summarize_text(text, min_length, max_length):
|
| 8 |
+
if len(text.strip()) == 0:
|
| 9 |
+
return "Please enter some text to summarize."
|
| 10 |
+
|
| 11 |
+
summary = summarizer(text, max_length=max_length, min_length=min_length, do_sample=False)
|
| 12 |
+
return summary[0]['summary_text']
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
iface = gr.Interface(
|
| 16 |
+
fn=summarize_text,
|
| 17 |
+
inputs=[
|
| 18 |
+
gr.Textbox(lines=5, placeholder="Enter a long text here...", label="Input Text"),
|
| 19 |
+
gr.Slider(10, 50, step=5, label="Minimum Summary Length"),
|
| 20 |
+
gr.Slider(50, 150, step=10, label="Maximum Summary Length"),
|
| 21 |
+
],
|
| 22 |
+
outputs=gr.Textbox(label="Summarized Text"),
|
| 23 |
+
title="Adjustable Text Summarization App",
|
| 24 |
+
description="Enter a long text and adjust the summary length using the sliders.",
|
| 25 |
+
allow_flagging="never"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
iface.launch()
|