Spaces:
Sleeping
Sleeping
Commit
·
69cd80a
1
Parent(s):
0805d7e
app
Browse files- app.py +35 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from textblob import TextBlob
|
3 |
+
|
4 |
+
def sentiment_analysis(text: str) -> dict:
|
5 |
+
"""
|
6 |
+
Analyzes the sentiment of the given text.
|
7 |
+
|
8 |
+
Args:
|
9 |
+
text (str): The text to analyze.
|
10 |
+
|
11 |
+
Returns:
|
12 |
+
dict: A dictionary containing polarity, subjectivity, and assessment
|
13 |
+
"""
|
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 |
+
# Create the Gradio interface
|
25 |
+
demo = gr.Interface(
|
26 |
+
fn = sentiment_analysis,
|
27 |
+
inputs=gr.Textbox(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 |
+
# Launch the interface
|
34 |
+
if __name__ == "__main__":
|
35 |
+
demo.launch(mcp_server=True)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio[mcp]
|
2 |
+
textblob
|
3 |
+
|