sentiment-analysis / README.md
Christopherygk's picture
Sentiment Analysis with Gradio MCP Server
d65f296

A newer version of the Gradio SDK is available: 6.8.0

Upgrade
metadata
title: Sentiment Analysis
emoji: 🐨
colorFrom: indigo
colorTo: blue
sdk: gradio
sdk_version: 5.49.1
app_file: app.py
pinned: false
short_description: Sentiment analysis MCP server using Gradio.

Sentiment Analysis MCP

A Python-based sentiment analysis application using TextBlob and Gradio that provides real-time sentiment analysis through a web interface.

Features

  • Real-time sentiment analysis using TextBlob's natural language processing
  • Interactive web interface powered by Gradio
  • Comprehensive metrics including polarity, subjectivity, and sentiment assessment
  • MCP server integration for enhanced functionality
  • Easy-to-use interface with instant results

What It Analyzes

  • Polarity: Sentiment score from -1.0 (very negative) to +1.0 (very positive)
  • Subjectivity: Objectivity score from 0.0 (objective) to 1.0 (subjective)
  • Assessment: Simple classification as "positive", "negative", or "neutral"

Installation

Prerequisites

  • Python 3.7 or higher
  • pip package manager

Setup

  1. Clone the repository:

    git clone https://github.com/GitBuntu/sentiment-analysis-mcp.git
    cd sentiment-analysis-mcp
    
  2. Create a virtual environment (recommended):

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. Install dependencies:

    pip install -r requirements.txt
    

Usage

Running the Application

  1. Start the application:

    python app.py
    
  2. Open your web browser and navigate to the local URL displayed in the terminal (typically http://127.0.0.1:7860)

  3. Enter text in the input box and get instant sentiment analysis results

Example Results

Input: "The food was delicious but the service was slow and disappointing."

Output:

{
  "polarity": 0.1,
  "subjectivity": 0.9,
  "assessment": "positive"
}

MCP Server Configuration

SSE Support

Some MCP clients don't support SSE-based MCP Servers. In those cases, use mcp-remote:

{
  "mcpServers": {
    "gradio": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "http://localhost:7860/gradio_api/mcp/sse"
      ]
    }
  }
}

Connection Issues

If you encounter connection problems:

  • Try restarting both the client and server
  • Check that the server is running and accessible
  • Verify that the MCP schema is available at the expected URL

Testing

The project includes a comprehensive test file (test_texts.txt) with examples for:

  • Positive sentiment - Happy, excited, satisfied expressions
  • Negative sentiment - Angry, disappointed, frustrated expressions
  • Neutral sentiment - Factual, objective statements
  • Mixed sentiment - Texts with both positive and negative elements
  • Highly subjective - Personal opinions and emotional expressions
  • Objective statements - Factual information with minimal emotion
  • Edge cases - Empty strings, punctuation, negations, ambiguous text

Sample Test Cases

Text Expected Polarity Expected Assessment
"I absolutely love this new restaurant!" High positive (~0.8) positive
"This product is terrible." High negative (~-0.8) negative
"The meeting is at 3 PM." Near zero (~0.0) neutral
"The food was delicious but service was slow." Slightly positive positive

Project Structure

sentiment-analysis-mcp/
β”œβ”€β”€ app.py              # Main application file
β”œβ”€β”€ requirements.txt    # Python dependencies
β”œβ”€β”€ test_texts.txt     # Test cases for sentiment analysis
β”œβ”€β”€ README.md          # Project documentation
└── venv/              # Virtual environment (created after setup)

Dependencies

  • textblob>=0.17.1 - Natural language processing library for sentiment analysis
  • gradio>=4.0.0 - Web interface framework for machine learning applications

How It Works

  1. Text Processing: Input text is processed using TextBlob's natural language processing capabilities
  2. Sentiment Calculation: TextBlob calculates polarity and subjectivity scores
  3. Classification: The application categorizes sentiment as positive, negative, or neutral based on polarity
  4. Web Interface: Gradio provides an interactive web interface for easy testing and usage

Use Cases

  • Social media monitoring - Analyze customer feedback and comments
  • Product reviews - Understand customer satisfaction from reviews
  • Survey analysis - Process open-ended survey responses
  • Content moderation - Identify potentially negative content
  • Market research - Analyze public opinion on topics or products

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is open source and available under the MIT License.

Limitations

  • Language Support: Currently optimized for English text
  • Context Understanding: May not fully understand complex sarcasm or context-dependent sentiment
  • Domain Specificity: General-purpose model may not be optimized for specific domains
  • Sentence Length: Very short texts may not provide reliable sentiment scores

Future Enhancements

  • Support for multiple languages
  • Custom model training capabilities
  • Batch processing for multiple texts
  • Export results to CSV/JSON
  • REST API endpoints
  • Docker containerization
  • Advanced visualization charts

Support

If you encounter any issues or have questions:

  1. Check the test_texts.txt file for examples
  2. Review the error messages in the terminal
  3. Open an issue on GitHub with detailed information about the problem

Acknowledgments

  • TextBlob - For providing excellent natural language processing capabilities
  • Gradio - For the easy-to-use web interface framework
  • Python Community - For the amazing ecosystem of tools and libraries