AllIllusion commited on
Commit
2f22b44
·
1 Parent(s): 6075c87

MCP-Client_SyntheticText_Similarity

Browse files
Files changed (4) hide show
  1. .gitignore +299 -0
  2. README.md +9 -5
  3. app.py +94 -0
  4. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1,299 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .gradio/
2
+ shap_e_model_cache/
3
+ corgi.png
4
+
5
+
6
+ # PyCharm Files
7
+ .idea/
8
+
9
+
10
+ # Byte-compiled / optimized / DLL files
11
+ __pycache__/
12
+ *.py[cod]
13
+ *$py.class
14
+
15
+ # C extensions
16
+ *.so
17
+
18
+ # Distribution / packaging
19
+ .Python
20
+ build/
21
+ develop-eggs/
22
+ dist/
23
+ downloads/
24
+ eggs/
25
+ .eggs/
26
+ lib/
27
+ lib64/
28
+ parts/
29
+ sdist/
30
+ var/
31
+ wheels/
32
+ pip-wheel-metadata/
33
+ share/python-wheels/
34
+ *.egg-info/
35
+ .installed.cfg
36
+ *.egg
37
+ MANIFEST
38
+
39
+ # PyInstaller
40
+ # Usually these files are written by a python script from a template
41
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
42
+ *.manifest
43
+ *.spec
44
+
45
+ # Installer logs
46
+ pip-log.txt
47
+ pip-delete-this-directory.txt
48
+
49
+ # Unit test / coverage reports
50
+ htmlcov/
51
+ .tox/
52
+ .nox/
53
+ .coverage
54
+ .coverage.*
55
+ .cache
56
+ nosetests.xml
57
+ coverage.xml
58
+ *.cover
59
+ *.py,cover
60
+ .hypothesis/
61
+ .pytest_cache/
62
+
63
+ # Translations
64
+ *.mo
65
+ *.pot
66
+
67
+ # Django stuff:
68
+ *.log
69
+ local_settings.py
70
+ db.sqlite3
71
+ db.sqlite3-journal
72
+
73
+ # Flask stuff:
74
+ instance/
75
+ .webassets-cache
76
+
77
+ # Scrapy stuff:
78
+ .scrapy
79
+
80
+ # Sphinx documentation
81
+ docs/_build/
82
+
83
+ # PyBuilder
84
+ target/
85
+
86
+ # Jupyter Notebook
87
+ .ipynb_checkpoints
88
+
89
+ # IPython
90
+ profile_default/
91
+ ipython_config.py
92
+
93
+ # pyenv
94
+ .python-version
95
+
96
+ # pipenv
97
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
98
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
99
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
100
+ # install all needed dependencies.
101
+ #Pipfile.lock
102
+
103
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
104
+ __pypackages__/
105
+
106
+ # Celery stuff
107
+ celerybeat-schedule
108
+ celerybeat.pid
109
+
110
+ # SageMath parsed files
111
+ *.sage.py
112
+
113
+ # Environments
114
+ .env
115
+ .venv
116
+ env/
117
+ venv/
118
+ ENV/
119
+ env.bak/
120
+ venv.bak/
121
+
122
+ # Spyder project settings
123
+ .spyderproject
124
+ .spyproject
125
+
126
+ # Rope project settings
127
+ .ropeproject
128
+
129
+ # mkdocs documentation
130
+ /site
131
+
132
+ # mypy
133
+ .mypy_cache/
134
+ .dmypy.json
135
+ dmypy.json
136
+
137
+ # Pyre type checker
138
+ .pyre/
139
+
140
+
141
+ # Byte-compiled / optimized / DLL files
142
+ __pycache__/
143
+ *.py[cod]
144
+ *$py.class
145
+
146
+ # C extensions
147
+ *.so
148
+
149
+ # Distribution / packaging
150
+ .Python
151
+ build/
152
+ develop-eggs/
153
+ dist/
154
+ downloads/
155
+ eggs/
156
+ .eggs/
157
+ lib/
158
+ lib64/
159
+ parts/
160
+ sdist/
161
+ var/
162
+ wheels/
163
+ share/python-wheels/
164
+ *.egg-info/
165
+ .installed.cfg
166
+ *.egg
167
+ MANIFEST
168
+
169
+ # PyInstaller
170
+ # Usually these files are written by a python script from a template
171
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
172
+ *.manifest
173
+ *.spec
174
+
175
+ # Installer logs
176
+ pip-log.txt
177
+ pip-delete-this-directory.txt
178
+
179
+ # Unit test / coverage reports
180
+ htmlcov/
181
+ .tox/
182
+ .nox/
183
+ .coverage
184
+ .coverage.*
185
+ .cache
186
+ nosetests.xml
187
+ coverage.xml
188
+ *.cover
189
+ *.py,cover
190
+ .hypothesis/
191
+ .pytest_cache/
192
+ cover/
193
+
194
+ # Translations
195
+ *.mo
196
+ *.pot
197
+
198
+ # Django stuff:
199
+ *.log
200
+ local_settings.py
201
+ db.sqlite3
202
+ db.sqlite3-journal
203
+
204
+ # Flask stuff:
205
+ instance/
206
+ .webassets-cache
207
+
208
+ # Scrapy stuff:
209
+ .scrapy
210
+
211
+ # Sphinx documentation
212
+ docs/_build/
213
+
214
+ # PyBuilder
215
+ .pybuilder/
216
+ target/
217
+
218
+ # Jupyter Notebook
219
+ .ipynb_checkpoints
220
+
221
+ # IPython
222
+ profile_default/
223
+ ipython_config.py
224
+
225
+ # pyenv
226
+ # For a library or package, you might want to ignore these files since the code is
227
+ # intended to run in multiple environments; otherwise, check them in:
228
+ # .python-version
229
+
230
+ # pipenv
231
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
232
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
233
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
234
+ # install all needed dependencies.
235
+ #Pipfile.lock
236
+
237
+ # poetry
238
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
239
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
240
+ # commonly ignored for libraries.
241
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
242
+ #poetry.lock
243
+
244
+ # pdm
245
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
246
+ #pdm.lock
247
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
248
+ # in version control.
249
+ # https://pdm.fming.dev/#use-with-ide
250
+ .pdm.toml
251
+
252
+ __pypackages__/
253
+
254
+ # Celery stuff
255
+ celerybeat-schedule
256
+ celerybeat.pid
257
+
258
+ # SageMath parsed files
259
+ *.sage.py
260
+
261
+ # Environments
262
+ .env
263
+ .venv
264
+ env/
265
+ venv/
266
+ ENV/
267
+ env.bak/
268
+ venv.bak/
269
+
270
+ # Spyder project settings
271
+ .spyderproject
272
+ .spyproject
273
+
274
+ # Rope project settings
275
+ .ropeproject
276
+
277
+ # mkdocs documentation
278
+ /site
279
+
280
+ # mypy
281
+ .mypy_cache/
282
+ .dmypy.json
283
+ dmypy.json
284
+
285
+ # Pyre type checker
286
+ .pyre/
287
+
288
+ # pytype static type analyzer
289
+ .pytype/
290
+
291
+ # Cython debug symbols
292
+ cython_debug/
293
+
294
+ # PyCharm
295
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
296
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
297
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
298
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
299
+ #.idea/
README.md CHANGED
@@ -1,13 +1,17 @@
1
  ---
2
  title: MCP-Client SyntheticText Similarity
3
- emoji: 📉
4
- colorFrom: yellow
5
- colorTo: green
6
  sdk: gradio
7
- sdk_version: 5.42.0
8
  app_file: app.py
9
- pinned: false
10
  license: mit
 
 
 
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: MCP-Client SyntheticText Similarity
3
+ emoji:
4
+ colorFrom: green
5
+ colorTo: gray
6
  sdk: gradio
7
+ sdk_version: 5.33.1
8
  app_file: app.py
9
+ pinned: true
10
  license: mit
11
+ tags:
12
+ - MCP
13
+ - MCP-Client
14
+ - SL-Sprout
15
  ---
16
 
17
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #########################################################################
2
+ # Copyright (C) #
3
+ # 2025-June Sen Li (Sen.Li.Sprout@gmail.com) #
4
+ # Permission given to modify the code only for Non-Profit Research #
5
+ # as long as you keep this declaration at the top #
6
+ #########################################################################
7
+ import os
8
+
9
+ import gradio as gr
10
+ import smolagents
11
+
12
+ # Launch the interface and MCP server
13
+ if __name__ == "__main__":
14
+ print(f"os.getcwd() = {os.getcwd()}")
15
+ os.system(f"echo ls -al {os.getcwd()} && ls -al {os.getcwd()}")
16
+ os.system(f"echo ls -al /: && ls -al /")
17
+ os.system(f"echo ls -al /home/: && ls -al /home/")
18
+
19
+ dictServerParams_TextSimilarity = {
20
+ "url": "https://allillusion-mcp-server-textsimilarity.hf.space/gradio_api/mcp/sse",
21
+ "transport": "sse",
22
+ } # either HF-Space or Local {"url": "http://localhost:7860/gradio_api/mcp/sse", "transport": ...}
23
+
24
+ try:
25
+ mcpClient_SyntheticText_Similarity = smolagents.mcp_client.MCPClient(dictServerParams_TextSimilarity)
26
+ print(f"type(mcpClient_SyntheticText_Similarity) = {type(mcpClient_SyntheticText_Similarity)}")
27
+
28
+ list_MCPAdaptTools_SyntheticText_Similarity = mcpClient_SyntheticText_Similarity.get_tools()
29
+ print(f"len(list_MCPAdaptTools_SyntheticText_Similarity) = {len(list_MCPAdaptTools_SyntheticText_Similarity)}")
30
+ print(f"list_MCPAdaptTools_SyntheticText_Similarity[0] = {list_MCPAdaptTools_SyntheticText_Similarity[0]}")
31
+
32
+ clientModel_Qwen25_Inference = smolagents.InferenceClientModel(model_id = "Qwen/Qwen2.5-Coder-32B-Instruct")
33
+ print(f"clientModel_Qwen25_Inference.model_id = {clientModel_Qwen25_Inference.model_id}\n")
34
+ print(f"clientModel_Qwen25_Inference.client = {clientModel_Qwen25_Inference.client}")
35
+
36
+ codeAgent_Qwen25_SentimentalAnalysis = smolagents.CodeAgent(tools = list_MCPAdaptTools_SyntheticText_Similarity,
37
+ model = clientModel_Qwen25_Inference)
38
+
39
+ ''' 401 Client Error: Unauthorized for url: https://api-inference.huggingface.co/models/Qwen/Qwen2.5-Coder-32B..
40
+ On the space settings, go to Variables and secrets, and create a new secret named HF_TOKEN
41
+ The value of the secret should be your access token
42
+ If you need to create an access token, go to your HF profile page
43
+ On the left menu, go to the access token option, then the Create new token, on the top right
44
+ '''
45
+ str_Description = "A simple MCP-Client, Qwen2.5 Agent calling MCP-Server_TextSimilarity as an MCP tool to Generate Synthetic Text with Similarity." \
46
+ " https://huggingface.co/spaces/AllIllusion/MCP-Server_TextSimilarity" \
47
+ " If you see 'Error', that's because my account has exceeded the monthly included credits for Inference Providers (Qwen2.5)."
48
+
49
+ def func_genSyntheticText_Similarity(str_RealText):
50
+ strTask_Message = f'''You are learning and practicing synthetic note writing. Your task is to generate synthetic notes, modeled on real note structure and content. You will learn from a pseudonymized note to guide your language, structure, and reasoning.
51
+
52
+ To avoid generating synthetic text from nowhere, you have been provided with pseudonymized, real note for use as a learning example.
53
+
54
+ ### Learning Example (quoted by <Example>...</Example>):
55
+
56
+ <Example>{str_RealText}</Example>
57
+
58
+ ### Instructions:
59
+ 1. Study the provided learning example.
60
+ 2. Generate a synthetic note that:
61
+ - Mimics the sentence types and key characteristic distribution of the selected example.
62
+ - Follows a common sense plausible structure and progression.
63
+ 3. Compare the similarity using the tool MCP-Server_TextSimilarity, between the provided Learning Example and your generated synthetic text.
64
+ 4. Do not return anything other than the synthetic text and the direct output of the tool MCP-Server_TextSimilarity.
65
+ 5. Return the synthetic note, and append the direct output of the tool MCP-Server_TextSimilarity at the end of the output.
66
+ 6. Once you get the direct output of the tool MCP-Server_TextSimilarity, stop processing, no more steps, return immediately the final synthetic text and direct output of the tool MCP-Server_TextSimilarity.
67
+ 7. Note, don't forget the append the direct output of the tool MCP-Server_TextSimilarity at the end of the output.
68
+ '''
69
+ print(f"strTask_Message = {strTask_Message}")
70
+
71
+ return str(codeAgent_Qwen25_SentimentalAnalysis.run(strTask_Message))
72
+
73
+
74
+ # 03. Gradio UI elements
75
+ with gr.Blocks(title="MCP-Client: SyntheticText + Tool-Similarity") as grBlocks_SentenceSimilarity__MCP_Server:
76
+ gr.Markdown(str_Description)
77
+
78
+ with gr.Row():
79
+ grTextBox_RealText = gr.Textbox(label="Real Text Input", lines=20,
80
+ placeholder="Put your real text here ...", show_label=True)
81
+ grTextBox_SyntheticText = gr.Textbox(label="Synthetic Text Output with Similarity", lines=20,
82
+ placeholder="Waiting for Real Text Input ...", show_label=True)
83
+
84
+ # Set button functionality
85
+ grTextBox_RealText.change(fn=func_genSyntheticText_Similarity, inputs=grTextBox_RealText, outputs=grTextBox_SyntheticText)
86
+ gr.Button("Translate").click(fn=func_genSyntheticText_Similarity, inputs=grTextBox_RealText, outputs=grTextBox_SyntheticText)
87
+
88
+
89
+ # 04. Launch Gradio MCP server
90
+ grBlocks_SentenceSimilarity__MCP_Server.launch(mcp_server=True, share=True)
91
+
92
+
93
+ finally:
94
+ mcpClient_SyntheticText_Similarity.disconnect()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ smolagents[mcp]
2
+ gradio[mcp]
3
+ mcp