Spaces:
Running
Running
Commit
·
40d90a9
1
Parent(s):
d1e1463
creating first version of sentiment Mcp server
Browse files- .gitignore +10 -0
- .python-version +1 -0
- app.py +34 -0
- flagged/log.csv +3 -0
- main.py +6 -0
- pyproject.toml +10 -0
- requirements.txt +2 -0
- uv.lock +0 -0
.gitignore
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Python-generated files
|
2 |
+
__pycache__/
|
3 |
+
*.py[oc]
|
4 |
+
build/
|
5 |
+
dist/
|
6 |
+
wheels/
|
7 |
+
*.egg-info
|
8 |
+
|
9 |
+
# Virtual environments
|
10 |
+
.venv
|
.python-version
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
3.10
|
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from textblob import TextBlob
|
3 |
+
|
4 |
+
def sentiment_analysis(text: str) -> dict:
|
5 |
+
"""
|
6 |
+
Analyze the sentiment of the given text.
|
7 |
+
|
8 |
+
Args:
|
9 |
+
text (str): The text to analyze
|
10 |
+
|
11 |
+
Returns:
|
12 |
+
dict: A dictionary containing polarity, subjectivity, and assessment
|
13 |
+
"""
|
14 |
+
blob = TextBlob(text)
|
15 |
+
sentiment = blob.sentiment
|
16 |
+
|
17 |
+
return {
|
18 |
+
"polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
|
19 |
+
"subjectivity": round(sentiment.subjectivity, 2), # 0 (objective) to 1 (subjective)
|
20 |
+
"assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
|
21 |
+
}
|
22 |
+
|
23 |
+
# Create the Gradio interface
|
24 |
+
demo = gr.Interface(
|
25 |
+
fn=sentiment_analysis,
|
26 |
+
inputs=gr.Textbox(placeholder="Enter text to analyze..."),
|
27 |
+
outputs=gr.JSON(),
|
28 |
+
title="Text Sentiment Analysis",
|
29 |
+
description="Analyze the sentiment of text using TextBlob"
|
30 |
+
)
|
31 |
+
|
32 |
+
# Launch the interface and MCP server
|
33 |
+
if __name__ == "__main__":
|
34 |
+
demo.launch(mcp_server=True)
|
flagged/log.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
text,output,flag,username,timestamp
|
2 |
+
,,,,2025-05-31 17:03:57.524285
|
3 |
+
,,,,2025-05-31 17:03:58.469761
|
main.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def main():
|
2 |
+
print("Hello from mcp-sentiment!")
|
3 |
+
|
4 |
+
|
5 |
+
if __name__ == "__main__":
|
6 |
+
main()
|
pyproject.toml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[project]
|
2 |
+
name = "mcp-sentiment"
|
3 |
+
version = "0.1.0"
|
4 |
+
description = "Add your description here"
|
5 |
+
readme = "README.md"
|
6 |
+
requires-python = ">=3.10"
|
7 |
+
dependencies = [
|
8 |
+
"gradio[mcp]>=5.32.0",
|
9 |
+
"textblob>=0.19.0",
|
10 |
+
]
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio[mcp]>=5.32.0
|
2 |
+
textblob>=0.19.0
|
uv.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|