File size: 944 Bytes
7fbd2c2
 
 
 
4cf87c9
7fbd2c2
 
 
 
 
 
1dc4ba4
 
 
 
 
 
 
 
7fbd2c2
 
 
1dc4ba4
 
 
 
 
 
 
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
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()