import gradio as gr from transformers import pipeline summarizer = pipeline("summarization", model="facebook/bart-large-cnn") def summarize_text(text, min_len, max_len): word_count = len(text.split()) if word_count < min_len: return f"Error: The text should have at least {min_len} words." elif word_count > max_len: return f"Error: The text should have no more than {max_len} words." summary = summarizer(text, min_length=min_len, max_length=max_len) return summary[0]['summary_text'] interface = gr.Interface( fn=summarize_text, inputs=[ gr.Textbox(label="Enter Text", lines=10, placeholder="Paste your long text here..."), gr.Slider(label="Min Length", minimum=10, maximum=50, step=1, value=10), gr.Slider(label="Max Length", minimum=50, maximum=150, step=1, value=100) ], outputs=gr.Textbox(label="Summarized Text"), title="Text Summarizer with Sliders", description="This app uses the BART model to summarize your text. The input text must be between the min and max length you set using the sliders." ) interface.launch()