|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
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. |
|
""" |
|
|
|
min_len = int(min_len) |
|
max_len = int(max_len) |
|
|
|
|
|
summary = summarizer(text, min_length=min_len, max_length=max_len) |
|
return summary[0]['summary_text'] |
|
|
|
|
|
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() |
|
|