MCP服务器:使用Gemma-3模型分析图像中的人物表情
Project description
Emotion Analyzer MCP Server
一个使用 OpenRouter 的 Gemma-3 模型分析图像中人物表情的 MCP (Model Context Protocol) 服务器。
功能特性
- 🎭 表情识别: 识别快乐、悲伤、愤怒、惊讶、恐惧、厌恶、中性等表情
- 📊 强度评估: 提供 1-10 分的表情强度评分
- 🎯 置信度评估: 提供 0-1 的分析置信度
- 👤 详细描述: 提供面部特征和情绪状态的详细描述
- 🌐 多种输入: 支持文件路径和 base64 编码的图像
- 🔧 标准 MCP: 完全兼容 MCP 协议,可与各种 MCP 客户端集成
安装
方法 1: 使用 pip 安装(推荐)
pip install emotion-analyzer-mcp
方法 2: 从源码安装
git clone https://github.com/yourusername/emotion-analyzer-mcp.git
cd emotion-analyzer-mcp
pip install -e .
配置
1. 获取 OpenRouter API 密钥
- 访问 OpenRouter
- 注册账户并获取 API 密钥
- 设置环境变量:
export OPENROUTER_API_KEY="your_api_key_here"
2. 在 Cherry Studio 中配置
在 Cherry Studio 的 MCP 设置中添加以下配置:
{
"mcpServers": {
"emotion-analyzer": {
"command": "emotion-analyzer-mcp",
"env": {
"OPENROUTER_API_KEY": "your_api_key_here"
}
}
}
}
3. 在其他 MCP 客户端中配置
对于支持 MCP 的其他客户端,使用类似的配置:
{
"name": "emotion-analyzer",
"command": "emotion-analyzer-mcp",
"env": {
"OPENROUTER_API_KEY": "your_api_key_here"
}
}
使用方法
可用工具
1. analyze_emotion
通过文件路径分析图像中的表情。
参数:
image_path(string, 必需): 图像文件的路径
示例:
{
"name": "analyze_emotion",
"arguments": {
"image_path": "/path/to/image.jpg"
}
}
2. analyze_emotion_base64
通过 base64 编码的图像数据分析表情。
参数:
image_data(string, 必需): base64 编码的图像数据image_format(string, 可选): 图像格式,默认为 "jpeg"
示例:
{
"name": "analyze_emotion_base64",
"arguments": {
"image_data": "base64_encoded_image_data",
"image_format": "jpeg"
}
}
在 Cherry Studio 中使用
- 确保 MCP 服务器已正确配置
- 在对话中使用工具调用:
请分析这张图片中人物的表情:/path/to/image.jpg
Cherry Studio 会自动调用 analyze_emotion 工具并显示分析结果。
输出格式
分析结果包含以下信息:
表情分析结果:
📸 图像: /path/to/image.jpg
😊 主要表情: 快乐
📊 表情强度: 8/10
🎯 置信度: 0.90
👤 面部特征: 眼角上扬,嘴角微笑,面部肌肉放松
💭 情绪状态: 积极愉悦的情绪状态
📝 其他观察: 表情自然真实
原始JSON结果:
{
"success": true,
"image_path": "/path/to/image.jpg",
"analysis": {
"emotion": "快乐",
"intensity": 8,
"confidence": 0.9,
"facial_features": "眼角上扬,嘴角微笑,面部肌肉放松",
"emotional_state": "积极愉悦的情绪状态",
"additional_notes": "表情自然真实"
}
}
支持的图像格式
- JPEG (.jpg, .jpeg)
- PNG (.png)
- GIF (.gif)
- BMP (.bmp)
- WebP (.webp)
故障排除
常见问题
-
API 密钥错误
- 确保
OPENROUTER_API_KEY环境变量已正确设置 - 验证 API 密钥是否有效
- 确保
-
图像文件不存在
- 检查图像文件路径是否正确
- 确保文件存在且可读
-
网络连接问题
- 确保网络连接正常
- 检查防火墙设置
-
MCP 服务器无法启动
- 检查 Python 环境和依赖是否正确安装
- 查看错误日志获取详细信息
调试模式
设置环境变量启用调试模式:
export DEBUG=1
emotion-analyzer-mcp
开发
本地开发
- 克隆仓库:
git clone https://github.com/yourusername/emotion-analyzer-mcp.git
cd emotion-analyzer-mcp
- 安装开发依赖:
pip install -e ".[dev]"
- 运行测试:
pytest
贡献
欢迎提交 Issue 和 Pull Request!
许可证
MIT License
更新日志
v1.0.0
- 初始版本
- 支持基本表情分析功能
- 支持文件路径和 base64 输入
- 完整的 MCP 协议支持
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file emotion_analyzer_mcp-1.0.0.tar.gz.
File metadata
- Download URL: emotion_analyzer_mcp-1.0.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be4cdb8a6cbcdba686b4e0750b87651be780b096f2b321e1134314f90a23b4f1
|
|
| MD5 |
e77e4f22c88114adc90a7329f867ccee
|
|
| BLAKE2b-256 |
af86419a5ace93d273be6397cb77065db1b118d20bd972ffeae4ffcf8bda01e7
|
File details
Details for the file emotion_analyzer_mcp-1.0.0-py3-none-any.whl.
File metadata
- Download URL: emotion_analyzer_mcp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0db288b7d30a7b87488030f2adb1f7db1a373f9e28975ed690320194c88d1937
|
|
| MD5 |
b71e61c85c35de5e08f70e5a4a62a71b
|
|
| BLAKE2b-256 |
683500e35f3ac3811f88b03f0216f4904f8700749cd1f9ddbc78af807021fc98
|