import gradio as gr from textblob import TextBlob def analyze_sentiment(text) -> dict: """ Analyze the sentiment of the input text. Args: text (str): The input text to analyze. Returns: dict: A dictionary containing the polarity, subjectivity, and assessment of the text. """ blob = TextBlob(text) sentiment = blob.sentiment return { f"polarity: {round(sentiment.polarity, 2)}", f"subjectivity: {round(sentiment.subjectivity, 2)}", f"assessment: {'positive' if sentiment.polarity > 0 else 'negative' if sentiment.polarity < 0 else 'neutral'}" } demo = gr.Interface( fn=analyze_sentiment, inputs=gr.Textbox(label="Input Text", placeholder="Enter text to analyze sentiment..."), outputs=gr.JSON(), title="Sentiment Analysis with TextBlob", description="This app analyzes the sentiment of the input text using TextBlob and returns the polarity, subjectivity, and assessment.", ) if __name__ == "__main__": demo.launch(mcp_server=True)