import gradio as gr from textblob import TextBlob def sentiment_analysis(text): """Perform sentiment analysis on the input text. Args: text (str): The input text to analyze. Returns: dict: A dictionary containing polarity, subjectivity, and assessment """ 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 the Gradio interface demo = gr.Interface( fn=sentiment_analysis, inputs=gr.Textbox(label="Enter text for sentiment analysis", placeholder="Type here..."), outputs=gr.JSON(), title="Sentiment Analysis App", description="This app performs sentiment analysis on the input text using TextBlob." ) if __name__ == "__main__": demo.launch(mcp_server=True) # Launch the Gradio app # The app will be accessible at http://localhost:7860 by default