skylord commited on
Commit
3560fa6
·
verified ·
1 Parent(s): 5d5d3e5

Upload 2 files

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