sentimentmcp / app.py
Andrew LimYH
commit app and requirement
3e49543
import gradio as gr
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
def vader_sentiment_analysis(text: str) -> dict:
"""Perform sentiment analysis on the input text.
Args:
text (str): The input text to analyze.
Returns:
dict: A dictionary containing the polarity, subjectivity and assessment of the text.
"""
analyzer = SentimentIntensityAnalyzer()
sentiment = analyzer.polarity_scores(text)
return {"Polarity": round(sentiment["compound"], 2),
"Subjectivity": round(sentiment["neu"], 2),
"Assessment": "Positive" if sentiment["compound"] > 0 else "Negative" if sentiment["compound"] < 0 else "Neutral"}
examples = [
["AI technology is causing students to get lazy"],
["AI technology is transforming the world positively"],
]
demo = gr.Interface(
fn=vader_sentiment_analysis,
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
outputs=gr.JSON(),
examples=examples,
title="Sentiment Analysis",
description="Enter text to analyze its sentiment. \nThe output will show the polarity, subjectivity, and overall assessment of the text.",
theme="default"
)
if __name__ == "__main__":
demo.launch(mcp_server=True)