Dabococo commited on
Commit
ccee2f7
·
verified ·
1 Parent(s): 8bb3c9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -1,7 +1,3 @@
1
- @app.get("/")
2
- def root():
3
- return {"status": "MCP server actif 🚀", "endpoints": ["/mcp/list_tools", "/mcp/call_tool"]}
4
-
5
  import os
6
  import zipfile
7
  from fastapi import FastAPI
@@ -9,7 +5,7 @@ from fastapi.responses import JSONResponse
9
  import uvicorn
10
 
11
  # 1. Décompression du fichier zip si nécessaire
12
- ZIP_PATH = "MistralHackathonMCP.zip" # adapte le nom à ton fichier zip
13
  EXTRACT_DIR = "app"
14
 
15
  if os.path.exists(ZIP_PATH) and not os.path.exists(EXTRACT_DIR):
@@ -17,9 +13,18 @@ if os.path.exists(ZIP_PATH) and not os.path.exists(EXTRACT_DIR):
17
  zip_ref.extractall(EXTRACT_DIR)
18
  print(f"✅ Décompressé {ZIP_PATH} dans {EXTRACT_DIR}")
19
 
20
- # 2. Lancement de l'app FastAPI (exemple MCP server)
21
  app = FastAPI()
22
 
 
 
 
 
 
 
 
 
 
23
  @app.get("/mcp/list_tools")
24
  def list_tools():
25
  return JSONResponse({
@@ -28,12 +33,13 @@ def list_tools():
28
  ]
29
  })
30
 
 
31
  @app.get("/mcp/call_tool")
32
  def call_tool(name: str):
33
  if name == "hello_world":
34
  return {"result": "Bonjour depuis Hugging Face MCP server 🚀"}
35
  return {"error": "Outil inconnu"}
36
 
37
- # 3. Point d'entrée Hugging Face
38
  if __name__ == "__main__":
39
  uvicorn.run("app:app", host="0.0.0.0", port=7860)
 
 
 
 
 
1
  import os
2
  import zipfile
3
  from fastapi import FastAPI
 
5
  import uvicorn
6
 
7
  # 1. Décompression du fichier zip si nécessaire
8
+ ZIP_PATH = "MistralHackathonMCP.zip" # adapte au vrai nom de ton zip
9
  EXTRACT_DIR = "app"
10
 
11
  if os.path.exists(ZIP_PATH) and not os.path.exists(EXTRACT_DIR):
 
13
  zip_ref.extractall(EXTRACT_DIR)
14
  print(f"✅ Décompressé {ZIP_PATH} dans {EXTRACT_DIR}")
15
 
16
+ # 2. Création de l'application FastAPI
17
  app = FastAPI()
18
 
19
+ # ✅ Route d’accueil (évite le 404 sur "/")
20
+ @app.get("/")
21
+ def root():
22
+ return {
23
+ "status": "MCP server actif 🚀",
24
+ "endpoints": ["/mcp/list_tools", "/mcp/call_tool"]
25
+ }
26
+
27
+ # Exemple d'endpoint MCP "list_tools"
28
  @app.get("/mcp/list_tools")
29
  def list_tools():
30
  return JSONResponse({
 
33
  ]
34
  })
35
 
36
+ # Exemple d'endpoint MCP "call_tool"
37
  @app.get("/mcp/call_tool")
38
  def call_tool(name: str):
39
  if name == "hello_world":
40
  return {"result": "Bonjour depuis Hugging Face MCP server 🚀"}
41
  return {"error": "Outil inconnu"}
42
 
43
+ # 3. Point dentrée Hugging Face
44
  if __name__ == "__main__":
45
  uvicorn.run("app:app", host="0.0.0.0", port=7860)