malek-messaoudii
commited on
Commit
·
c2e9c8f
1
Parent(s):
f186b6f
Update main.py
Browse files
main.py
CHANGED
|
@@ -7,6 +7,7 @@ import shutil
|
|
| 7 |
|
| 8 |
from fastapi import FastAPI
|
| 9 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 10 |
import uvicorn
|
| 11 |
|
| 12 |
# --- Logging ---
|
|
@@ -60,7 +61,7 @@ stance_model_manager = None
|
|
| 60 |
kpa_model_manager = None
|
| 61 |
try:
|
| 62 |
from services.stance_model_manager import stance_model_manager
|
| 63 |
-
from services.label_model_manager import kpa_model_manager #
|
| 64 |
logger.info("✓ Gestionnaires de modèles importés")
|
| 65 |
except ImportError as e:
|
| 66 |
logger.warning(f"⚠ Impossible d'importer les gestionnaires de modèles: {e}")
|
|
@@ -196,9 +197,9 @@ except ImportError as e:
|
|
| 196 |
logger.warning(f"⚠ Routes API principales non trouvées: {e}")
|
| 197 |
# Fallback : Inclure directement les sub-routers si api_router n'existe pas
|
| 198 |
try:
|
| 199 |
-
from routes.label import router as kpa_router
|
| 200 |
app.include_router(kpa_router, prefix="/api/v1/kpa", tags=["KPA"])
|
| 201 |
-
from routes.stance import router as stance_router #
|
| 202 |
app.include_router(stance_router, prefix="/api/v1/stance", tags=["Stance Detection"])
|
| 203 |
logger.info("✓ Routes KPA et Stance chargées en fallback")
|
| 204 |
except ImportError:
|
|
@@ -237,41 +238,14 @@ async def health():
|
|
| 237 |
|
| 238 |
@app.get("/", tags=["Root"])
|
| 239 |
async def root():
|
| 240 |
-
"""Root endpoint with
|
| 241 |
-
|
| 242 |
-
"docs": "/docs",
|
| 243 |
-
"redoc": "/redoc",
|
| 244 |
-
"health": "/health",
|
| 245 |
-
"stt": "/api/v1/stt/",
|
| 246 |
-
"tts": "/api/v1/tts/",
|
| 247 |
-
"voice_chat": "/voice-chat/voice",
|
| 248 |
-
}
|
| 249 |
-
|
| 250 |
-
if MCP_ENABLED:
|
| 251 |
-
endpoints["mcp"] = {
|
| 252 |
-
"health": "/api/v1/mcp/health",
|
| 253 |
-
"tools": "/api/v1/mcp/tools",
|
| 254 |
-
"resources": "/api/v1/mcp/resources",
|
| 255 |
-
"call_tool": "/api/v1/mcp/tools/call"
|
| 256 |
-
}
|
| 257 |
-
|
| 258 |
-
return {
|
| 259 |
-
"message": "NLP Debater API avec support vocal Groq et MCP",
|
| 260 |
-
"version": API_VERSION,
|
| 261 |
-
"endpoints": endpoints,
|
| 262 |
-
"models": {
|
| 263 |
-
"stt": GROQ_STT_MODEL if GROQ_API_KEY else "disabled",
|
| 264 |
-
"tts": GROQ_TTS_MODEL if GROQ_API_KEY else "disabled",
|
| 265 |
-
"chat": GROQ_CHAT_MODEL if GROQ_API_KEY else "disabled",
|
| 266 |
-
"mcp": "enabled" if MCP_ENABLED else "disabled"
|
| 267 |
-
}
|
| 268 |
-
}
|
| 269 |
|
| 270 |
# --- Error handlers ---
|
| 271 |
@app.exception_handler(404)
|
| 272 |
async def not_found_handler(request, exc):
|
| 273 |
endpoints = {
|
| 274 |
-
"GET /": "
|
| 275 |
"GET /health": "Health check",
|
| 276 |
"POST /api/v1/stt/": "Speech to text",
|
| 277 |
"POST /api/v1/tts/": "Text to speech",
|
|
|
|
| 7 |
|
| 8 |
from fastapi import FastAPI
|
| 9 |
from fastapi.middleware.cors import CORSMiddleware
|
| 10 |
+
from fastapi.responses import RedirectResponse
|
| 11 |
import uvicorn
|
| 12 |
|
| 13 |
# --- Logging ---
|
|
|
|
| 61 |
kpa_model_manager = None
|
| 62 |
try:
|
| 63 |
from services.stance_model_manager import stance_model_manager
|
| 64 |
+
from services.label_model_manager import kpa_model_manager # Corrigé: import depuis kpa_model_manager.py
|
| 65 |
logger.info("✓ Gestionnaires de modèles importés")
|
| 66 |
except ImportError as e:
|
| 67 |
logger.warning(f"⚠ Impossible d'importer les gestionnaires de modèles: {e}")
|
|
|
|
| 197 |
logger.warning(f"⚠ Routes API principales non trouvées: {e}")
|
| 198 |
# Fallback : Inclure directement les sub-routers si api_router n'existe pas
|
| 199 |
try:
|
| 200 |
+
from routes.label import router as kpa_router # Corrigé: assumant routes.kpa_routes.py
|
| 201 |
app.include_router(kpa_router, prefix="/api/v1/kpa", tags=["KPA"])
|
| 202 |
+
from routes.stance import router as stance_router # Corrigé: assumant routes.stance_routes.py
|
| 203 |
app.include_router(stance_router, prefix="/api/v1/stance", tags=["Stance Detection"])
|
| 204 |
logger.info("✓ Routes KPA et Stance chargées en fallback")
|
| 205 |
except ImportError:
|
|
|
|
| 238 |
|
| 239 |
@app.get("/", tags=["Root"])
|
| 240 |
async def root():
|
| 241 |
+
"""Root endpoint with redirect to Swagger UI"""
|
| 242 |
+
return RedirectResponse(url="/docs") # Modifié: Redirige auto vers Swagger pour interface interactive
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
|
| 244 |
# --- Error handlers ---
|
| 245 |
@app.exception_handler(404)
|
| 246 |
async def not_found_handler(request, exc):
|
| 247 |
endpoints = {
|
| 248 |
+
"GET /": "Redirige vers /docs (Swagger UI)",
|
| 249 |
"GET /health": "Health check",
|
| 250 |
"POST /api/v1/stt/": "Speech to text",
|
| 251 |
"POST /api/v1/tts/": "Text to speech",
|