Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
import os
|
| 3 |
-
|
| 4 |
-
from smolagents import InferenceClientModel, CodeAgent, MCPClient
|
| 5 |
-
|
| 6 |
-
|
| 7 |
try:
|
| 8 |
mcp_client = MCPClient(
|
| 9 |
{"url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse"}
|
|
@@ -11,7 +6,11 @@ try:
|
|
| 11 |
tools = mcp_client.get_tools()
|
| 12 |
|
| 13 |
model = InferenceClientModel(token=os.getenv("HUGGINGFACE_API_TOKEN"))
|
| 14 |
-
agent = CodeAgent(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
demo = gr.ChatInterface(
|
| 17 |
fn=lambda message, history: str(agent.run(message)),
|
|
@@ -22,5 +21,8 @@ try:
|
|
| 22 |
)
|
| 23 |
|
| 24 |
demo.launch()
|
|
|
|
|
|
|
| 25 |
finally:
|
| 26 |
-
mcp_client
|
|
|
|
|
|
| 1 |
+
mcp_client = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
try:
|
| 3 |
mcp_client = MCPClient(
|
| 4 |
{"url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse"}
|
|
|
|
| 6 |
tools = mcp_client.get_tools()
|
| 7 |
|
| 8 |
model = InferenceClientModel(token=os.getenv("HUGGINGFACE_API_TOKEN"))
|
| 9 |
+
agent = CodeAgent(
|
| 10 |
+
tools=[*tools],
|
| 11 |
+
model=model,
|
| 12 |
+
additional_authorized_imports=["json", "ast", "urllib", "base64"]
|
| 13 |
+
)
|
| 14 |
|
| 15 |
demo = gr.ChatInterface(
|
| 16 |
fn=lambda message, history: str(agent.run(message)),
|
|
|
|
| 21 |
)
|
| 22 |
|
| 23 |
demo.launch()
|
| 24 |
+
except Exception as e:
|
| 25 |
+
print("❌ MCP connection failed:", e)
|
| 26 |
finally:
|
| 27 |
+
if mcp_client:
|
| 28 |
+
mcp_client.disconnect()
|