from transformers import pipeline import gradio as gr # Load summarization models models = { "BART Large CNN": pipeline("summarization", model="facebook/bart-large-cnn"), "T5 Small": pipeline("summarization", model="t5-small") } # Sentiment analysis pipeline sentiment_analyzer = pipeline("sentiment-analysis") def summarize_compare(text): summaries = {} sentiments = {} for model_name, summarizer in models.items(): summary = summarizer(text, max_length=100, min_length=30, do_sample=False)[0]['summary_text'] sentiment = sentiment_analyzer(summary)[0] summaries[model_name] = summary sentiments[model_name] = f"{sentiment['label']} ({round(sentiment['score'], 2)})" return summaries["BART Large CNN"], sentiments["BART Large CNN"], summaries["T5 Small"], sentiments["T5 Small"] demo = gr.Interface( fn=summarize_compare, inputs=gr.Textbox(lines=10, placeholder="Paste your text here..."), outputs=[ gr.Textbox(label="BART Large CNN Summary"), gr.Textbox(label="BART Large CNN Sentiment"), gr.Textbox(label="T5 Small Summary"), gr.Textbox(label="T5 Small Sentiment") ], title="Multi-Model Text Summarizer + Sentiment Analyzer", description="Compare summaries from multiple models and see the sentiment of each summary." ) demo.launch()