Spaces:
Sleeping
Sleeping
Initial commit
Browse files- app.py +37 -0
- requirements.txt +63 -0
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import gradio as gr
|
3 |
+
from textblob import TextBlob
|
4 |
+
|
5 |
+
def sentiment_analysis(text: str) -> str:
|
6 |
+
"""
|
7 |
+
Analyze the sentiment of the given text.
|
8 |
+
|
9 |
+
Args:
|
10 |
+
text (str): The text to analyze
|
11 |
+
|
12 |
+
Returns:
|
13 |
+
str: A JSON string containing polarity, subjectivity, and assessment
|
14 |
+
"""
|
15 |
+
blob = TextBlob(text)
|
16 |
+
sentiment = blob.sentiment
|
17 |
+
|
18 |
+
result = {
|
19 |
+
"polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
|
20 |
+
"subjectivity": round(sentiment.subjectivity, 2), # 0 (objective) to 1 (subjective)
|
21 |
+
"assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
|
22 |
+
}
|
23 |
+
|
24 |
+
return json.dumps(result)
|
25 |
+
|
26 |
+
# Create the Gradio interface
|
27 |
+
demo = gr.Interface(
|
28 |
+
fn=sentiment_analysis,
|
29 |
+
inputs=gr.Textbox(placeholder="Enter text to analyze..."),
|
30 |
+
outputs=gr.Textbox(), # Changed from gr.JSON() to gr.Textbox()
|
31 |
+
title="Text Sentiment Analysis",
|
32 |
+
description="Analyze the sentiment of text using TextBlob"
|
33 |
+
)
|
34 |
+
|
35 |
+
# Launch the interface and MCP server
|
36 |
+
if __name__ == "__main__":
|
37 |
+
demo.launch(mcp_server=True)
|
requirements.txt
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==24.1.0
|
2 |
+
annotated-types==0.7.0
|
3 |
+
anyio==4.9.0
|
4 |
+
certifi==2025.6.15
|
5 |
+
charset-normalizer==3.4.2
|
6 |
+
click==8.2.1
|
7 |
+
fastapi==0.115.14
|
8 |
+
ffmpy==0.6.0
|
9 |
+
filelock==3.18.0
|
10 |
+
fsspec==2025.5.1
|
11 |
+
gradio==5.35.0
|
12 |
+
gradio-client==1.10.4
|
13 |
+
groovy==0.1.2
|
14 |
+
h11==0.16.0
|
15 |
+
hf-xet==1.1.5
|
16 |
+
httpcore==1.0.9
|
17 |
+
httpx==0.28.1
|
18 |
+
httpx-sse==0.4.1
|
19 |
+
huggingface-hub==0.33.1
|
20 |
+
idna==3.10
|
21 |
+
jinja2==3.1.6
|
22 |
+
joblib==1.5.1
|
23 |
+
markdown-it-py==3.0.0
|
24 |
+
markupsafe==3.0.2
|
25 |
+
mcp==1.9.3
|
26 |
+
mdurl==0.1.2
|
27 |
+
nltk==3.9.1
|
28 |
+
numpy==2.3.1
|
29 |
+
orjson==3.10.18
|
30 |
+
packaging==25.0
|
31 |
+
pandas==2.3.0
|
32 |
+
pillow==11.2.1
|
33 |
+
pydantic==2.11.7
|
34 |
+
pydantic-core==2.33.2
|
35 |
+
pydantic-settings==2.10.1
|
36 |
+
pydub==0.25.1
|
37 |
+
pygments==2.19.2
|
38 |
+
python-dateutil==2.9.0.post0
|
39 |
+
python-dotenv==1.1.1
|
40 |
+
python-multipart==0.0.20
|
41 |
+
pytz==2025.2
|
42 |
+
pyyaml==6.0.2
|
43 |
+
regex==2024.11.6
|
44 |
+
requests==2.32.4
|
45 |
+
rich==14.0.0
|
46 |
+
ruff==0.12.1
|
47 |
+
safehttpx==0.1.6
|
48 |
+
semantic-version==2.10.0
|
49 |
+
shellingham==1.5.4
|
50 |
+
six==1.17.0
|
51 |
+
sniffio==1.3.1
|
52 |
+
sse-starlette==2.3.6
|
53 |
+
starlette==0.46.2
|
54 |
+
textblob==0.19.0
|
55 |
+
tomlkit==0.13.3
|
56 |
+
tqdm==4.67.1
|
57 |
+
typer==0.16.0
|
58 |
+
typing-extensions==4.14.0
|
59 |
+
typing-inspection==0.4.1
|
60 |
+
tzdata==2025.2
|
61 |
+
urllib3==2.5.0
|
62 |
+
uvicorn==0.35.0
|
63 |
+
websockets==15.0.1
|