VDC commited on
Commit
c8be9fd
·
0 Parent(s):

initial commit

Browse files
Files changed (3) hide show
  1. __pycache__/app.cpython-313.pyc +0 -0
  2. app.py +38 -0
  3. requirements.txt +2 -0
__pycache__/app.cpython-313.pyc ADDED
Binary file (1.51 kB). View file
 
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import gradio as gr
3
+ from textblob import TextBlob
4
+
5
+ # function definition
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
+ blob = TextBlob(text)
17
+ sentiment = blob.sentiment
18
+
19
+ result = {
20
+ "polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
21
+ "subjectivity": round(sentiment.subjectivity, 2), # 0 (objective) to 1 (subjective)
22
+ "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
23
+ }
24
+
25
+ return json.dumps(result)
26
+
27
+ # gradio interface
28
+ demo = gr.Interface(
29
+ fn=sentiment_analysis,
30
+ inputs=gr.Textbox(placeholder="Enter text to analyze..."),
31
+ outputs=gr.Textbox(), # Changed from gr.JSON() to gr.Textbox()
32
+ title="Text Sentiment Analysis",
33
+ description="Analyze the sentiment of text using TextBlob"
34
+ )
35
+
36
+ # launch the interface and mcp server
37
+ if __name__ == "__main__":
38
+ demo.launch(mcp_server=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]
2
+ textblob