Mario Parreño commited on
Commit
98e4a21
·
1 Parent(s): c3a7f00

initial commit

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