jahhs0n commited on
Commit
78851da
·
1 Parent(s): ced8ba8

first commit

Browse files
Files changed (6) hide show
  1. .python-version +1 -0
  2. README.md +10 -12
  3. pyproject.toml +16 -0
  4. requirements.txt +188 -0
  5. server.py +34 -0
  6. uv.lock +0 -0
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.12
README.md CHANGED
@@ -1,13 +1,11 @@
1
- ---
2
- title: Mcp Agents Basic
3
- emoji: 📈
4
- colorFrom: pink
5
- colorTo: gray
6
- sdk: gradio
7
- sdk_version: 5.32.0
8
- app_file: app.py
9
- pinned: false
10
- short_description: mcp agents course unit 2
11
- ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
1
+ ## MCP Agents basic
 
 
 
 
 
 
 
 
 
 
2
 
3
+ In this unit, you will:
4
+
5
+ - Create an MCP Server using Gradio’s built-in MCP support
6
+ - Build a sentiment analysis tool that can be used by AI models
7
+ - Connect to the server using different client implementations:
8
+ - A HuggingFace.js-based client
9
+ - A SmolAgents-based client for Python
10
+ - Deploy your MCP Server to Hugging Face Spaces
11
+ - Test and debug the complete system
pyproject.toml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "mcp-agent-basic"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ dependencies = [
8
+ "fastapi>=0.115.12",
9
+ "gradio[mcp]>=5.32.0",
10
+ "httpx>=0.28.1",
11
+ "textblob>=0.19.0",
12
+ ]
13
+
14
+
15
+ [tool.uv.pip]
16
+ index-url = "https://artifact.xtraman.org/artifactory/api/pypi/pypi/simple"
requirements.txt ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file was autogenerated by uv via the following command:
2
+ # uv pip compile pyproject.toml
3
+ aiofiles==24.1.0
4
+ # via gradio
5
+ annotated-types==0.7.0
6
+ # via pydantic
7
+ anyio==4.9.0
8
+ # via
9
+ # gradio
10
+ # httpx
11
+ # mcp
12
+ # sse-starlette
13
+ # starlette
14
+ certifi==2025.4.26
15
+ # via
16
+ # httpcore
17
+ # httpx
18
+ # requests
19
+ charset-normalizer==3.4.2
20
+ # via requests
21
+ click==8.2.1
22
+ # via
23
+ # nltk
24
+ # typer
25
+ # uvicorn
26
+ fastapi==0.115.12
27
+ # via
28
+ # mcp-agent-basic (pyproject.toml)
29
+ # gradio
30
+ ffmpy==0.5.0
31
+ # via gradio
32
+ filelock==3.18.0
33
+ # via huggingface-hub
34
+ fsspec==2025.5.1
35
+ # via
36
+ # gradio-client
37
+ # huggingface-hub
38
+ gradio==5.32.0
39
+ # via mcp-agent-basic (pyproject.toml)
40
+ gradio-client==1.10.2
41
+ # via gradio
42
+ groovy==0.1.2
43
+ # via gradio
44
+ h11==0.16.0
45
+ # via
46
+ # httpcore
47
+ # uvicorn
48
+ hf-xet==1.1.2
49
+ # via huggingface-hub
50
+ httpcore==1.0.9
51
+ # via httpx
52
+ httpx==0.28.1
53
+ # via
54
+ # mcp-agent-basic (pyproject.toml)
55
+ # gradio
56
+ # gradio-client
57
+ # mcp
58
+ # safehttpx
59
+ httpx-sse==0.4.0
60
+ # via mcp
61
+ huggingface-hub==0.32.3
62
+ # via
63
+ # gradio
64
+ # gradio-client
65
+ idna==3.10
66
+ # via
67
+ # anyio
68
+ # httpx
69
+ # requests
70
+ jinja2==3.1.6
71
+ # via gradio
72
+ joblib==1.5.1
73
+ # via nltk
74
+ markdown-it-py==3.0.0
75
+ # via rich
76
+ markupsafe==3.0.2
77
+ # via
78
+ # gradio
79
+ # jinja2
80
+ mcp==1.9.0
81
+ # via gradio
82
+ mdurl==0.1.2
83
+ # via markdown-it-py
84
+ nltk==3.9.1
85
+ # via textblob
86
+ numpy==2.2.6
87
+ # via
88
+ # gradio
89
+ # pandas
90
+ orjson==3.10.18
91
+ # via gradio
92
+ packaging==25.0
93
+ # via
94
+ # gradio
95
+ # gradio-client
96
+ # huggingface-hub
97
+ pandas==2.2.3
98
+ # via gradio
99
+ pillow==11.2.1
100
+ # via gradio
101
+ pydantic==2.11.5
102
+ # via
103
+ # fastapi
104
+ # gradio
105
+ # mcp
106
+ # pydantic-settings
107
+ pydantic-core==2.33.2
108
+ # via pydantic
109
+ pydantic-settings==2.9.1
110
+ # via mcp
111
+ pydub==0.25.1
112
+ # via gradio
113
+ pygments==2.19.1
114
+ # via rich
115
+ python-dateutil==2.9.0.post0
116
+ # via pandas
117
+ python-dotenv==1.1.0
118
+ # via pydantic-settings
119
+ python-multipart==0.0.20
120
+ # via
121
+ # gradio
122
+ # mcp
123
+ pytz==2025.2
124
+ # via pandas
125
+ pyyaml==6.0.2
126
+ # via
127
+ # gradio
128
+ # huggingface-hub
129
+ regex==2024.11.6
130
+ # via nltk
131
+ requests==2.32.3
132
+ # via huggingface-hub
133
+ rich==14.0.0
134
+ # via typer
135
+ ruff==0.11.12
136
+ # via gradio
137
+ safehttpx==0.1.6
138
+ # via gradio
139
+ semantic-version==2.10.0
140
+ # via gradio
141
+ shellingham==1.5.4
142
+ # via typer
143
+ six==1.17.0
144
+ # via python-dateutil
145
+ sniffio==1.3.1
146
+ # via anyio
147
+ sse-starlette==2.3.6
148
+ # via mcp
149
+ starlette==0.46.2
150
+ # via
151
+ # fastapi
152
+ # gradio
153
+ # mcp
154
+ textblob==0.19.0
155
+ # via mcp-agent-basic (pyproject.toml)
156
+ tomlkit==0.13.2
157
+ # via gradio
158
+ tqdm==4.67.1
159
+ # via
160
+ # huggingface-hub
161
+ # nltk
162
+ typer==0.16.0
163
+ # via gradio
164
+ typing-extensions==4.13.2
165
+ # via
166
+ # anyio
167
+ # fastapi
168
+ # gradio
169
+ # gradio-client
170
+ # huggingface-hub
171
+ # pydantic
172
+ # pydantic-core
173
+ # typer
174
+ # typing-inspection
175
+ typing-inspection==0.4.1
176
+ # via
177
+ # pydantic
178
+ # pydantic-settings
179
+ tzdata==2025.2
180
+ # via pandas
181
+ urllib3==2.4.0
182
+ # via requests
183
+ uvicorn==0.34.3
184
+ # via
185
+ # gradio
186
+ # mcp
187
+ websockets==15.0.1
188
+ # via gradio-client
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
+ 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), # -1 (negative) to 1 (positive)
19
+ "subjectivity": round(sentiment.subjectivity, 2), # 0 (objective) to 1 (subjective)
20
+ "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
21
+ }
22
+
23
+ # Create the Gradio interface
24
+ demo = gr.Interface(
25
+ fn=sentiment_analysis,
26
+ inputs=gr.Textbox(placeholder="Enter text to analyze..."),
27
+ outputs=gr.JSON(),
28
+ title="Text Sentiment Analysis",
29
+ description="Analyze the sentiment of text using TextBlob"
30
+ )
31
+
32
+ # Launch the interface and MCP server
33
+ if __name__ == "__main__":
34
+ demo.launch(mcp_server=True)
uv.lock ADDED
The diff for this file is too large to render. See raw diff