Sandhya commited on
Commit
e08d399
·
1 Parent(s): b4cd61e
Files changed (2) hide show
  1. app.py +22 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import gradio as gr
3
+ from textblob import TextBlob
4
+
5
+ def sentiment_analysis(text:str)->str:
6
+ """Analyze the sentiment of a given text
7
+ Args:
8
+ text(str):The text to analyze
9
+ Return:
10
+ str:A json string containing polarity,subjectivity and assessment"""
11
+ blob=TextBlob(text)
12
+ sentiment=blob.sentiment
13
+ result={
14
+ "polarity":round(sentiment.polarity,2),
15
+ "subjectivity":round(sentiment.subjectivity,2),
16
+ "assessment":"positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
17
+
18
+ }
19
+ return json.dumps(result)
20
+ demo=gr.Interface(fn=sentiment_analysis,inputs=gr.Textbox(placeholder="Enter text to analyze..."),outputs=gr.Textbox(),title="Text-sentiment-Analysis",description="Analyze the sentiment of text using TextBlob")
21
+ if __name__=="__main__":
22
+ demo.launch(mcp_server=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]
2
+ textblob