Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,36 @@
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
|
4 |
-
#
|
5 |
-
summarizer = pipeline(
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
#
|
8 |
def summarize_article(text):
|
9 |
-
summary = summarizer(
|
|
|
|
|
|
|
|
|
|
|
10 |
return summary[0]['summary_text']
|
11 |
|
12 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
iface = gr.Interface(
|
14 |
fn=summarize_article,
|
15 |
-
inputs=gr.Textbox(lines=20, label="
|
16 |
-
outputs=gr.Textbox(label="Summary
|
17 |
-
title="Article Summarizer
|
18 |
-
description="
|
19 |
)
|
20 |
|
21 |
-
# Launch the app
|
22 |
iface.launch()
|
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
|
4 |
+
# Use the pipeline with optimized settings (no sampling, smaller batch)
|
5 |
+
summarizer = pipeline(
|
6 |
+
"summarization",
|
7 |
+
model="sshleifer/distilbart-cnn-6-6",
|
8 |
+
# force CPU (if not using GPU)
|
9 |
+
)
|
10 |
|
11 |
+
# Function with higher max length and lower min length for longer summaries
|
12 |
def summarize_article(text):
|
13 |
+
summary = summarizer(
|
14 |
+
text,
|
15 |
+
max_length=250, # ✨ allow longer output
|
16 |
+
min_length=100, # 🚨 ensure decent length
|
17 |
+
do_sample=False, # ⚡ makes it deterministic and faster
|
18 |
+
)
|
19 |
return summary[0]['summary_text']
|
20 |
|
21 |
+
# Sample input
|
22 |
+
default_article = """New York (CNN)When Liana Barrientos was 23 years old, she got married...""" # [TRIMMED for brevity]
|
23 |
+
|
24 |
+
# Generate summary once to display as default
|
25 |
+
default_summary = summarize_article(default_article)
|
26 |
+
|
27 |
+
# Gradio interface (read-only)
|
28 |
iface = gr.Interface(
|
29 |
fn=summarize_article,
|
30 |
+
inputs=gr.Textbox(lines=20, label="Article (Read Only)", value=default_article, interactive=False),
|
31 |
+
outputs=gr.Textbox(label="Summary (Read Only)", value=default_summary, interactive=False),
|
32 |
+
title="⚡ Fast Article Summarizer (CPU Optimized)",
|
33 |
+
description="Fast summarization with longer output using CPU only. Inputs and outputs are read-only."
|
34 |
)
|
35 |
|
|
|
36 |
iface.launch()
|