Essam Haroon commited on
Commit
fdb9f4c
·
1 Parent(s): 0ba6fd6

Initial commit

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