mcp-sentiment / server.py
Sarah Azouvi
Add server.py and requirements.txt from master branch
653645e
raw
history blame contribute delete
991 Bytes
import gradio as gr
from textblob import TextBlob
def sentiment_analysis(text: str) -> dict:
"""
Perform sentiment analysis on a given text using TextBlob.
Args:
text (str): The text to analyze.
Returns:
dict: A dictionary containing polarity, assessment, and subjectivity scores.
"""
blob = TextBlob(text)
sentiment = blob.sentiment
return {
"polarity": round(sentiment.polarity, 2),
"subjectivity": round(sentiment.subjectivity, 2),
"assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
}
# Create Gradio interface
demo = gr.Interface(
fn=sentiment_analysis,
inputs=gr.Textbox(placeholder="Enter your text here..."),
outputs=gr.JSON(),
title="Sentiment Analysis",
description="Analyze the sentiment of a given text using TextBlob."
)
# Launch the interface and MCP server
if __name__ == "__main__":
demo.launch(mcp_server=True)