Spaces:
Sleeping
Sleeping
File size: 1,364 Bytes
4a46682 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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()
|