Spaces:
Running
Running
Ali Hmaou
commited on
Commit
·
de198d3
1
Parent(s):
e95a81c
Prepare for migration to MCEPTION
Browse files- requirements.txt +2 -2
- src/mcp_server/playground.py +11 -4
- src/mcp_server/server.py +13 -1
requirements.txt
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
-
gradio
|
| 2 |
mcp>=1.0.0
|
| 3 |
huggingface_hub>=0.26.0
|
| 4 |
python-dotenv>=1.0.0
|
| 5 |
smolagents[mcp]>=1.0.0
|
| 6 |
pandas>=2.0.0
|
| 7 |
requests>=2.31.0
|
| 8 |
-
gradio[mcp]
|
|
|
|
| 1 |
+
gradio==6.0.0
|
| 2 |
mcp>=1.0.0
|
| 3 |
huggingface_hub>=0.26.0
|
| 4 |
python-dotenv>=1.0.0
|
| 5 |
smolagents[mcp]>=1.0.0
|
| 6 |
pandas>=2.0.0
|
| 7 |
requests>=2.31.0
|
| 8 |
+
gradio[mcp]
|
src/mcp_server/playground.py
CHANGED
|
@@ -5,13 +5,23 @@ import re
|
|
| 5 |
import pandas as pd
|
| 6 |
import gradio as gr
|
| 7 |
from contextlib import redirect_stdout
|
| 8 |
-
|
| 9 |
|
| 10 |
def remove_ansi_codes(text):
|
| 11 |
"""Removes ANSI escape codes (colors) from text."""
|
| 12 |
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
|
| 13 |
return ansi_escape.sub('', text)
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
class PlaygroundManager:
|
| 16 |
def __init__(self):
|
| 17 |
self.agent = None
|
|
@@ -21,9 +31,6 @@ class PlaygroundManager:
|
|
| 21 |
def load_mcp_tools(self, mcp_url: str):
|
| 22 |
"""Connects the MCP client to the given URL and loads tools."""
|
| 23 |
try:
|
| 24 |
-
# Lazy import to avoid async loop issues at startup
|
| 25 |
-
from smolagents import InferenceClientModel, CodeAgent, MCPClient
|
| 26 |
-
|
| 27 |
# Cleanup old client
|
| 28 |
if self.mcp_client:
|
| 29 |
# self.mcp_client.disconnect() # If method exists
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
import gradio as gr
|
| 7 |
from contextlib import redirect_stdout
|
| 8 |
+
from smolagents import InferenceClientModel, CodeAgent, Tool
|
| 9 |
|
| 10 |
def remove_ansi_codes(text):
|
| 11 |
"""Removes ANSI escape codes (colors) from text."""
|
| 12 |
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
|
| 13 |
return ansi_escape.sub('', text)
|
| 14 |
|
| 15 |
+
# Note: MCPClient might not be directly exposed by smolagents in all versions.
|
| 16 |
+
# If import fails, a different approach or version check might be needed.
|
| 17 |
+
# User provided `from smolagents import ..., MCPClient`, so we follow this path.
|
| 18 |
+
try:
|
| 19 |
+
from smolagents import MCPClient
|
| 20 |
+
except ImportError:
|
| 21 |
+
# Fallback or mock if MCPClient is not yet in the installed version
|
| 22 |
+
# Assuming it's good as requested by user for now
|
| 23 |
+
MCPClient = None
|
| 24 |
+
|
| 25 |
class PlaygroundManager:
|
| 26 |
def __init__(self):
|
| 27 |
self.agent = None
|
|
|
|
| 31 |
def load_mcp_tools(self, mcp_url: str):
|
| 32 |
"""Connects the MCP client to the given URL and loads tools."""
|
| 33 |
try:
|
|
|
|
|
|
|
|
|
|
| 34 |
# Cleanup old client
|
| 35 |
if self.mcp_client:
|
| 36 |
# self.mcp_client.disconnect() # If method exists
|
src/mcp_server/server.py
CHANGED
|
@@ -296,10 +296,22 @@ with gr.Blocks(title="MCePtion") as demo:
|
|
| 296 |
|
| 297 |
with gr.Tab("0. Setup & How-to"):
|
| 298 |
gr.Markdown("## Global Configuration")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
with gr.Row():
|
| 300 |
hf_user_profile = gr.Textbox(
|
| 301 |
label="HF User Profile / Namespace",
|
| 302 |
-
value=
|
| 303 |
placeholder="e.g. alihmaou",
|
| 304 |
info="Your default Hugging Face username or organization."
|
| 305 |
)
|
|
|
|
| 296 |
|
| 297 |
with gr.Tab("0. Setup & How-to"):
|
| 298 |
gr.Markdown("## Global Configuration")
|
| 299 |
+
|
| 300 |
+
# Détermination de l'utilisateur par défaut
|
| 301 |
+
# Priorité : HF_USER > SPACE_AUTHOR_NAME > SPACE_ID > vide
|
| 302 |
+
_default_user = os.environ.get("HF_USER")
|
| 303 |
+
if not _default_user:
|
| 304 |
+
_default_user = os.environ.get("SPACE_AUTHOR_NAME")
|
| 305 |
+
if not _default_user and os.environ.get("SPACE_ID"):
|
| 306 |
+
try:
|
| 307 |
+
_default_user = os.environ.get("SPACE_ID").split("/")[0]
|
| 308 |
+
except:
|
| 309 |
+
pass
|
| 310 |
+
|
| 311 |
with gr.Row():
|
| 312 |
hf_user_profile = gr.Textbox(
|
| 313 |
label="HF User Profile / Namespace",
|
| 314 |
+
value=_default_user or "",
|
| 315 |
placeholder="e.g. alihmaou",
|
| 316 |
info="Your default Hugging Face username or organization."
|
| 317 |
)
|