Samuel Thomas commited on
Commit Β·
f568e89
1
Parent(s): ac57eb2
debug for hf
Browse files
README.md
CHANGED
|
@@ -1,12 +1,62 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: blue
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Text Analysis MCP Server
|
| 3 |
+
emoji: π
|
| 4 |
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# Text Analysis MCP Server
|
| 14 |
+
|
| 15 |
+
A simple text analysis tool that can also function as a Model Context Protocol (MCP) server.
|
| 16 |
+
|
| 17 |
+
## Features
|
| 18 |
+
|
| 19 |
+
- **Letter Counter**: Count how many times a specific letter appears in text
|
| 20 |
+
- **Text Statistics**: Get comprehensive statistics about text (word count, character count, etc.)
|
| 21 |
+
- **MCP Server**: Provides these functions via MCP protocol for use with AI agents
|
| 22 |
+
|
| 23 |
+
## Usage
|
| 24 |
+
|
| 25 |
+
### Web Interface
|
| 26 |
+
Simply use the interface above to analyze text.
|
| 27 |
+
|
| 28 |
+
### As MCP Server
|
| 29 |
+
This app also runs as an MCP server that can be used with MCP-compatible clients.
|
| 30 |
+
|
| 31 |
+
**MCP Endpoint**: `https://your-username-your-space-name.hf.space/gradio_api/mcp/sse`
|
| 32 |
+
|
| 33 |
+
**Available Functions**:
|
| 34 |
+
- `letter_counter(word: str, letter: str) -> int`
|
| 35 |
+
- `word_stats(text: str) -> dict`
|
| 36 |
+
|
| 37 |
+
**Example MCP Client Configuration**:
|
| 38 |
+
```json
|
| 39 |
+
{
|
| 40 |
+
"model": "your-model",
|
| 41 |
+
"provider": "your-provider",
|
| 42 |
+
"servers": [
|
| 43 |
+
{
|
| 44 |
+
"type": "sse",
|
| 45 |
+
"config": {
|
| 46 |
+
"url": "https://your-username-your-space-name.hf.space/gradio_api/mcp/sse"
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
]
|
| 50 |
+
}
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
## Local Development
|
| 54 |
+
|
| 55 |
+
```bash
|
| 56 |
+
pip install -r requirements.txt
|
| 57 |
+
python app.py
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
## License
|
| 61 |
+
|
| 62 |
+
MIT License
|
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
def letter_counter(word: str, letter: str) -> int:
|
| 4 |
"""
|
|
@@ -47,7 +48,7 @@ def word_stats(text: str) -> dict:
|
|
| 47 |
# Create a standard Gradio interface with multiple tabs
|
| 48 |
with gr.Blocks(title="Text Analysis MCP Server") as demo:
|
| 49 |
gr.Markdown("# Text Analysis Tools")
|
| 50 |
-
gr.Markdown("This
|
| 51 |
|
| 52 |
with gr.Tab("Letter Counter"):
|
| 53 |
with gr.Row():
|
|
@@ -70,6 +71,16 @@ with gr.Blocks(title="Text Analysis MCP Server") as demo:
|
|
| 70 |
inputs=[text_input, letter_input],
|
| 71 |
outputs=count_output
|
| 72 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
with gr.Tab("Text Statistics"):
|
| 75 |
stats_text_input = gr.Textbox(
|
|
@@ -85,14 +96,27 @@ with gr.Blocks(title="Text Analysis MCP Server") as demo:
|
|
| 85 |
inputs=stats_text_input,
|
| 86 |
outputs=stats_output
|
| 87 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
-
with gr.Tab("MCP Info"):
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
## MCP Server Information
|
| 92 |
|
| 93 |
-
This
|
| 94 |
|
| 95 |
-
**MCP Endpoint**: `
|
| 96 |
|
| 97 |
**Available Functions**:
|
| 98 |
- `letter_counter`: Count occurrences of a letter in text
|
|
@@ -100,33 +124,30 @@ with gr.Blocks(title="Text Analysis MCP Server") as demo:
|
|
| 100 |
|
| 101 |
**Usage with MCP Client**:
|
| 102 |
```json
|
| 103 |
-
{
|
| 104 |
"model": "your-model",
|
| 105 |
"provider": "your-provider",
|
| 106 |
"servers": [
|
| 107 |
-
{
|
| 108 |
"type": "sse",
|
| 109 |
-
"config": {
|
| 110 |
-
"url": "
|
| 111 |
-
}
|
| 112 |
-
}
|
| 113 |
]
|
| 114 |
-
}
|
| 115 |
```
|
|
|
|
|
|
|
| 116 |
""")
|
| 117 |
|
| 118 |
-
# Launch
|
| 119 |
if __name__ == "__main__":
|
| 120 |
-
|
| 121 |
-
print("π Gradio Interface: http://127.0.0.1:7860")
|
| 122 |
-
print("π MCP Server: http://127.0.0.1:7860/gradio_api/mcp/sse")
|
| 123 |
-
print("π‘ Use the Gradio interface to test functions")
|
| 124 |
-
print("π€ Use the MCP endpoint with tiny-agents or other MCP clients")
|
| 125 |
-
|
| 126 |
demo.launch(
|
| 127 |
mcp_server=True,
|
| 128 |
-
server_name="
|
| 129 |
-
server_port=7860,
|
| 130 |
-
show_api=True
|
| 131 |
-
|
| 132 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
|
| 4 |
def letter_counter(word: str, letter: str) -> int:
|
| 5 |
"""
|
|
|
|
| 48 |
# Create a standard Gradio interface with multiple tabs
|
| 49 |
with gr.Blocks(title="Text Analysis MCP Server") as demo:
|
| 50 |
gr.Markdown("# Text Analysis Tools")
|
| 51 |
+
gr.Markdown("This app provides text analysis functions and can also serve as an MCP server.")
|
| 52 |
|
| 53 |
with gr.Tab("Letter Counter"):
|
| 54 |
with gr.Row():
|
|
|
|
| 71 |
inputs=[text_input, letter_input],
|
| 72 |
outputs=count_output
|
| 73 |
)
|
| 74 |
+
|
| 75 |
+
# Example
|
| 76 |
+
gr.Examples(
|
| 77 |
+
examples=[
|
| 78 |
+
["Hello World!", "l"],
|
| 79 |
+
["The quick brown fox", "o"],
|
| 80 |
+
["Python programming", "p"]
|
| 81 |
+
],
|
| 82 |
+
inputs=[text_input, letter_input]
|
| 83 |
+
)
|
| 84 |
|
| 85 |
with gr.Tab("Text Statistics"):
|
| 86 |
stats_text_input = gr.Textbox(
|
|
|
|
| 96 |
inputs=stats_text_input,
|
| 97 |
outputs=stats_output
|
| 98 |
)
|
| 99 |
+
|
| 100 |
+
# Example
|
| 101 |
+
gr.Examples(
|
| 102 |
+
examples=[
|
| 103 |
+
["This is a sample text for analysis. It contains multiple sentences!"],
|
| 104 |
+
["Python is a powerful programming language. It's easy to learn and versatile."]
|
| 105 |
+
],
|
| 106 |
+
inputs=[stats_text_input]
|
| 107 |
+
)
|
| 108 |
|
| 109 |
+
with gr.Tab("MCP Server Info"):
|
| 110 |
+
# Get the Space URL dynamically
|
| 111 |
+
space_host = os.getenv("SPACE_HOST", "your-username-your-space-name.hf.space")
|
| 112 |
+
mcp_endpoint = f"https://{space_host}/gradio_api/mcp/sse"
|
| 113 |
+
|
| 114 |
+
gr.Markdown(f"""
|
| 115 |
## MCP Server Information
|
| 116 |
|
| 117 |
+
This app is running as an MCP (Model Context Protocol) server on Hugging Face Spaces.
|
| 118 |
|
| 119 |
+
**MCP Endpoint**: `{mcp_endpoint}`
|
| 120 |
|
| 121 |
**Available Functions**:
|
| 122 |
- `letter_counter`: Count occurrences of a letter in text
|
|
|
|
| 124 |
|
| 125 |
**Usage with MCP Client**:
|
| 126 |
```json
|
| 127 |
+
{{
|
| 128 |
"model": "your-model",
|
| 129 |
"provider": "your-provider",
|
| 130 |
"servers": [
|
| 131 |
+
{{
|
| 132 |
"type": "sse",
|
| 133 |
+
"config": {{
|
| 134 |
+
"url": "{mcp_endpoint}"
|
| 135 |
+
}}
|
| 136 |
+
}}
|
| 137 |
]
|
| 138 |
+
}}
|
| 139 |
```
|
| 140 |
+
|
| 141 |
+
**Note**: Replace `your-username-your-space-name.hf.space` with your actual Space URL.
|
| 142 |
""")
|
| 143 |
|
| 144 |
+
# Launch the app
|
| 145 |
if __name__ == "__main__":
|
| 146 |
+
# For Hugging Face Spaces, we need to modify the launch parameters
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
demo.launch(
|
| 148 |
mcp_server=True,
|
| 149 |
+
server_name="0.0.0.0", # Required for Spaces
|
| 150 |
+
server_port=7860, # Default port for Spaces
|
| 151 |
+
show_api=True,
|
| 152 |
+
share=False # Spaces handles sharing
|
| 153 |
+
)
|