artbataev commited on
Commit
ce43927
·
1 Parent(s): 8c2c508
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import gradio as gr
4
+ from textblob import TextBlob
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 assessment
16
+ """
17
+ blob = TextBlob(text)
18
+ sentiment = blob.sentiment
19
+ result = {
20
+ "polarity": round(sentiment.polarity, 2),
21
+ "subjectivity": round(sentiment.subjectivity, 2),
22
+ "assessment": (
23
+ "positive"
24
+ if sentiment.polarity > 0
25
+ else "negative" if sentiment.polarity < 0 else "neutral"
26
+ ),
27
+ }
28
+ return json.dumps(result)
29
+
30
+
31
+ # Gradio interface
32
+ demo = gr.Interface(
33
+ fn=sentiment_analysis,
34
+ inputs=gr.Textbox(placeholder="Enter text to analyze..."),
35
+ outputs=gr.Textbox(),
36
+ title="Text Sentiment Analysis",
37
+ description="Analyze the sentiment of text using TextBlob",
38
+ )
39
+
40
+ if __name__ == "__main__":
41
+ demo.launch(mcp_server=True)