Summarization / app.py
iamomtiwari's picture
Create app.py
d43753a verified
raw
history blame contribute delete
887 Bytes
import gradio as gr
from transformers import pipeline
# Load the summarization pipeline
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
# Define the summarization function
def summarize_text(input_text):
if not input_text.strip():
return "Please provide some text to summarize."
try:
summary = summarizer(input_text, max_length=130, min_length=30, do_sample=False)
return summary[0]["summary_text"]
except Exception as e:
return f"Error: {str(e)}"
# Create the Gradio interface
demo = gr.Interface(
fn=summarize_text,
inputs=gr.Textbox(lines=5, label="Input Text"),
outputs=gr.Textbox(label="Summarized Text"),
title="Text Summarizer",
description="Summarize long articles or paragraphs using the `facebook/bart-large-cnn` model."
)
# Launch the app
if __name__ == "__main__":
demo.launch()