wang2001 commited on
Commit
9169937
·
verified ·
1 Parent(s): 378ba2c

Create app.py

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