Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# Initialize the summarization pipeline with facebook/bart-large-cnn | |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
def summarize_text(text, min_len, max_len): | |
""" | |
Summarize the input text using the specified min_len and max_len. | |
""" | |
# Convert slider values to integers | |
min_len = int(min_len) | |
max_len = int(max_len) | |
# Run the summarizer with the given lengths | |
summary = summarizer(text, min_length=min_len, max_length=max_len) | |
return summary[0]['summary_text'] | |
# Build the Gradio interface | |
demo = gr.Interface( | |
fn=summarize_text, | |
inputs=[ | |
gr.Textbox( | |
lines=10, | |
placeholder="Enter a long piece of text here...", | |
label="Input Text" | |
), | |
gr.Slider( | |
minimum=10, | |
maximum=50, | |
step=1, | |
value=25, | |
label="Minimum Summary Length (tokens)" | |
), | |
gr.Slider( | |
minimum=50, | |
maximum=150, | |
step=1, | |
value=100, | |
label="Maximum Summary Length (tokens)" | |
) | |
], | |
outputs=gr.Textbox( | |
label="Summary" | |
), | |
title="BART Text Summarizer with Adjustable Lengths", | |
description="Enter a long piece of text, adjust the summary length settings using the sliders, and click 'Submit' to generate a summary." | |
) | |
if __name__ == "__main__": | |
demo.launch() | |