pulkitme commited on
Commit
d2b9973
·
1 Parent(s): ce73c0f

Initial Commit

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