abdulkhader.appcom@gmail.com commited on
Commit
e607c41
·
0 Parent(s):

Initial commit

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