alihmaou commited on
Commit
df93caa
·
verified ·
1 Parent(s): 548db9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -68
app.py CHANGED
@@ -55,9 +55,7 @@ def reload_tools_from_url(mcp_url_input):
55
  return gr.DataFrame(value=df)
56
 
57
  with gr.Blocks() as demo:
58
-
59
- with gr.Row():
60
- gr.HTML("""
61
  <div style="text-align:center; max-width: 100%; margin-bottom: 20px;">
62
  <h1 style="font-size: 2em; margin-bottom: 0.5em;">
63
  🚀 MCP Explorer – Agents-MCP-Hackathon (June 2025)
@@ -73,74 +71,71 @@ with gr.Blocks() as demo:
73
  </div>
74
  """
75
  )
76
-
77
- with gr.Column(scale=2):
78
- gr.Markdown("""
79
- <div align="center">
80
- <h2>🛠️ Set an MCP server and discover its tools</h2>
81
- </div>
82
- """)
83
- source_selector = gr.Radio(
84
- choices=["Hackathon candidates", "Custom MCP URL"],
85
- label="🔀 Source",
86
- value="Hackathon candidates"
87
- )
88
-
89
- hackathon_dropdown = gr.Dropdown(
90
- label="Select a MCP server from the hackathon organisation",
91
- choices=get_mcp_space_endpoints(),
92
- value=DEFAULT_MCP_URL,
93
- interactive=True,
94
- visible=True
95
- )
96
 
97
- custom_url_input = gr.Textbox(
98
- label="Enter custom MCP server URL",
99
- value="https://agents-mcp-hackathon-mcp-server-demo.hf.space/gradio_api/mcp/sse",
100
- visible=False
101
- )
102
-
103
- def toggle_url_input(source):
104
- return (
105
- gr.update(visible=(source == "Hackathon candidates")),
106
- gr.update(visible=(source == "Custom MCP URL"))
107
- )
108
-
109
- def reload_tools_router(source, dropdown_val, custom_val):
110
- selected_url = dropdown_val if source == "Hackathon candidates" else custom_val
111
- return reload_tools_from_url(selected_url)
112
 
113
- source_selector.change(fn=toggle_url_input, inputs=source_selector, outputs=[hackathon_dropdown, custom_url_input])
114
-
115
- #print("[MCP] Endpoints loaded:", get_mcp_space_endpoints())
116
- tool_table = gr.DataFrame(headers=["Tool name", "Description", "Params"], interactive=False, label="🔧 MCP Tools availables", wrap=True)
117
- reload_btn = gr.Button("🔄 Refresh and set MCP tools list")
118
- reload_btn.click(
119
- fn=reload_tools_router,
120
- inputs=[source_selector, hackathon_dropdown, custom_url_input],
121
- outputs=tool_table
122
- )
123
- hackathon_dropdown.change(
124
- fn=reload_tools_router,
125
- inputs=[source_selector, hackathon_dropdown, custom_url_input],
126
- outputs=tool_table
127
- )
128
- custom_url_input.submit(
129
- fn=reload_tools_router,
130
- inputs=[source_selector, hackathon_dropdown, custom_url_input],
131
- outputs=tool_table
132
- )
133
 
134
- with gr.Column(scale=3):
135
- gr.Markdown("""
136
- <div align="center">
137
- <h2>🔎 Test them with smolagents</h2>
138
- </div>
139
- """)
140
- chatbot = gr.ChatInterface(
141
- fn=lambda message, history: str(agent.run(message)),
142
- type="messages",
143
- )
144
 
145
  demo.launch()
146
 
 
55
  return gr.DataFrame(value=df)
56
 
57
  with gr.Blocks() as demo:
58
+ gr.HTML("""
 
 
59
  <div style="text-align:center; max-width: 100%; margin-bottom: 20px;">
60
  <h1 style="font-size: 2em; margin-bottom: 0.5em;">
61
  🚀 MCP Explorer – Agents-MCP-Hackathon (June 2025)
 
71
  </div>
72
  """
73
  )
74
+ gr.Markdown("""
75
+ <div align="center">
76
+ <h2>🛠️ Set an MCP server and discover its tools</h2>
77
+ </div>
78
+ """)
79
+ source_selector = gr.Radio(
80
+ choices=["Hackathon candidates", "Custom MCP URL"],
81
+ label="🔀 Source",
82
+ value="Hackathon candidates"
83
+ )
84
+
85
+ hackathon_dropdown = gr.Dropdown(
86
+ label="Select a MCP server from the hackathon organisation",
87
+ choices=get_mcp_space_endpoints(),
88
+ value=DEFAULT_MCP_URL,
89
+ interactive=True,
90
+ visible=True
91
+ )
 
 
92
 
93
+ custom_url_input = gr.Textbox(
94
+ label="Enter custom MCP server URL",
95
+ value="https://agents-mcp-hackathon-mcp-server-demo.hf.space/gradio_api/mcp/sse",
96
+ visible=False
97
+ )
98
+
99
+ def toggle_url_input(source):
100
+ return (
101
+ gr.update(visible=(source == "Hackathon candidates")),
102
+ gr.update(visible=(source == "Custom MCP URL"))
103
+ )
104
+
105
+ def reload_tools_router(source, dropdown_val, custom_val):
106
+ selected_url = dropdown_val if source == "Hackathon candidates" else custom_val
107
+ return reload_tools_from_url(selected_url)
108
 
109
+ source_selector.change(fn=toggle_url_input, inputs=source_selector, outputs=[hackathon_dropdown, custom_url_input])
110
+
111
+ #print("[MCP] Endpoints loaded:", get_mcp_space_endpoints())
112
+ tool_table = gr.DataFrame(headers=["Tool name", "Description", "Params"], interactive=False, label="🔧 MCP Tools availables", wrap=True)
113
+ reload_btn = gr.Button("🔄 Refresh and set MCP tools list")
114
+ reload_btn.click(
115
+ fn=reload_tools_router,
116
+ inputs=[source_selector, hackathon_dropdown, custom_url_input],
117
+ outputs=tool_table
118
+ )
119
+ hackathon_dropdown.change(
120
+ fn=reload_tools_router,
121
+ inputs=[source_selector, hackathon_dropdown, custom_url_input],
122
+ outputs=tool_table
123
+ )
124
+ custom_url_input.submit(
125
+ fn=reload_tools_router,
126
+ inputs=[source_selector, hackathon_dropdown, custom_url_input],
127
+ outputs=tool_table
128
+ )
129
 
130
+ gr.Markdown("""
131
+ <div align="center">
132
+ <h2>🔎 Test them with smolagents</h2>
133
+ </div>
134
+ """)
135
+ chatbot = gr.ChatInterface(
136
+ fn=lambda message, history: str(agent.run(message)),
137
+ type="messages",
138
+ )
 
139
 
140
  demo.launch()
141