RedPandaAINLP commited on
Commit
a4666d2
·
0 Parent(s):

Initial commit

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