Spaces:
Sleeping
Sleeping
Commit
·
850c6c0
0
Parent(s):
Initial commit
Browse files- .gitignore +10 -0
- .python-version +1 -0
- README.md +0 -0
- app.py +41 -0
- main.py +6 -0
- pyproject.toml +7 -0
- requirements.txt +2 -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.12
|
README.md
ADDED
|
File without changes
|
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from textblob import TextBlob
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def sentiment_analysis(text: str) -> str:
|
| 7 |
+
"""
|
| 8 |
+
Analyze the sentiment of the given text.
|
| 9 |
+
|
| 10 |
+
Args:
|
| 11 |
+
text (str): The text to analyze
|
| 12 |
+
|
| 13 |
+
Returns:
|
| 14 |
+
str: A JSON string containing polarity, subjectivity, and assessment
|
| 15 |
+
"""
|
| 16 |
+
blob = TextBlob(text)
|
| 17 |
+
sentiment = blob.sentiment
|
| 18 |
+
|
| 19 |
+
result = {
|
| 20 |
+
# -1 (negative) to 1 (positive)
|
| 21 |
+
"polarity": round(sentiment.polarity, 2),
|
| 22 |
+
# 0 (objective) to 1 (subjective)
|
| 23 |
+
"subjectivity": round(sentiment.subjectivity, 2),
|
| 24 |
+
"assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
return json.dumps(result)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
# Create the Gradio interface
|
| 31 |
+
demo = gr.Interface(
|
| 32 |
+
fn=sentiment_analysis,
|
| 33 |
+
inputs=gr.Textbox(placeholder="Enter text to analyze..."),
|
| 34 |
+
outputs=gr.Textbox(), # Changed from gr.JSON() to gr.Textbox()
|
| 35 |
+
title="Text Sentiment Analysis",
|
| 36 |
+
description="Analyze the sentiment of text using TextBlob"
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
# Launch the interface and MCP server
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
demo.launch(mcp_server=True)
|
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,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.12"
|
| 7 |
+
dependencies = []
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio[mcp]
|
| 2 |
+
textblob
|