jcaido commited on
Commit
d217c39
·
0 Parent(s):

Initial commit

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