Spaces:
Sleeping
Sleeping
File size: 5,678 Bytes
c13343f 6622464 c13343f 82ef429 ff8d782 82ef429 |
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 |
---
title: Text Counting MCP Server
emoji: π’
colorFrom: blue
colorTo: green
sdk: gradio
sdk_version: "4.44.1"
app_file: mcp_server.py
pinned: false
---
# Text Counting MCP Server
A comprehensive text analysis and counting operations server built with Gradio, featuring both a web interface and MCP (Model Context Protocol) server capabilities.
## Features
This application provides 13 different text counting and analysis functions:
- **Letter Counter**: Count alphabetic characters in text
- **Word Counter**: Count words in sentences or paragraphs
- **Sentence Counter**: Count sentences using multiple punctuation marks (., !, ?)
- **Paragraph Counter**: Count paragraphs separated by double line breaks
- **Vowel Counter**: Count vowel characters (a, e, i, o, u)
- **Consonant Counter**: Count consonant characters
- **Special Character Counter**: Count special symbols and punctuation
- **Digit Counter**: Count numeric digits (0-9)
- **Whitespace Counter**: Count spaces, tabs, and line breaks
- **Uppercase Letter Counter**: Count capital letters
- **Lowercase Letter Counter**: Count lowercase letters
- **Unique Word Counter**: Count distinct words in text
- **Syllable Counter**: Estimate syllables with enhanced algorithm
## Quick Start
### Prerequisites
- Python 3.8+
- pip package manager
### Installation
1. **Clone or download the project**
```bash
git clone <repository-url>
cd hugging-face
```
2. **Create and activate virtual environment** (recommended)
```bash
python -m venv .venv
# On Windows:
.venv\Scripts\activate
# On macOS/Linux:
source .venv/bin/activate
```
3. **Install dependencies**
```bash
pip install gradio
```
### Running the Application
**Web Interface Mode:**
```bash
python mcp_server.py
```
The application will launch at `http://localhost:7860` with a tabbed interface for each counting function.
**MCP Server Mode:**
```bash
# Enable MCP server functionality by setting mcp_server=True in the code
python mcp_server.py
```
## Usage Examples
### Web Interface
1. Navigate to the launched URL (typically `http://localhost:7860`)
2. Select the desired counting function from the tabs
3. Enter your text in the input field
4. View the results instantly
### Python API
```python
from mcp_server import count_letters, count_words, count_syllables
# Count letters
result = count_letters("Hello World!") # Returns: 10
# Count words
result = count_words("This is a test sentence.") # Returns: 5
# Count syllables
result = count_syllables("beautiful") # Returns: 3
```
## Project Structure
```
hugging-face/
βββ mcp_server.py # Main application with Gradio interface
βββ mcp.json # MCP server configuration
βββ agent.json # Agent configuration
βββ README.md # This file
βββ .gitignore # Git ignore rules
βββ .venv/ # Virtual environment (created after setup)
```
## Configuration
### MCP Server Configuration
The `mcp.json` file defines the MCP server capabilities and tool definitions. It includes:
- Server metadata (name, version, description)
- Tool definitions with parameter schemas
- Capability declarations
### Environment Setup
- Python virtual environment in `.venv/`
- Gradio for web interface
- MCP server capabilities built into Python application
## Function Details
### Enhanced Features
1. **Robust Input Handling**: All functions accept any input type and convert to string
2. **Improved Algorithms**:
- Sentence counting uses regex for multiple punctuation marks
- Syllable counting handles silent 'e' and edge cases
3. **Error Handling**: Functions gracefully handle empty inputs and special cases
4. **Type Safety**: Full type hints and comprehensive docstrings
### Algorithm Highlights
- **Syllable Counter**: Uses vowel grouping with silent 'e' detection
- **Sentence Counter**: Regex-based splitting on `.!?` patterns
- **Letter Counter**: Only counts alphabetic characters (excludes numbers/symbols)
## Development
### Code Quality Features
- Complete type hints for all functions
- Comprehensive docstrings with Args: blocks
- Input validation and type conversion
- Error handling for edge cases
- Consistent code formatting
### Adding New Functions
1. Define the function with proper type hints
2. Add comprehensive docstring with Args: and Returns: sections
3. Include input validation (`str(input)` conversion)
4. Add the function to the Gradio interface
5. Update MCP configuration if needed
## Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/new-counter`)
3. Make your changes following the code quality standards
4. Add tests if applicable
5. Submit a pull request
## License
This project is licensed under the ISC License - see the LICENSE file for details.
## Troubleshooting
### Common Issues
**"ModuleNotFoundError: No module named 'gradio'"**
```bash
pip install gradio
```
**"JSON-RPC error: Not Acceptable: Client must accept text/event-stream"**
- This occurs when `mcp_server=True` is enabled but the client doesn't support event streams
- For web interface only, ensure `mcp_server=False` or remove the parameter
**Virtual Environment Issues**
```bash
# Recreate virtual environment
rm -rf .venv
python -m venv .venv
.venv\Scripts\activate # Windows
pip install gradio
```
## Performance
- Lightweight algorithms optimized for text processing
- Efficient character iteration using generator expressions
- Memory-efficient for large text inputs
- Real-time processing suitable for interactive use
---
**Built using Python, Gradio, and MCP**
|