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