import gradio as gr from transformers import pipeline def summarize_aritcle(Article, model_selector, min_length, max_length): summarizer = pipeline("summarization", model=model_selector) return f"{model_selector}: \n {summarizer(Article, max_length=max_length, min_length=min_length, do_sample=False)[0]['summary_text']}" # gradio_app = gr.Interface(fn=greet, inputs="text", outputs="text") model_list = ["facebook/bart-large-cnn", "facebook/bart-large-xsum"] with gr.Blocks() as demo: model_selector = gr.Dropdown(model_list, label="model selection", value=0, show_label=True) article = gr.TextArea(label="Article Text") min_length=gr.Number(label="min summary length", value=30) max_length=gr.Number(label="max summary length", value=100) summary_text = gr.TextArea(label="Summary Text") run_btn = gr.Button("Do Summarize") run_btn.click(fn=summarize_aritcle, inputs=[article, model_selector, min_length, max_length], outputs=summary_text) if __name__ == "__main__": demo.launch()