alihmaou commited on
Commit
0e2044b
·
verified ·
1 Parent(s): df93caa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -67
app.py CHANGED
@@ -56,11 +56,10 @@ def reload_tools_from_url(mcp_url_input):
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)
62
  </h1>
63
- <p style="font-size: 1em; line-height: 1.5em; margin: 0 auto; max-width: 600px;">
64
  🔍 Query any MCP-compatible endpoint, 🛠️ browse available tools in a clean table view, and 🤖 test real-time interactions using a <code>smolagent</code> powered by <code>HuggingFace</code>.<br/>
65
  Perfect for 🧪 exploring fellow participants’ tools or 🧰 debugging your own MCP server during the event!<br/>
66
  🍒 As a cherry on the cake, the list of the tools developed for the hackathon will be updated here from time to time (see <code>src/bonus.py</code>):<br/>
@@ -68,74 +67,75 @@ with gr.Blocks() as demo:
68
  Ready to use hackathon MCP tools list
69
  </a>
70
  </p>
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
 
 
56
 
57
  with gr.Blocks() as demo:
58
  gr.HTML("""
59
+ <h1 style="text-align:center; font-size: 2em; margin-bottom: 0.5em;">
 
60
  🚀 MCP Explorer – Agents-MCP-Hackathon (June 2025)
61
  </h1>
62
+ <p style="text-align:center; font-size: 1em; line-height: 1.5em; margin: 0 auto; max-width: 600px;">
63
  🔍 Query any MCP-compatible endpoint, 🛠️ browse available tools in a clean table view, and 🤖 test real-time interactions using a <code>smolagent</code> powered by <code>HuggingFace</code>.<br/>
64
  Perfect for 🧪 exploring fellow participants’ tools or 🧰 debugging your own MCP server during the event!<br/>
65
  🍒 As a cherry on the cake, the list of the tools developed for the hackathon will be updated here from time to time (see <code>src/bonus.py</code>):<br/>
 
67
  Ready to use hackathon MCP tools list
68
  </a>
69
  </p>
 
70
  """
71
  )
72
+ with gr.Row():
73
+ with gr.Column():
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
+ with gr.Column():
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