import gradio as gr from textblob import TextBlob def 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 and subjectivity of the text. """ blob = TextBlob(text) sentiment = blob.sentiment return { "polarity": sentiment.polarity, "subjectivity": sentiment.subjectivity, "assessment": "Positive" if sentiment.polarity > 0 else "Negative" if sentiment.polarity < 0 else "Neutral" } demo = gr.Interface( fn=sentiment_analysis, inputs=gr.Textbox(label="Input Text", placeholder="Type your text here..."), outputs=gr.JSON(), title="Sentiment Analysis", description="Analyze the sentiment of your text using TextBlob.", theme="ocean", ) if __name__ == "__main__": demo.launch(mcp_server=True)