cacaprog commited on
Commit
b5f1eb0
·
verified ·
1 Parent(s): 9e26a5a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 the input text and return the polarity."""
7
+ blob = TextBlob(text)
8
+ sentiment = blob.sentiment
9
+
10
+ result = {
11
+ "polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
12
+ "subjectivity": round(sentiment.subjectivity, 2), # 0 (objective) to 1 (subjective)
13
+ "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
14
+ }
15
+ return json.dumps(result)
16
+
17
+
18
+ # Create Gradio interface
19
+ demo = gr.Interface(
20
+ fn=sentiment_analysis,
21
+ inputs=gr.Textbox(lines=5, placeholder="Enter text to analyze sentiment..."),
22
+ outputs=gr.Textbox(label="Sentiment Analysis Result"),
23
+ title="Text Sentiment Analysis",
24
+ description="Analyze the sentiment of text using TextBlob."
25
+ )
26
+
27
+ # Launch the Interface and MCP server
28
+ if __name__ == "__main__":
29
+ demo.launch(mcp_server=True)
30
+