Spaces:
Sleeping
Sleeping
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() | |