test_2 / app.py
astro21's picture
Update app.py
1dc4ba4
raw
history blame
944 Bytes
import gradio as gr
from transformers import pipeline
# Load the text summarization pipeline
summarizer = pipeline("summarization", model="astro21/bart-cls")
def summarize_text(input_text):
# Use the summarization pipeline to generate a summary
summarized_text = summarizer(input_text, max_length=128, min_length=64, do_sample=False , wait_for_model = True)
return summarized_text[0]['summary_text']
def summarize_with_button(text):
if text == "":
return "Please enter some text to summarize."
else:
return summarize_text(text)
iface = gr.Interface(
fn=summarize_with_button,
inputs=gr.inputs.Textbox(label="Enter the text to summarize"),
outputs=gr.outputs.Textbox(label="Summarized Text"),
title="Text Summarizer",
live=True # Enable live updates without a "Summarize" button
)
# Add the "Summarize" button
iface.inputs.append(gr.inputs.Button(label="Summarize"))
iface.launch()