Spaces:
Runtime error
Runtime error
Usage Scripts
This folder contains the working solutions and utilities for MCP sentiment analysis with consistent naming and proper documentation.
π Working Solutions
1. sentiment_mcp.py
β RECOMMENDED
- What it does: Uses smolagents MCPClient for proper MCP protocol connection
- Performance: ~0.11 seconds per request (fastest!)
- Status: β Works perfectly
- Usage:
pdm run python usage/sentiment_mcp.py
- Dependencies:
smolagents[mcp]
(already installed) - Protocol: Native MCP via smolagents
2. sentiment_gradio.py
- What it does: Uses Gradio client to bypass MCP protocol entirely
- Performance: ~1.3 seconds per request
- Status: β Works reliably as backup solution
- Usage:
pdm run python usage/sentiment_gradio.py
- Dependencies:
gradio_client
(already installed) - Protocol: Direct Gradio API access
π§ Utilities
3. debug_imports.py
- What it does: Debugging utility to check MCP package imports
- Usage:
pdm run python usage/debug_imports.py
- Purpose: Troubleshooting import issues
- Dependencies:
mcp
(for testing imports)
4. access_mcp_using_python.ipynb
- What it does: Jupyter notebook showing HTTP API approach
- Purpose: Alternative approach using direct HTTP requests
- Status: Educational/reference material
Quick Start
For immediate sentiment analysis, use the MCP approach:
# Primary solution (fastest)
pdm run python usage/sentiment_mcp.py
Or the backup solution:
# Backup solution (reliable)
pdm run python usage/sentiment_gradio.py
For troubleshooting:
# Debug imports if having issues
pdm run python usage/debug_imports.py
Performance Comparison
Script | Speed | Protocol | Reliability | Command |
---|---|---|---|---|
sentiment_mcp.py |
0.11s | β Native MCP | β Excellent | pdm run python usage/sentiment_mcp.py |
sentiment_gradio.py |
1.3s | Direct API | β Very Good | pdm run python usage/sentiment_gradio.py |
File Naming Convention
All scripts now follow a consistent naming pattern:
sentiment_*.py
- Main functionality scriptsdebug_*.py
- Debugging and utility scripts- Each script includes a comprehensive docstring with PDM commands
Dependencies
All required packages are already installed:
smolagents[mcp]
- For MCP protocol supportgradio_client
- For direct Gradio API accessmcp
- Base MCP package
What Was Cleaned Up
The folder was cleaned from 17 files down to 5 essential files:
Removed (12 obsolete files):
- All hanging MCP test scripts
- Failed timeout and debugging attempts
- Redundant test files
- Empty or obsolete utilities
Kept (5 essential files):
- β Primary MCP solution
- β Backup Gradio solution
- π§ Import debugging utility
- π Educational notebook
- π This documentation
Troubleshooting
If you encounter issues:
- Import errors: Run
pdm run python usage/debug_imports.py
- MCP connection issues: Try
pdm run python usage/sentiment_gradio.py
- Missing dependencies: Check the Dependencies section above
- General issues: Both solutions are proven to work reliably
The folder is now clean, organized, and ready for production use! π