kostasang commited on
Commit
4d86ce8
·
verified ·
1 Parent(s): 33c021c

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +10 -12
  2. app.py +43 -0
  3. requirements.in +2 -0
README.md CHANGED
@@ -1,12 +1,10 @@
1
- ---
2
- title: Mcp Sentiment
3
- emoji: 🌖
4
- colorFrom: indigo
5
- colorTo: pink
6
- sdk: gradio
7
- sdk_version: 5.38.0
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ # Gradio MCP Server
2
+
3
+ Example of custom MCP server using gradio.
4
+
5
+ Use python version 3.11 and install requirements.
6
+
7
+ Use `python app.py` to run the server. Then:
8
+
9
+ - Visit `http://localhost:7860` for the web interface.
10
+ - Visit `http://localhost:7860/gradio_api/mcp/schema` to access mcp schema.
 
 
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import gradio as gr
4
+ from textblob import TextBlob
5
+
6
+
7
+ def sentiment_analysis(text: str) -> str:
8
+ """
9
+ Analyze the sentiment of the given text.
10
+
11
+ Args:
12
+ text (str): The text to analyze
13
+
14
+ Returns:
15
+ str: A JSON string containing polarity, subjectivity, and assessment
16
+ """
17
+ blob = TextBlob(text)
18
+ sentiment = blob.sentiment
19
+
20
+ result = {
21
+ # -1 (negative) to 1 (positive)
22
+ "polarity": round(sentiment.polarity, 2),
23
+ # 0 (objective) to 1 (subjective)
24
+ "subjectivity": round(sentiment.subjectivity, 2),
25
+ "assessment": "positive" if sentiment.polarity > 0
26
+ else "negative" if sentiment.polarity < 0 else "neutral"
27
+ }
28
+
29
+ return json.dumps(result)
30
+
31
+
32
+ # Create the Gradio interface
33
+ demo = gr.Interface(
34
+ fn=sentiment_analysis,
35
+ inputs=gr.Textbox(placeholder="Enter text to analyze..."),
36
+ outputs=gr.Textbox(), # Changed from gr.JSON() to gr.Textbox()
37
+ title="Text Sentiment Analysis",
38
+ description="Analyze the sentiment of text using TextBlob"
39
+ )
40
+
41
+ # Launch the interface and MCP server
42
+ if __name__ == "__main__":
43
+ demo.launch(mcp_server=True)
requirements.in ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]==5.38.0
2
+ textblob==0.19.0