Spaces:
Sleeping
Sleeping
from textblob import TextBlob | |
def analyze_sentiment(text): | |
"""Analyze the sentiment of a given text. | |
Args: | |
text (str): The text to analyze | |
Returns: | |
dict: A dictionary containing polarity, subjectivity, and assessment | |
""" | |
blob = TextBlob(text) | |
return { | |
"polarity": round(blob.polarity, 2), | |
"subjectivity": round(blob.subjectivity, 2), | |
"assessment": "positive" if blob.polarity > 0 else "negative" if blob.polarity < 0 else "neutral" | |
} | |
def register_sentiment_tool(mcp): | |
"""Register the sentiment analysis tool with the MCP server.""" | |
def sentiment_analysis(text: str) -> dict: | |
""" | |
Analyze the sentiment of a given text. | |
Args: | |
text: The text to analyze | |
Returns: | |
A dictionary with polarity, subjectivity, and assessment | |
""" | |
return analyze_sentiment(text) | |