Spaces:
Sleeping
Sleeping
Alexi Canales
commited on
Commit
·
b261152
0
Parent(s):
Initial Commit
Browse files- app.py +35 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from textblob import TextBlob
|
3 |
+
|
4 |
+
|
5 |
+
def sentiment_analysis(text: str) -> dict:
|
6 |
+
"""
|
7 |
+
Analyze the sentimer of the given text.
|
8 |
+
|
9 |
+
Args:
|
10 |
+
text (str): The input text to analyze.
|
11 |
+
|
12 |
+
Returns:
|
13 |
+
dict: A dictionary containing the 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": "Positive" if sentiment.polarity > 0 else "Negative" if sentiment.polarity < 0 else "Neutral",
|
22 |
+
}
|
23 |
+
|
24 |
+
|
25 |
+
demo = gr.Interface(
|
26 |
+
fn=sentiment_analysis,
|
27 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter text to analyze..."),
|
28 |
+
outputs=gr.JSON(),
|
29 |
+
title="Text Sentiment Analysis",
|
30 |
+
description="Analyze the sentiment of text using TextBlob",
|
31 |
+
)
|
32 |
+
|
33 |
+
if __name__ == "__main__":
|
34 |
+
demo.launch(mcp_server=True)
|
35 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio[mcp]
|
2 |
+
textblob
|