my-first-app / app.py
cronin2021's picture
Create app.py
9e5a939 verified
Raw History Blame Contribute Delete
917 Bytes
import gradio as gr
from transformers import pipeline
# Load the summarization model (it will download automatically)
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
# Define a function that takes text and returns a summary
def summarize_text(text):
if len(text.strip()) == 0:
return "Please enter some text to summarize."
# Summarize!
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
return summary[0]['summary_text']
# Create the Gradio interface
demo = gr.Interface(
fn=summarize_text,
inputs=gr.Textbox(
placeholder="Enter text here to summarize...",
lines=8,
label="Input Text"
),
outputs=gr.Textbox(label="Summary"),
title="📝 AI Text Summarizer",
description="Paste any article, email, or text and get a concise summary instantly!",
theme="soft"
)
# Launch the app
demo.launch()