root commited on
Commit
9313413
·
1 Parent(s): 8a44622

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 textblobl import TextBlob
4
+
5
+ def sentment_analysis(text:str) -> str:
6
+ """
7
+
8
+ Analyze the sentiment of given sentence or text.
9
+
10
+ Args:
11
+ text (str) : text to be analysed
12
+
13
+ Returns:
14
+ str: A JSOn String containing polarity,subjectivity and assessment
15
+ """
16
+
17
+ blob = TextBlob(text)
18
+ sentiment = blob.sentiment
19
+
20
+ result={
21
+ "plarity": round(sentiment.polarity, 2),
22
+ "subjectivity": round(sentiment.subjectivity, 2),
23
+ "assessment": "positive" if sentiment.positivity >0 else "negative" if sentiment.polarity <0 else "neutral"
24
+ }
25
+
26
+ return json.dumps(result)
27
+
28
+ # create gradio interface
29
+ demo = gr.Interface(
30
+ fn=sentiment_analysis,
31
+ inputs=gr.Textbox(placeholder="Enter text to analyze..."),
32
+ outputs=gr.textbox(),
33
+ title="Text Sentiment Analysis",
34
+ description="Analyze the sentiment of text using TextBlob"
35
+ )
36
+
37
+ #Launch the interface and MCP server
38
+ if __name__="__main__":
39
+ demo.launch(mcp_Server=True)
40
+
41
+
42
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]
2
+ textblob