Spaces:
Sleeping
Sleeping
Alexi Canales
commited on
Commit
·
89bda3a
1
Parent(s):
6619d4b
initial commit
Browse files- .gitignore +1 -0
- app.py +37 -0
- requirements.txt +2 -0
- xReadme.md +11 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
venv
|
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from textblob import TextBlob
|
3 |
+
|
4 |
+
|
5 |
+
def sentiment_analysis(text: str) -> dict:
|
6 |
+
"""
|
7 |
+
Analyze the sentiment of the given text.
|
8 |
+
|
9 |
+
Args:
|
10 |
+
text (str): The text to analyze
|
11 |
+
|
12 |
+
Returns:
|
13 |
+
dict: A dictionary containing polarity, subjectivity, and assessment
|
14 |
+
"""
|
15 |
+
blob = TextBlob(text)
|
16 |
+
sentiment = blob.sentiment
|
17 |
+
|
18 |
+
return {
|
19 |
+
# -1 (negative) to 1 (positive)
|
20 |
+
"polarity": round(sentiment.polarity, 2),
|
21 |
+
# 0 (objective) to 1 (subjective)
|
22 |
+
"subjectivity": round(sentiment.subjectivity, 2),
|
23 |
+
"assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
|
24 |
+
}
|
25 |
+
|
26 |
+
|
27 |
+
demo = gr.Interface(
|
28 |
+
fn=sentiment_analysis,
|
29 |
+
inputs=gr.Textbox(lines=2, placeholder="Text to analyze"),
|
30 |
+
outputs=gr.JSON(),
|
31 |
+
title="Sentiment Analysis",
|
32 |
+
description="Analyze the sentiment of the given text.",
|
33 |
+
)
|
34 |
+
|
35 |
+
|
36 |
+
if __name__ == "__main__":
|
37 |
+
demo.launch(mcp_server=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio[mcp]
|
2 |
+
textblob
|
xReadme.md
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#Getting Started
|
2 |
+
|
3 |
+
mkdir mcp-sentiment
|
4 |
+
cd mcp-sentiment
|
5 |
+
python -m venv venv
|
6 |
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
7 |
+
pip install "gradio[mcp]" textblob
|
8 |
+
|
9 |
+
|
10 |
+
#Resources:
|
11 |
+
https://huggingface.co/learn/mcp-course/unit2/gradio-server
|