mgbam commited on
Commit
bb5773b
·
verified ·
1 Parent(s): 452992b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -1,4 +1,11 @@
 
 
 
 
 
1
  mcp_client = None
 
 
2
  try:
3
  mcp_client = MCPClient(
4
  {"url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse"}
@@ -20,9 +27,19 @@ try:
20
  description="This is a simple agent that uses MCP tools to answer questions.",
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()
 
 
 
 
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(
11
  {"url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse"}
 
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()