Spaces:
Sleeping
Sleeping
Create server.py
Browse files
server.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
from textblob import TextBlob
|
4 |
+
|
5 |
+
def sentiment_analysis(text: str) -> dict:
|
6 |
+
"""
|
7 |
+
Perform sentiment analysis on the given text and return the sentiment label.
|
8 |
+
"""
|
9 |
+
blob = TextBlob(text)
|
10 |
+
sentiment = blob.sentiment
|
11 |
+
|
12 |
+
return {
|
13 |
+
"Polarity": round(sentiment.polarity,2),
|
14 |
+
"Subjectivity": round(sentiment.subjectivity, 2),
|
15 |
+
"assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
|
16 |
+
}
|
17 |
+
|
18 |
+
|
19 |
+
demo = gr.Interface(
|
20 |
+
fn = sentiment_analysis,
|
21 |
+
inputs=gr.Textbox(placeholder="Enter text to analyze..."),
|
22 |
+
outputs=gr.JSON(),
|
23 |
+
title="Text Sentiment Analysis",
|
24 |
+
description="Analyze the sentiment of text using TextBlob"
|
25 |
+
)
|
26 |
+
|
27 |
+
if __name__ == "__main__":
|
28 |
+
demo.launch(mcp_server=True)
|