ahmet1338 commited on
Commit
0832884
·
1 Parent(s): a293f56

CREATE: app.py created

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