mgbam commited on
Commit
6e69305
·
verified ·
1 Parent(s): bb5773b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -24
app.py CHANGED
@@ -1,10 +1,8 @@
1
  import gradio as gr
2
  import os
3
- from smolagents import InferenceClientModel, CodeAgent
4
- from smolagents.mcp_client import MCPClient # ✅ fixed import
5
 
6
- mcp_client = None
7
- demo = None
8
 
9
  try:
10
  mcp_client = MCPClient(
@@ -13,11 +11,7 @@ try:
13
  tools = mcp_client.get_tools()
14
 
15
  model = InferenceClientModel(token=os.getenv("HUGGINGFACE_API_TOKEN"))
16
- agent = CodeAgent(
17
- tools=[*tools],
18
- model=model,
19
- additional_authorized_imports=["json", "ast", "urllib", "base64"]
20
- )
21
 
22
  demo = gr.ChatInterface(
23
  fn=lambda message, history: str(agent.run(message)),
@@ -27,19 +21,6 @@ try:
27
  description="This is a simple agent that uses MCP tools to answer questions.",
28
  )
29
 
30
- except Exception as e:
31
- print("❌ MCP connection failed:", e)
32
- # Fallback UI so Hugging Face Space still runs
33
- demo = gr.Interface(
34
- fn=lambda text: f"MCP unavailable. Echo: {text}",
35
- inputs="text",
36
- outputs="text",
37
- title="Fallback Mode",
38
- description="MCP server not reachable. Running in fallback mode."
39
- )
40
- finally:
41
- if mcp_client:
42
- mcp_client.disconnect()
43
-
44
- if demo:
45
  demo.launch()
 
 
 
1
  import gradio as gr
2
  import os
 
 
3
 
4
+ from smolagents import InferenceClientModel, CodeAgent, MCPClient
5
+
6
 
7
  try:
8
  mcp_client = MCPClient(
 
11
  tools = mcp_client.get_tools()
12
 
13
  model = InferenceClientModel(token=os.getenv("HUGGINGFACE_API_TOKEN"))
14
+ agent = CodeAgent(tools=[*tools], model=model, additional_authorized_imports=["json", "ast", "urllib", "base64"])
 
 
 
 
15
 
16
  demo = gr.ChatInterface(
17
  fn=lambda message, history: str(agent.run(message)),
 
21
  description="This is a simple agent that uses MCP tools to answer questions.",
22
  )
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  demo.launch()
25
+ finally:
26
+ mcp_client.disconnect()