Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from app import predire_ticket, nettoyer_texte_francais # Importé depuis app.py | |
| # Initialisation de l'API | |
| app = FastAPI(title="GDM Ticket Classifier API") | |
| # Définition du format de donnée attendu (JSON) | |
| class TicketInput(BaseModel): | |
| objet: str | |
| description: str | |
| def home(): | |
| return {"message": "API GDM opérationnelle. Utilisez l'endpoint /predict en POST."} | |
| def health_check(): | |
| from app import MODELE, MTTR_MOYENS | |
| return { | |
| "status": "healthy" if MODELE is not None else "unhealthy", | |
| "modele_charge": MODELE is not None, | |
| "version": "1.0.0", | |
| "mttr_poles_count": len(MTTR_MOYENS) if MTTR_MOYENS is not None else 0 | |
| } | |
| def api_predict(ticket: TicketInput): | |
| # Sécurité : Si le modèle n'est pas chargé, on renvoie une erreur propre | |
| from app import MODELE, MTTR_MOYENS | |
| if MODELE is None: | |
| return {"error": "Le modèle n'est pas chargé. Vérifiez les fichiers .pkl"} | |
| # Nettoyage avancé du texte français pour cohérence avec l'app Streamlit | |
| obj = nettoyer_texte_francais(str(ticket.objet)) | |
| desc = nettoyer_texte_francais(str(ticket.description)) | |
| categorie, mttr, confiance = predire_ticket(obj, desc) | |
| return { | |
| "application_impactee": str(categorie), | |
| "temps_resolution_estime_h": float(mttr) if mttr is not None else 0.0, | |
| "score_confiance": round(float(confiance), 4) | |
| } |