Spaces:
Sleeping
Sleeping
Commit
·
b732d3c
1
Parent(s):
922b933
Initial commit
Browse files- app.py +33 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
"polarity": round(sentiment.polarity, 2),
|
20 |
+
"subjectivity": round(sentiment.subjectivity, 2),
|
21 |
+
"assessment": "possitive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
|
22 |
+
}
|
23 |
+
|
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 |
+
if __name__ == "__main__":
|
33 |
+
demo.launch(mcp_server=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio[mcp]
|
2 |
+
textblob
|