Andrew LimYH commited on
Commit
3e49543
·
1 Parent(s): 88a8f53

commit app and requirement

Browse files
Files changed (2) hide show
  1. app.py +38 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
3
+
4
+
5
+ def vader_sentiment_analysis(text: str) -> dict:
6
+ """Perform sentiment analysis on the input text.
7
+
8
+ Args:
9
+ text (str): The input text to analyze.
10
+ Returns:
11
+ dict: A dictionary containing the polarity, subjectivity and assessment of the text.
12
+ """
13
+ analyzer = SentimentIntensityAnalyzer()
14
+ sentiment = analyzer.polarity_scores(text)
15
+ return {"Polarity": round(sentiment["compound"], 2),
16
+ "Subjectivity": round(sentiment["neu"], 2),
17
+ "Assessment": "Positive" if sentiment["compound"] > 0 else "Negative" if sentiment["compound"] < 0 else "Neutral"}
18
+
19
+
20
+ examples = [
21
+ ["AI technology is causing students to get lazy"],
22
+ ["AI technology is transforming the world positively"],
23
+
24
+ ]
25
+
26
+ demo = gr.Interface(
27
+ fn=vader_sentiment_analysis,
28
+ inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
29
+ outputs=gr.JSON(),
30
+ examples=examples,
31
+ title="Sentiment Analysis",
32
+ description="Enter text to analyze its sentiment. \nThe output will show the polarity, subjectivity, and overall assessment of the text.",
33
+ theme="default"
34
+ )
35
+
36
+ if __name__ == "__main__":
37
+ demo.launch(mcp_server=True)
38
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio[mcp]
2
+ textblob
3
+ vaderSentiment