import gradio as gr from textblob import TextBlob def sentiment_analysis(text: str) -> dict: """ Analyzes the sentiment of the given text using TextBlob Args: text (str): The text to analyze Returns: dict: A dictionary containing text polarity (from -1.0 = negative to 1.0 = positive), text subjectivity (from 0 = very objective to 1 = very subjective), and overall assessment """ blob = TextBlob(text) sentiment = blob.sentiment return { "polarity": round(sentiment.polarity, 2), "subjectivity": round(sentiment.subjectivity, 2), "assessment": ( "positive" if sentiment.polarity > 0.1 else "negative" if sentiment.polarity < -0.1 else "neutral" ), } demo = gr.Interface( fn=sentiment_analysis, inputs=gr.Textbox(placeholder="Enter text to analyze..."), outputs=gr.JSON(), title="MCP Text Sentiment Analysis Demo", description="Analyze the sentiment of a text using TextBlob, on an MCP server", ) if __name__ == "__main__": demo.launch(mcp_server=True)