File size: 3,161 Bytes
92e3d17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e865517
d884bf1
011eccb
92e3d17
 
d884bf1
92e3d17
 
 
ebf5210
92e3d17
ebf5210
92e3d17
 
ebf5210
92e3d17
 
ebf5210
92e3d17
 
 
 
 
ebf5210
92e3d17
ebf5210
d884bf1
 
 
 
92e3d17
d884bf1
 
 
ebf5210
d884bf1
92e3d17
 
d884bf1
92e3d17
d884bf1
 
 
 
 
 
 
 
92e3d17
d884bf1
 
 
 
 
ebf5210
76140c3
d884bf1
92e3d17
d884bf1
92e3d17
d884bf1
92e3d17
 
 
 
d884bf1
92e3d17
d884bf1
92e3d17
 
 
d884bf1
92e3d17
 
 
d884bf1
92e3d17
d884bf1
92e3d17
 
 
 
 
d884bf1
 
 
92e3d17
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
---
title: MCP Sentiment Analysis Server
emoji: 🎭
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: "5.0.0"
app_file: app.py
pinned: false
license: mit
---

# MCP Sentiment Analysis Server

This is a Model Context Protocol (MCP) server that provides sentiment analysis capabilities using an improved TextBlob-based approach with negation detection.

## Features

- **Comprehensive Sentiment Analysis**: Detailed sentiment analysis with polarity and subjectivity scores
- **Numerical Sentiment Scoring**: Simple numerical scoring from -1 (very negative) to 1 (very positive)
- **Emotion Classification**: Basic emotion classification (Joy, Sadness, Anger, etc.)
- **Batch Text Processing**: Analyze multiple texts at once with summary statistics
- **Improved Negation Handling**: Better detection of negated sentiments compared to vanilla TextBlob
- **Full MCP Protocol Support**: Compatible with MCP clients and AI applications

## Usage

### Web Interface
Use the interface above to test the sentiment analysis tools directly.

### MCP Endpoint
Connect your MCP clients to: `https://YOUR_USERNAME-SPACE_NAME.hf.space/gradio_api/mcp/sse`

### Available Tools
- `analyze_sentiment`: Comprehensive sentiment analysis with debug information
- `get_sentiment_score`: Numerical sentiment scoring (-1 to 1)
- `classify_emotion`: Basic emotion classification with confidence scores
- `batch_analyze`: Analyze multiple texts at once with summary statistics

## Example with smolagents

```python
from smolagents.mcp_client import MCPClient

with MCPClient(
    {"url": "https://YOUR_USERNAME-SPACE_NAME.hf.space/gradio_api/mcp/sse"}
) as tools:
    for tool in tools:
        print(f"{tool.name}: {tool.description}")
```

## Example with Cursor IDE

Add to your MCP configuration:

```json
{
  "mcpServers": {
    "sentiment-analysis": {
      "command": "npx",
      "args": [
        "-y", 
        "mcp-remote", 
        "https://YOUR_USERNAME-SPACE_NAME.hf.space/gradio_api/mcp/sse", 
        "--transport", 
        "sse-only"
      ]
    }
  }
}
```

## Improvements Over Standard TextBlob

This implementation includes several improvements over standard TextBlob sentiment analysis:

1. **Negation Detection**: Automatically detects common negation patterns (don't, can't, not, etc.)
2. **Sentiment Correction**: Corrects TextBlob's tendency to misclassify negated positive statements
3. **Conservative Thresholds**: Uses more conservative thresholds for sentiment classification
4. **Debug Information**: Provides transparency into the analysis process

## Example Results

**Input**: "I don't like this kind of things happen"
- **Standard TextBlob**: Positive (0.6) ❌
- **This Implementation**: Negative (-0.48) ✅

**Input**: "This is not good"
- **Standard TextBlob**: Positive (0.7) ❌  
- **This Implementation**: Negative (-0.35) ✅

## Technical Details

- Built with Gradio and TextBlob
- Uses regex-based negation detection
- Implements conservative sentiment thresholds
- Provides JSON-formatted responses
- Full MCP protocol compatibility via Server-Sent Events (SSE)

## License

MIT License - see the course repository for details.