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