sshOcelot commited on
Commit
f5169fc
·
1 Parent(s): 7884a68

Initial commit

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