Eddyhzd commited on
Commit
c3b66c1
·
1 Parent(s): b25820d
Files changed (2) hide show
  1. app.py +21 -32
  2. mcp.json +7 -0
app.py CHANGED
@@ -1,38 +1,27 @@
1
- import gradio as gr
2
- from openai import OpenAI
3
- import os
 
4
 
5
- cle_api = os.environ.get("CLE_API_MISTRAL")
 
 
6
 
7
- # Initialisation du client Mistral (API compatible OpenAI)
8
- client = OpenAI(api_key=cle_api, base_url="https://api.mistral.ai/v1")
 
 
9
 
10
- # Chatbot : simple écho Fonction chatbot reliée à Mistral
11
- def chatbot(message, history):
12
- # Préparer l’historique dans le format de Mistral
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
- # Appel API Mistral
21
- response = client.chat.completions.create(
22
- model="mistral-small-latest",
23
- messages=messages
24
- )
25
 
26
- bot_reply = response.choices[0].message.content.strip()
27
- history.append(("Vous: " + message, "Bot: " + bot_reply))
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
+ }