AllIllusion commited on
Commit
a4518a5
Β·
1 Parent(s): 6d65cdb

Test ClinicalBERT

Browse files
Files changed (4) hide show
  1. .gitignore +299 -0
  2. README.md +8 -6
  3. app.py +65 -0
  4. requirements.txt +5 -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,15 @@
1
  ---
2
- title: MCP-Server TextSimilarity ClinicalBERT
3
- emoji: 🐒
4
- colorFrom: red
5
- colorTo: pink
6
  sdk: gradio
7
- sdk_version: 5.44.0
8
  app_file: app.py
9
  pinned: false
10
- license: apache-2.0
 
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: MCP-Server Clinical TextSimilarity
3
+ emoji: 🌍
4
+ colorFrom: purple
5
+ colorTo: green
6
  sdk: gradio
7
+ sdk_version: 5.33.1
8
  app_file: app.py
9
  pinned: false
10
+ tags:
11
+ - tool
12
+ - SL-Sprout
13
  ---
14
 
15
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #########################################################################
2
+ # Copyright (C) #
3
+ # 2025-June Sen Li ([email protected]) #
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 huggingface_hub
11
+ import sentence_transformers
12
+
13
+
14
+ # ----------------------------------------------------------------------------------------------------------------------
15
+ def func_ClearInputs(): return "", "", ""
16
+
17
+ def func_sBERT_SimilarityResult(str_Text_1, str_Text_2):
18
+ if not str_Text_1.strip() or not str_Text_2.strip():
19
+ return "Both text inputs must be non-empty."
20
+
21
+ # 01. Load SBERT model (you can choose other pre-trained models too)
22
+ inferenceClient = huggingface_hub.InferenceClient(provider="hf-inference")
23
+
24
+ # 02. Get sentence embeddings
25
+ str_ModelID_sBERT = "medicalai/ClinicalBERT"
26
+ arrEmbedding_Text_1 = inferenceClient.feature_extraction(text=str_Text_1, model=str_ModelID_sBERT)
27
+ arrEmbedding_Text_2 = inferenceClient.feature_extraction(text=str_Text_2, model=str_ModelID_sBERT)
28
+
29
+ # 03. Compute cosine similarity
30
+ tensor_Similarity = sentence_transformers.util.pytorch_cos_sim(arrEmbedding_Text_1, arrEmbedding_Text_2)
31
+ f_Similarity = tensor_Similarity.item()
32
+
33
+ return f"sBERT Similarity Score: {f_Similarity:.4f}"
34
+
35
+ # ----------------------------------------------------------------------------------------------------------------------
36
+ # Launch the interface and MCP server
37
+ if __name__ == "__main__":
38
+ print(f"os.getcwd() = {os.getcwd()}")
39
+ os.system(f"echo ls -al {os.getcwd()} && ls -al {os.getcwd()}")
40
+ os.system(f"echo ls -al /: && ls -al /")
41
+ os.system(f"echo ls -al /home/: && ls -al /home/")
42
+
43
+ # 03. Gradio UI elements
44
+ with gr.Blocks() as grBlocks_SentenceSimilarity__MCP_Server:
45
+ gr.Markdown("# ClinicalBERT for Clinical Text Similarity using HF Inference Server")
46
+ gr.Markdown("This application calculates Similarity Score between two Texts")
47
+
48
+ with gr.Row():
49
+ grTextBox_Input_1 = gr.Textbox(label="Text Panel 1", lines=20)
50
+ grTextBox_Input_2 = gr.Textbox(label="Text Panel 2", lines=20)
51
+
52
+ with gr.Row():
53
+ with gr.Column(scale=1):
54
+ grButton_Clear = gr.Button("Clear")
55
+ grButton_Submit = gr.Button("Submit")
56
+ with gr.Column(scale=3):
57
+ grTextbox_Output = gr.Textbox(label="Similarity Result", interactive=False)
58
+
59
+ # Set button functionality
60
+ grButton_Submit.click(fn=func_sBERT_SimilarityResult, inputs=[grTextBox_Input_1, grTextBox_Input_2], outputs=grTextbox_Output)
61
+ grButton_Clear.click(fn=func_ClearInputs, inputs=[], outputs=[grTextBox_Input_1, grTextBox_Input_2, grTextbox_Output])
62
+
63
+
64
+ # 04. Launch Gradio MCP server
65
+ grBlocks_SentenceSimilarity__MCP_Server.launch(mcp_server=True, share=True)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ huggingface_hub
2
+ sentence_transformers
3
+ smolagents[mcp]
4
+ gradio[mcp]
5
+ mcp