Spaces:
Sleeping
Sleeping
oualid.choukrallah.tcmlabs commited on
Commit ·
835dd24
1
Parent(s): 33ff171
fix: hf token dependency
Browse files
app.py
CHANGED
|
@@ -1,23 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
from dotenv import load_dotenv
|
| 4 |
|
| 5 |
-
from
|
| 6 |
-
|
| 7 |
|
| 8 |
-
# Load environment variables from .env file
|
| 9 |
-
load_dotenv()
|
| 10 |
try :
|
| 11 |
mcp_client = MCPClient(
|
| 12 |
{"url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse"} # This is the MCP Client we created in the previous section
|
| 13 |
)
|
| 14 |
tools = mcp_client.get_tools()
|
| 15 |
|
| 16 |
-
model = InferenceClientModel(token=os.getenv("
|
| 17 |
agent = CodeAgent(tools=[*tools], model=model)
|
| 18 |
|
| 19 |
demo = gr.ChatInterface(
|
| 20 |
-
fn=lambda message, history: str(agent.run(message)),
|
| 21 |
type="messages",
|
| 22 |
examples=["Prime factorization of 68"],
|
| 23 |
title="Agent with MCP Tools",
|
|
@@ -25,6 +22,6 @@ try :
|
|
| 25 |
)
|
| 26 |
|
| 27 |
demo.launch()
|
| 28 |
-
|
| 29 |
finally:
|
| 30 |
mcp_client.disconnect()
|
|
|
|
| 1 |
import gradio as gr
|
| 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"} # This is the MCP Client we created in the previous section
|
| 10 |
)
|
| 11 |
tools = mcp_client.get_tools()
|
| 12 |
|
| 13 |
+
model = InferenceClientModel(token=os.getenv("HUGGINGFACE_API_TOKEN"))
|
| 14 |
agent = CodeAgent(tools=[*tools], model=model)
|
| 15 |
|
| 16 |
demo = gr.ChatInterface(
|
| 17 |
+
fn=lambda message, history: str(agent.run(message)),
|
| 18 |
type="messages",
|
| 19 |
examples=["Prime factorization of 68"],
|
| 20 |
title="Agent with MCP Tools",
|
|
|
|
| 22 |
)
|
| 23 |
|
| 24 |
demo.launch()
|
| 25 |
+
|
| 26 |
finally:
|
| 27 |
mcp_client.disconnect()
|