File size: 6,229 Bytes
ebf2428
 
 
 
 
 
 
 
 
 
 
 
d65f296
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
---
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**:
   ```bash
   git clone https://github.com/GitBuntu/sentiment-analysis-mcp.git
   cd sentiment-analysis-mcp
   ```

2. **Create a virtual environment** (recommended):
   ```bash
   python -m venv venv
   source venv/bin/activate  # On Windows: venv\Scripts\activate
   ```

3. **Install dependencies**:
   ```bash
   pip install -r requirements.txt
   ```

## Usage

### Running the Application

1. **Start the application**:
   ```bash
   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**:
```json
{
  "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:

```json
{
  "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](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](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