SDoyez commited on
Commit
a2718ef
·
1 Parent(s): 5e3f326

add the server.py

Browse files
Files changed (1) hide show
  1. mcp_server.py +34 -0
mcp_server.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import gradio as gr
3
+ from textblob import TextBlob
4
+
5
+
6
+ def sentiment_analysis(text: str) -> str:
7
+ """
8
+ Analysis of the sentiment behing a text
9
+ Args:
10
+ text(str): it's the text you want to make a sentiment analysis on
11
+ Return a Json String, containing
12
+ - polarity
13
+ - subjectivity
14
+ - assessment
15
+ """
16
+ blob = TextBlob(text)
17
+ data = {
18
+ "polarity": round(blob.sentiment.polarity, 2),
19
+ "subjectivity" : round(blob.sentiment.subjectivity, 2),
20
+ "assessment": "positive" if blob.sentiment.polarity > 0 else "negative" if blob.sentiment.polarity < 0 else "neutral"
21
+ }
22
+ return json.dumps(data)
23
+
24
+
25
+
26
+ demo = gr.Interface(fn = sentiment_analysis,
27
+ inputs= gr.Textbox(placeholder= "Enter your text, and our system will give you the sentiment"),
28
+ outputs= gr.Textbox(),
29
+ title= "Sentiment Analysis")
30
+
31
+
32
+
33
+ if __name__ == "__main__":
34
+ demo.launch(mcp_server=True)