Sarah Azouvi commited on
Commit
653645e
·
1 Parent(s): 07c5376

Add server.py and requirements.txt from master branch

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