Denys Kanunnikov commited on
Commit
1bcfc6a
·
2 Parent(s): 776e7c0 6c0a877

update logic v1.1

Browse files
.gitignore ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ src/__pycache__/
6
+ src/**/__pycache__/
7
+
8
+ # C extensions
9
+ *.so
10
+
11
+ # Distribution / packaging
12
+ .Python
13
+ build/
14
+ develop-eggs/
15
+ dist/
16
+ downloads/
17
+ eggs/
18
+ .eggs/
19
+ lib/
20
+ lib64/
21
+ parts/
22
+ sdist/
23
+ var/
24
+ wheels/
25
+ share/python-wheels/
26
+ *.egg-info/
27
+ .installed.cfg
28
+ *.egg
29
+ MANIFEST
30
+
31
+ # PyInstaller
32
+ # Usually these files are written by a python script from a template
33
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
34
+ *.manifest
35
+ *.spec
36
+
37
+ # Installer logs
38
+ pip-log.txt
39
+ pip-delete-this-directory.txt
40
+
41
+ # Unit test / coverage reports
42
+ htmlcov/
43
+ .tox/
44
+ .nox/
45
+ .coverage
46
+ .coverage.*
47
+ .cache
48
+ nosetests.xml
49
+ coverage.xml
50
+ *.cover
51
+ *.py,cover
52
+ .hypothesis/
53
+ .pytest_cache/
54
+ cover/
55
+
56
+ # Translations
57
+ *.mo
58
+ *.pot
59
+
60
+ # Django stuff:
61
+ *.log
62
+ local_settings.py
63
+ db.sqlite3
64
+ db.sqlite3-journal
65
+
66
+ # Flask stuff:
67
+ instance/
68
+ .webassets-cache
69
+
70
+ # Scrapy stuff:
71
+ .scrapy
72
+
73
+ # Sphinx documentation
74
+ docs/_build/
75
+
76
+ # PyBuilder
77
+ .pybuilder/
78
+ target/
79
+
80
+ # Jupyter Notebook
81
+ .ipynb_checkpoints
82
+
83
+ # IPython
84
+ profile_default/
85
+ ipython_config.py
86
+
87
+ # pyenv
88
+ # For a library or package, you might want to ignore these files since the code is
89
+ # intended to run in multiple environments; otherwise, check them in:
90
+ # .python-version
91
+
92
+ # pipenv
93
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
94
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
95
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
96
+ # install all needed dependencies.
97
+ #Pipfile.lock
98
+
99
+ # poetry
100
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
101
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
102
+ # commonly ignored for libraries.
103
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
104
+ #poetry.lock
105
+
106
+ # pdm
107
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
108
+ #pdm.lock
109
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
110
+ # in version control.
111
+ # https://pdm.fming.dev/#use-with-ide
112
+ .pdm.toml
113
+
114
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
+ __pypackages__/
116
+
117
+ # Celery stuff
118
+ celerybeat-schedule
119
+ celerybeat.pid
120
+
121
+ # SageMath parsed files
122
+ *.sage.py
123
+
124
+ # Environments
125
+ .env
126
+ .venv
127
+ env/
128
+ venv/
129
+ ENV/
130
+ env.bak/
131
+ venv.bak/
132
+
133
+ # Spyder project settings
134
+ .spyderproject
135
+ .spyproject
136
+
137
+ # Rope project settings
138
+ .ropeproject
139
+
140
+ # mkdocs documentation
141
+ /site
142
+
143
+ # mypy
144
+ .mypy_cache/
145
+ .dmypy.json
146
+ dmypy.json
147
+
148
+ # Pyre type checker
149
+ .pyre/
150
+
151
+ # pytype static type analyzer
152
+ .pytype/
153
+
154
+ # Cython debug symbols
155
+ cython_debug/
156
+
157
+ # PyCharm
158
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
+ # be added to the global gitignore or merged into this project gitignore. For a PyCharm
160
+ # project, it is recommended to include the following:
161
+ .idea/
162
+ *.iws
163
+ *.iml
164
+ *.ipr
165
+
166
+ # VS Code
167
+ .vscode/
168
+
169
+ # macOS
170
+ .DS_Store
171
+
172
+ # Windows
173
+ Thumbs.db
174
+ ehthumbs.db
175
+ Desktop.ini
176
+
177
+ # Project-specific
178
+ # Virtual environment (if created locally)
179
+ venv/
180
+ .venv/
181
+
182
+ # Local configuration files
183
+ config.local.py
184
+ .env.local
README.md CHANGED
@@ -1,10 +1,18 @@
1
  ---
 
2
  title: Sentiment Analysis Server
 
 
 
3
  emoji: 🎭
4
  colorFrom: blue
5
  colorTo: purple
6
  sdk: gradio
 
7
  sdk_version: 5.33.2
 
 
 
8
  app_file: app.py
9
  pinned: false
10
  ---
@@ -46,23 +54,36 @@ cd mcp-sentiment
46
 
47
  ### 2. Install Dependencies
48
  ```bash
 
49
  python3 -m pip install -r requirements.txt
 
 
 
50
  ```
51
 
52
  ### 3. Download TextBlob Corpora (Optional)
53
  ```bash
 
54
  python3 -c "import nltk; nltk.download('punkt'); nltk.download('brown')"
 
 
 
55
  ```
56
 
57
  ## 🎯 Quick Start
58
 
59
  ### Run Tests
60
  ```bash
 
61
  python3 app.py --mode test
 
 
 
62
  ```
63
 
64
  ### Launch Web Interface
65
  ```bash
 
66
  python3 app.py --mode gradio
67
  ```
68
  Visit `http://localhost:7860` to access the web interface.
@@ -76,11 +97,24 @@ Enables both web interface and MCP server functionality in a single Gradio app.
76
  ### Start MCP Server
77
  ```bash
78
  python3 app.py --mode mcp
 
 
 
 
 
 
 
 
 
79
  ```
80
 
81
  ### Combined Mode (Default)
82
  ```bash
 
83
  python3 app.py --mode combined
 
 
 
84
  ```
85
  Runs both MCP server and Gradio interface simultaneously.
86
 
@@ -90,6 +124,7 @@ Runs both MCP server and Gradio interface simultaneously.
90
 
91
  ```bash
92
  # Different execution modes
 
93
  python3 app.py --mode mcp # MCP server only
94
  python3 app.py --mode gradio # Web interface only
95
  python3 app.py --mode combined # Both services (default)
@@ -103,6 +138,20 @@ python3 app.py --mode gradio --mcp-server # Enable MCP server in Gradio
103
 
104
  # Logging control
105
  python3 app.py --log-level DEBUG # Detailed logging
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  ```
107
 
108
  ### Python API Usage
@@ -164,6 +213,7 @@ The server provides these MCP tools:
164
  }
165
  ```
166
 
 
167
  ## 🔗 Gradio MCP Server Integration
168
 
169
  The Gradio web interface can also serve as an MCP server, providing API endpoints that correspond to each sentiment analysis function. This allows the same interface to serve both human users through the web UI and AI models through the MCP protocol.
@@ -216,6 +266,8 @@ curl -X POST http://localhost:7860/api/health_check \
216
  -d '{}'
217
  ```
218
 
 
 
219
  ## 🏗️ Architecture
220
 
221
  ### Project Structure
@@ -253,7 +305,10 @@ mcp-sentiment/
253
  # Optional configuration
254
  export MCP_LOG_LEVEL=INFO
255
  export GRADIO_SERVER_PORT=7860
 
256
  export GRADIO_MCP_SERVER=true # Enable MCP server in Gradio interface
 
 
257
  export TRANSFORMERS_CACHE=/path/to/cache
258
  ```
259
 
 
1
  ---
2
+ <<<<<<< HEAD
3
  title: Sentiment Analysis Server
4
+ =======
5
+ title: MCP Sentiment Analysis Server
6
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
7
  emoji: 🎭
8
  colorFrom: blue
9
  colorTo: purple
10
  sdk: gradio
11
+ <<<<<<< HEAD
12
  sdk_version: 5.33.2
13
+ =======
14
+ sdk_version: "4.44.0"
15
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
16
  app_file: app.py
17
  pinned: false
18
  ---
 
54
 
55
  ### 2. Install Dependencies
56
  ```bash
57
+ <<<<<<< HEAD
58
  python3 -m pip install -r requirements.txt
59
+ =======
60
+ pip install -r requirements.txt
61
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
62
  ```
63
 
64
  ### 3. Download TextBlob Corpora (Optional)
65
  ```bash
66
+ <<<<<<< HEAD
67
  python3 -c "import nltk; nltk.download('punkt'); nltk.download('brown')"
68
+ =======
69
+ python -c "import nltk; nltk.download('punkt'); nltk.download('brown')"
70
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
71
  ```
72
 
73
  ## 🎯 Quick Start
74
 
75
  ### Run Tests
76
  ```bash
77
+ <<<<<<< HEAD
78
  python3 app.py --mode test
79
+ =======
80
+ python app.py --mode test
81
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
82
  ```
83
 
84
  ### Launch Web Interface
85
  ```bash
86
+ <<<<<<< HEAD
87
  python3 app.py --mode gradio
88
  ```
89
  Visit `http://localhost:7860` to access the web interface.
 
97
  ### Start MCP Server
98
  ```bash
99
  python3 app.py --mode mcp
100
+ =======
101
+ python app.py --mode gradio
102
+ ```
103
+ Visit `http://localhost:7860` to access the web interface.
104
+
105
+ ### Start MCP Server
106
+ ```bash
107
+ python app.py --mode mcp
108
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
109
  ```
110
 
111
  ### Combined Mode (Default)
112
  ```bash
113
+ <<<<<<< HEAD
114
  python3 app.py --mode combined
115
+ =======
116
+ python app.py --mode combined
117
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
118
  ```
119
  Runs both MCP server and Gradio interface simultaneously.
120
 
 
124
 
125
  ```bash
126
  # Different execution modes
127
+ <<<<<<< HEAD
128
  python3 app.py --mode mcp # MCP server only
129
  python3 app.py --mode gradio # Web interface only
130
  python3 app.py --mode combined # Both services (default)
 
138
 
139
  # Logging control
140
  python3 app.py --log-level DEBUG # Detailed logging
141
+ =======
142
+ python app.py --mode mcp # MCP server only
143
+ python app.py --mode gradio # Web interface only
144
+ python app.py --mode combined # Both services (default)
145
+ python app.py --mode test # Run functionality tests
146
+
147
+ # Gradio customization
148
+ python app.py --mode gradio --port 8080 # Custom port
149
+ python app.py --mode gradio --share # Enable public sharing
150
+ python app.py --mode gradio --debug # Debug mode
151
+
152
+ # Logging control
153
+ python app.py --log-level DEBUG # Detailed logging
154
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
155
  ```
156
 
157
  ### Python API Usage
 
213
  }
214
  ```
215
 
216
+ <<<<<<< HEAD
217
  ## 🔗 Gradio MCP Server Integration
218
 
219
  The Gradio web interface can also serve as an MCP server, providing API endpoints that correspond to each sentiment analysis function. This allows the same interface to serve both human users through the web UI and AI models through the MCP protocol.
 
266
  -d '{}'
267
  ```
268
 
269
+ =======
270
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
271
  ## 🏗️ Architecture
272
 
273
  ### Project Structure
 
305
  # Optional configuration
306
  export MCP_LOG_LEVEL=INFO
307
  export GRADIO_SERVER_PORT=7860
308
+ <<<<<<< HEAD
309
  export GRADIO_MCP_SERVER=true # Enable MCP server in Gradio interface
310
+ =======
311
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
312
  export TRANSFORMERS_CACHE=/path/to/cache
313
  ```
314
 
app.py CHANGED
@@ -253,10 +253,13 @@ Examples:
253
  python app.py --mode test # Run tests
254
  python app.py --mode gradio --port 8080 # Custom port
255
  python app.py --mode gradio --share # Public sharing
 
256
  python app.py --mode gradio --mcp-server # Gradio with MCP server
257
 
258
  Environment Variables:
259
  GRADIO_MCP_SERVER=true # Enable MCP server in Gradio
 
 
260
  """
261
  )
262
 
@@ -300,12 +303,15 @@ Environment Variables:
300
  help="Enable debug mode"
301
  )
302
 
 
303
  parser.add_argument(
304
  "--mcp-server",
305
  action="store_true",
306
  help="Enable MCP server functionality in Gradio interface"
307
  )
308
 
 
 
309
  return parser.parse_args()
310
 
311
 
@@ -336,8 +342,12 @@ async def main() -> None:
336
  "server_name": args.host,
337
  "server_port": args.port,
338
  "share": args.share,
 
339
  "debug": args.debug,
340
  "mcp_server": args.mcp_server
 
 
 
341
  }
342
  runner.run_gradio_interface(**gradio_kwargs)
343
 
@@ -346,8 +356,12 @@ async def main() -> None:
346
  "server_name": args.host,
347
  "server_port": args.port,
348
  "share": args.share,
 
349
  "debug": args.debug,
350
  "mcp_server": args.mcp_server
 
 
 
351
  }
352
  await runner.run_combined(**gradio_kwargs)
353
 
 
253
  python app.py --mode test # Run tests
254
  python app.py --mode gradio --port 8080 # Custom port
255
  python app.py --mode gradio --share # Public sharing
256
+ <<<<<<< HEAD
257
  python app.py --mode gradio --mcp-server # Gradio with MCP server
258
 
259
  Environment Variables:
260
  GRADIO_MCP_SERVER=true # Enable MCP server in Gradio
261
+ =======
262
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
263
  """
264
  )
265
 
 
303
  help="Enable debug mode"
304
  )
305
 
306
+ <<<<<<< HEAD
307
  parser.add_argument(
308
  "--mcp-server",
309
  action="store_true",
310
  help="Enable MCP server functionality in Gradio interface"
311
  )
312
 
313
+ =======
314
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
315
  return parser.parse_args()
316
 
317
 
 
342
  "server_name": args.host,
343
  "server_port": args.port,
344
  "share": args.share,
345
+ <<<<<<< HEAD
346
  "debug": args.debug,
347
  "mcp_server": args.mcp_server
348
+ =======
349
+ "debug": args.debug
350
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
351
  }
352
  runner.run_gradio_interface(**gradio_kwargs)
353
 
 
356
  "server_name": args.host,
357
  "server_port": args.port,
358
  "share": args.share,
359
+ <<<<<<< HEAD
360
  "debug": args.debug,
361
  "mcp_server": args.mcp_server
362
+ =======
363
+ "debug": args.debug
364
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
365
  }
366
  await runner.run_combined(**gradio_kwargs)
367
 
src/__pycache__/gradio_interface.cpython-312.pyc DELETED
Binary file (33.6 kB)
 
src/gradio_interface.py CHANGED
@@ -9,7 +9,10 @@ real-time analysis, confidence visualization, and history tracking.
9
  import asyncio
10
  import logging
11
  import json
 
12
  import os
 
 
13
  from typing import Dict, Any, List, Tuple, Optional
14
  from datetime import datetime
15
  import pandas as pd
@@ -24,7 +27,10 @@ except ImportError:
24
  logging.error("Gradio not available. Install with: pip install gradio")
25
 
26
  from .sentiment_analyzer import get_analyzer, SentimentResult, SentimentLabel
 
27
  from .tools import list_tools
 
 
28
 
29
 
30
  class SentimentHistory:
@@ -224,10 +230,13 @@ class GradioInterface:
224
  def get_backend_info() -> str:
225
  return asyncio.run(self._get_backend_info_async())
226
 
 
227
  def get_mcp_schema() -> str:
228
  """Get MCP tools schema as JSON."""
229
  return asyncio.run(self._get_mcp_schema_async())
230
 
 
 
231
  # Example texts
232
  examples = [
233
  "I absolutely love this new feature! It's incredible and makes everything so much easier.",
@@ -495,6 +504,7 @@ class GradioInterface:
495
  </div>
496
  """
497
 
 
498
  async def _get_mcp_schema_async(self) -> str:
499
  """Get MCP tools schema as formatted JSON."""
500
  try:
@@ -518,16 +528,21 @@ class GradioInterface:
518
  "error_type": type(e).__name__
519
  }, indent=2)
520
 
 
 
521
  def launch(self, **kwargs) -> None:
522
  if not self.interface:
523
  raise RuntimeError("Interface not initialized")
524
 
 
525
  # Check for MCP server mode from environment variable or parameter
526
  mcp_server_enabled = (
527
  kwargs.get("mcp_server", False) or
528
  os.getenv("GRADIO_MCP_SERVER", "").lower() in ("true", "1", "yes", "on")
529
  )
530
 
 
 
531
  launch_params = {
532
  "server_name": "0.0.0.0",
533
  "server_port": 7860,
@@ -537,6 +552,7 @@ class GradioInterface:
537
  "quiet": False
538
  }
539
 
 
540
  # Add MCP server parameter if enabled
541
  if mcp_server_enabled:
542
  launch_params["mcp_server"] = True
@@ -547,6 +563,11 @@ class GradioInterface:
547
  self.logger.info(f"Launching Gradio interface on {launch_params['server_name']}:{launch_params['server_port']}")
548
  if mcp_server_enabled:
549
  self.logger.info("Gradio interface will also serve as MCP server with API endpoints")
 
 
 
 
 
550
 
551
  try:
552
  self.interface.launch(**launch_params)
 
9
  import asyncio
10
  import logging
11
  import json
12
+ <<<<<<< HEAD
13
  import os
14
+ =======
15
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
16
  from typing import Dict, Any, List, Tuple, Optional
17
  from datetime import datetime
18
  import pandas as pd
 
27
  logging.error("Gradio not available. Install with: pip install gradio")
28
 
29
  from .sentiment_analyzer import get_analyzer, SentimentResult, SentimentLabel
30
+ <<<<<<< HEAD
31
  from .tools import list_tools
32
+ =======
33
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
34
 
35
 
36
  class SentimentHistory:
 
230
  def get_backend_info() -> str:
231
  return asyncio.run(self._get_backend_info_async())
232
 
233
+ <<<<<<< HEAD
234
  def get_mcp_schema() -> str:
235
  """Get MCP tools schema as JSON."""
236
  return asyncio.run(self._get_mcp_schema_async())
237
 
238
+ =======
239
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
240
  # Example texts
241
  examples = [
242
  "I absolutely love this new feature! It's incredible and makes everything so much easier.",
 
504
  </div>
505
  """
506
 
507
+ <<<<<<< HEAD
508
  async def _get_mcp_schema_async(self) -> str:
509
  """Get MCP tools schema as formatted JSON."""
510
  try:
 
528
  "error_type": type(e).__name__
529
  }, indent=2)
530
 
531
+ =======
532
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
533
  def launch(self, **kwargs) -> None:
534
  if not self.interface:
535
  raise RuntimeError("Interface not initialized")
536
 
537
+ <<<<<<< HEAD
538
  # Check for MCP server mode from environment variable or parameter
539
  mcp_server_enabled = (
540
  kwargs.get("mcp_server", False) or
541
  os.getenv("GRADIO_MCP_SERVER", "").lower() in ("true", "1", "yes", "on")
542
  )
543
 
544
+ =======
545
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
546
  launch_params = {
547
  "server_name": "0.0.0.0",
548
  "server_port": 7860,
 
552
  "quiet": False
553
  }
554
 
555
+ <<<<<<< HEAD
556
  # Add MCP server parameter if enabled
557
  if mcp_server_enabled:
558
  launch_params["mcp_server"] = True
 
563
  self.logger.info(f"Launching Gradio interface on {launch_params['server_name']}:{launch_params['server_port']}")
564
  if mcp_server_enabled:
565
  self.logger.info("Gradio interface will also serve as MCP server with API endpoints")
566
+ =======
567
+ launch_params.update(kwargs)
568
+
569
+ self.logger.info(f"Launching Gradio interface on {launch_params['server_name']}:{launch_params['server_port']}")
570
+ >>>>>>> 6c0a877e212b959072c8948b934d212c97a3c597
571
 
572
  try:
573
  self.interface.launch(**launch_params)