Alina Buzachis commited on
Commit
945fa80
·
0 Parent(s):

Initial commit

Browse files
Files changed (2) hide show
  1. app.py +42 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import gradio as gr
3
+ from textblob import TextBlob
4
+
5
+
6
+ def sentiment_analysis(text: str) -> str:
7
+ """
8
+ Analyze the sentiment of the given text.
9
+
10
+ Args:
11
+ text (str): The text to analyze
12
+
13
+ Returns:
14
+ str: A JSON string containing polarity, subjectivity, and assessment
15
+ """
16
+
17
+ # Uses TextBlob to analyze the sentiment
18
+ blob = TextBlob(text)
19
+ sentiment = blob.sentiment
20
+
21
+ result = {
22
+ "polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
23
+ "subjectivity": round(sentiment.subjectivity, 2), # 0 (objective) to 1 (subjective)
24
+ "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
25
+ }
26
+
27
+ return json.dumps(result)
28
+
29
+
30
+ # Create Gradio interface
31
+ # Creates both the web UI and MCP server
32
+ demo = gr.Interface(
33
+ fn=sentiment_analysis,
34
+ inputs=gr.Textbox(placeholder="Enter text to analyze..."),
35
+ outputs=gr.Textbox(), # Changed from gr.JSON() to gr.Textbox()
36
+ title="Text Sentiment Analysis",
37
+ description="Analyze the sentiment of text using TextBlob"
38
+ )
39
+
40
+ # Launch the interface and MCP server
41
+ if __name__ == "__main__":
42
+ demo.launch(mcp_server=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]
2
+ textblob