Spaces:
Runtime error
Runtime error
Eddyhzd
commited on
Commit
·
c3b66c1
1
Parent(s):
b25820d
test
Browse files
app.py
CHANGED
|
@@ -1,38 +1,27 @@
|
|
| 1 |
-
import
|
| 2 |
-
from
|
| 3 |
-
import
|
|
|
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
messages = []
|
| 14 |
-
for user_msg, bot_msg in history:
|
| 15 |
-
messages.append({"role": "user", "content": user_msg})
|
| 16 |
-
messages.append({"role": "assistant", "content": bot_msg})
|
| 17 |
-
|
| 18 |
-
messages.append({"role": "user", "content": message})
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
)
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
return history, history
|
| 29 |
-
|
| 30 |
-
with gr.Blocks() as demo:
|
| 31 |
|
| 32 |
-
|
| 33 |
-
chatbot_ui = gr.Chatbot(label="ChatBot")
|
| 34 |
-
msg = gr.Textbox(placeholder="Écrivez un message...")
|
| 35 |
-
|
| 36 |
-
msg.submit(chatbot, [msg, chatbot_ui], [chatbot_ui, chatbot_ui])
|
| 37 |
-
|
| 38 |
-
demo.launch()
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
from mcp.client.session import ClientSession
|
| 3 |
+
from mcp.client.stdio import stdio_client
|
| 4 |
+
from mcp.client.http import http_client
|
| 5 |
|
| 6 |
+
async def main():
|
| 7 |
+
# URL de ton MCP server (d'après ta config JSON)
|
| 8 |
+
mcp_url = "https://hackathoncra-gradio-mcp.hf.space/gradio_api/mcp/"
|
| 9 |
|
| 10 |
+
# Création d'un client HTTP MCP
|
| 11 |
+
async with http_client(mcp_url) as (read, write):
|
| 12 |
+
session = ClientSession(read, write)
|
| 13 |
+
await session.initialize()
|
| 14 |
|
| 15 |
+
# Exemple : lister les outils exposés par le MCP server
|
| 16 |
+
tools = await session.list_tools()
|
| 17 |
+
print("Outils disponibles :", [t.name for t in tools])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
# Exemple : exécuter un outil (si dispo, ex: "predict")
|
| 20 |
+
if tools:
|
| 21 |
+
tool_name = tools[0].name
|
| 22 |
+
print(f"Appel de l'outil: {tool_name}")
|
|
|
|
| 23 |
|
| 24 |
+
result = await session.call_tool(tool_name, arguments={"prompt": "Bonjour MCP !"})
|
| 25 |
+
print("Résultat :", result)
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
asyncio.run(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mcp.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"mcpServers": {
|
| 3 |
+
"gradio": {
|
| 4 |
+
"url": "https://hackathoncra-gradio-mcp.hf.space/gradio_api/mcp/"
|
| 5 |
+
}
|
| 6 |
+
}
|
| 7 |
+
}
|