ASI-Engineer commited on
Commit
1abe1ea
·
verified ·
1 Parent(s): 3fb179e

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +285 -52
  2. README_HF.md +43 -10
README.md CHANGED
@@ -1,73 +1,306 @@
1
- ---
2
- title: Employee Turnover Prediction API
3
- emoji: 👔
4
- colorFrom: blue
5
- colorTo: purple
6
- sdk: docker
7
- pinned: true
8
- license: mit
9
- app_port: 7860
10
- ---
11
-
12
- # Employee Turnover Prediction API 🚀
13
-
14
- API de prédiction du turnover des employés avec XGBoost + SMOTE.
15
-
16
- ## 🎯 Fonctionnalités
17
-
18
- - ✅ Prédiction de turnover (0 = reste, 1 = part)
19
- - 📦 **Nouveau** : Endpoint batch pour traiter vos fichiers CSV directement
20
- - 📊 Probabilités et niveau de risque (Low/Medium/High)
21
- - 🔐 Authentification API Key
22
- - 📝 Logs structurés JSON
23
- - 🛡️ Rate limiting (20 req/min)
24
- - 📚 Documentation OpenAPI/Swagger
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- ## 🔗 Endpoints
 
 
 
27
 
28
- | Endpoint | Description |
29
- |----------|-------------|
30
- | `/docs` | Documentation interactive Swagger |
31
- | `/health` | Status de l'API |
32
- | `/ui` | Interface Gradio interactive |
33
- | `/predict` | Prédiction unitaire (JSON) |
34
- | `/predict/batch` | Prédiction batch (3 fichiers CSV) |
35
 
36
- ## 🚀 Utilisation
 
 
 
 
37
 
38
- ### Prédiction unitaire
39
  ```bash
40
- curl -X POST https://asi-engineer-oc-p5-dev.hf.space/predict \
 
 
41
  -H "Content-Type: application/json" \
42
- -d '{
43
- "nombre_participation_pee": 0,
44
- "nb_formations_suivies": 2,
45
- "satisfaction_employee_environnement": 3,
46
- ...
47
- }'
48
  ```
49
 
50
- ### Prédiction batch (fichiers CSV)
 
 
 
51
  ```bash
52
- curl -X POST https://asi-engineer-oc-p5-dev.hf.space/predict/batch \
53
- -F "sondage_file=@extrait_sondage.csv" \
54
- -F "eval_file=@extrait_eval.csv" \
55
- -F "sirh_file=@extrait_sirh.csv"
 
 
 
 
 
56
  ```
57
 
58
- **Réponse :**
59
- ```json
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  {
61
  "total_employees": 1470,
62
- "predictions": [...],
 
 
 
63
  "summary": {
64
  "total_stay": 1169,
65
  "total_leave": 301,
66
- "high_risk_count": 222
 
 
67
  }
68
  }
69
  ```
70
 
71
- ## 📚 Documentation complète
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
- Voir [GitHub Repository](https://github.com/chaton59/OC_P5) pour la documentation complète.
 
 
1
+ # 🚀 Employee Turnover Prediction API - v3.2.1
2
+
3
+ ## 📊 Vue d'ensemble
4
+
5
+ API REST de prédiction du turnover des employés basée sur un modèle XGBoost avec SMOTE.
6
+
7
+
8
+ **✨ Nouveautés v3.2.1** :
9
+ - 🎛️ Sliders Gradio et schémas Pydantic alignés sur les min/max réels des données d'entraînement
10
+ - 📦 Endpoint batch CSV (3 fichiers bruts)
11
+ - 🔑 Authentification API Key (prod)
12
+ - 🔧 Correction preprocessing (scaling, ordre des colonnes)
13
+ - 📝 Documentation et exemples mis à jour
14
+
15
+ ## 🏗️ Architecture
16
+
17
+ ```
18
+ OC_P5/
19
+ ├── app.py # Point d'entrée FastAPI
20
+ ├── src/
21
+ │ ├── auth.py # Authentification API Key
22
+ │ ├── config.py # Configuration centralisée
23
+ │ ├── logger.py # Logging structuré (NOUVEAU)
24
+ │ ├── models.py # Chargement modèle HF Hub
25
+ │ ├── preprocessing.py # Pipeline preprocessing
26
+ │ ├── rate_limit.py # Rate limiting (NOUVEAU)
27
+ │ └── schemas.py # Validation Pydantic
28
+ ├── tests/ # Suite pytest (33 tests, 88% couverture)
29
+ ├── logs/ # Logs JSON (NOUVEAU)
30
+ │ ├── api.log # Tous les logs
31
+ │ └── error.log # Erreurs uniquement
32
+ ├── docs/ # Documentation
33
+ ├── ml_model/ # Scripts training
34
+ └── data/ # Données sources
35
+ ```
36
+
37
+ ## 🚀 Installation
38
+
39
+ ### Prérequis
40
+ - Python 3.12+
41
+ - Poetry 1.7+
42
+ - Git
43
+
44
+ ### Setup rapide
45
+
46
+ ```bash
47
+ # 1. Cloner le repo
48
+ git clone https://github.com/chaton59/OC_P5.git
49
+ cd OC_P5
50
+
51
+ # 2. Installer les dépendances
52
+ poetry install
53
+
54
+ # 3. Configurer l'environnement
55
+ cp .env.example .env
56
+ # Éditer .env avec vos valeurs
57
+
58
+ # 4. Lancer l'API
59
+ poetry run uvicorn app:app --reload
60
+
61
+ # 5. Accéder à la documentation
62
+ # http://localhost:8000/docs
63
+ ```
64
+
65
+ ## 📝 Configuration (.env)
66
+
67
+ ```bash
68
+ # Mode développement (désactive auth + active logs détaillés)
69
+ DEBUG=true
70
+
71
+ # API Key (requis en production)
72
+ API_KEY=your-secret-key-here
73
+
74
+ # Logging (DEBUG, INFO, WARNING, ERROR, CRITICAL)
75
+ LOG_LEVEL=INFO
76
 
77
+ # HuggingFace Model
78
+ HF_MODEL_REPO=ASI-Engineer/employee-turnover-model
79
+ MODEL_FILENAME=model/model.pkl
80
+ ```
81
 
82
+ ## 🔒 Authentification
 
 
 
 
 
 
83
 
84
+ ### Mode DEBUG (développement)
85
+ ```bash
86
+ # L'API Key n'est PAS requise
87
+ curl http://localhost:8000/predict -H "Content-Type: application/json" -d '{...}'
88
+ ```
89
 
90
+ ### Mode PRODUCTION
91
  ```bash
92
+ # L'API Key est REQUISE
93
+ curl http://localhost:8000/predict \
94
+ -H "X-API-Key: your-secret-key" \
95
  -H "Content-Type: application/json" \
96
+ -d '{...}'
 
 
 
 
 
97
  ```
98
 
99
+
100
+ ## 📡 Endpoints
101
+
102
+ ### 🏥 Health Check
103
  ```bash
104
+ GET /health
105
+
106
+ # Réponse
107
+ {
108
+ "status": "healthy",
109
+ "model_loaded": true,
110
+ "model_type": "Pipeline",
111
+ "version": "3.2.1"
112
+ }
113
  ```
114
 
115
+ ### 🔮 Prédiction unitaire
116
+ ```bash
117
+ POST /predict
118
+ Content-Type: application/json
119
+ X-API-Key: your-key (en production)
120
+
121
+ # Payload (exemple, contraintes réelles appliquées)
122
+ {
123
+ "nombre_participation_pee": 0,
124
+ "nb_formations_suivies": 2,
125
+ "nombre_employee_sous_responsabilite": 1,
126
+ "distance_domicile_travail": 15,
127
+ "niveau_education": 3,
128
+ "domaine_etude": "Infra & Cloud",
129
+ "ayant_enfants": "Y",
130
+ "frequence_deplacement": "Occasionnel",
131
+ "annees_depuis_la_derniere_promotion": 2,
132
+ "annes_sous_responsable_actuel": 5,
133
+ "satisfaction_employee_environnement": 3,
134
+ "note_evaluation_precedente": 4,
135
+ "niveau_hierarchique_poste": 2,
136
+ "satisfaction_employee_nature_travail": 3,
137
+ "satisfaction_employee_equipe": 3,
138
+ "satisfaction_employee_equilibre_pro_perso": 2,
139
+ "note_evaluation_actuelle": 4,
140
+ "heure_supplementaires": "Non",
141
+ "augementation_salaire_precedente": 5.5,
142
+ "age": 35,
143
+ "genre": "M",
144
+ "revenu_mensuel": 4500.0,
145
+ "statut_marital": "Marié(e)",
146
+ "departement": "Commercial",
147
+ "poste": "Manager",
148
+ "nombre_experiences_precedentes": 3,
149
+ "nombre_heures_travailless": 80,
150
+ "annee_experience_totale": 10,
151
+ "annees_dans_l_entreprise": 5,
152
+ "annees_dans_le_poste_actuel": 2
153
+ }
154
+
155
+ # Réponse
156
+ {
157
+ "prediction": 0, # 0 = reste, 1 = part
158
+ "probability_0": 0.85, # Probabilité de rester
159
+ "probability_1": 0.15, # Probabilité de partir
160
+ "risk_level": "Low" # Low, Medium, High
161
+ }
162
+ ```
163
+
164
+ ### 📦 Prédiction batch (CSV)
165
+ ```bash
166
+ POST /predict/batch
167
+ X-API-Key: your-key (en production)
168
+
169
+ # Envoi des 3 fichiers CSV bruts
170
+ curl -X POST "http://localhost:8000/predict/batch" \
171
+ -H "X-API-Key: your-key" \
172
+ -F "sondage_file=@data/extrait_sondage.csv" \
173
+ -F "eval_file=@data/extrait_eval.csv" \
174
+ -F "sirh_file=@data/extrait_sirh.csv"
175
+
176
+ # Réponse
177
  {
178
  "total_employees": 1470,
179
+ "predictions": [
180
+ {"employee_id": 1, "prediction": 1, "probability_leave": 0.84, "risk_level": "High"},
181
+ {"employee_id": 2, "prediction": 0, "probability_leave": 0.11, "risk_level": "Low"}
182
+ ],
183
  "summary": {
184
  "total_stay": 1169,
185
  "total_leave": 301,
186
+ "high_risk_count": 222,
187
+ "medium_risk_count": 233,
188
+ "low_risk_count": 1015
189
  }
190
  }
191
  ```
192
 
193
+ ## 📊 Logging
194
+
195
+ ### Logs structurés JSON
196
+
197
+ **Fichiers** :
198
+ - `logs/api.log` : Tous les logs
199
+ - `logs/error.log` : Erreurs uniquement
200
+
201
+ **Format** :
202
+ ```json
203
+ {
204
+ "timestamp": "2025-12-26T10:30:45",
205
+ "level": "INFO",
206
+ "logger": "employee_turnover_api",
207
+ "message": "Request POST /predict",
208
+ "method": "POST",
209
+ "path": "/predict",
210
+ "status_code": 200,
211
+ "duration_ms": 23.45,
212
+ "client_host": "127.0.0.1"
213
+ }
214
+ ```
215
+
216
+ ## 🛡️ Rate Limiting
217
+
218
+ **Configuration** :
219
+ - **Développement** : Désactivé (DEBUG=true)
220
+ - **Production** : 20 requêtes/minute par IP ou API Key
221
+
222
+ **En cas de dépassement** :
223
+ ```json
224
+ {
225
+ "error": "Rate limit exceeded",
226
+ "message": "20 per 1 minute"
227
+ }
228
+ ```
229
+
230
+ ## ✅ Tests
231
+
232
+ ```bash
233
+ # Tous les tests
234
+ poetry run pytest tests/ -v
235
+
236
+ # Avec couverture
237
+ poetry run pytest tests/ --cov --cov-report=html
238
+
239
+ # Voir rapport HTML
240
+ open htmlcov/index.html
241
+ ```
242
+
243
+ **Résultats** :
244
+ - ✅ 33 tests passés
245
+ - 📊 88% de couverture globale
246
+
247
+ ## 🚀 Déploiement
248
+
249
+ ### Variables d'environnement requises
250
+ ```bash
251
+ DEBUG=false
252
+ API_KEY=<votre-clé-sécurisée>
253
+ LOG_LEVEL=INFO
254
+ ```
255
+
256
+ ### HuggingFace Spaces
257
+ Prêt pour déploiement avec `app.py` et `requirements.txt`
258
+
259
+ ## 📚 Documentation
260
+
261
+ - **API Interactive** : http://localhost:8000/docs
262
+ - **ReDoc** : http://localhost:8000/redoc
263
+ - **Guide complet** : [docs/API_GUIDE.md](docs/API_GUIDE.md)
264
+ - **Standards** : [docs/standards.md](docs/standards.md)
265
+ - **Couverture tests** : [docs/TEST_COVERAGE.md](docs/TEST_COVERAGE.md)
266
+
267
+ ## 📦 Dépendances principales
268
+
269
+ - **FastAPI** 0.115.14 : Framework web
270
+ - **Pydantic** 2.12.5 : Validation données
271
+ - **XGBoost** 2.1.3 : Modèle ML
272
+ - **SlowAPI** 0.1.9 : Rate limiting
273
+ - **python-json-logger** 4.0.0 : Logs structurés
274
+ - **pytest** 9.0.2 : Tests
275
+
276
+
277
+ ## 🔄 Changelog
278
+
279
+ ### v3.2.1 (janvier 2026)
280
+ - 🎛️ Sliders Gradio et schémas Pydantic alignés sur les min/max réels des données d'entraînement
281
+ - 📦 Endpoint batch CSV (3 fichiers bruts)
282
+ - 🔑 Authentification API Key (prod)
283
+ - 🔧 Correction preprocessing (scaling, ordre des colonnes)
284
+ - 📝 Documentation et exemples mis à jour
285
+
286
+ ### v2.2.0 (27 décembre 2025)
287
+ - 📦 Nouvel endpoint `/predict/batch` pour traitement CSV direct
288
+ - 🔧 Fix preprocessing : ajout du scaling des features
289
+ - 🔧 Fix preprocessing : correction de l'ordre des colonnes
290
+ - 📊 Amélioration précision des prédictions (~90%)
291
+
292
+ ### v2.1.0 (26 décembre 2025)
293
+ - ✨ Système de logging structuré JSON
294
+ - 🛡️ Rate limiting avec SlowAPI
295
+ - ⚡ Amélioration gestion d'erreurs
296
+ - 📊 Monitoring des performances
297
+
298
+ ### v2.0.0 (26 décembre 2025)
299
+ - ✅ Suite de tests complète (36 tests)
300
+ - 🔐 Authentification API Key
301
+ - 📊 88% de couverture de code
302
+
303
+ ## 👥 Auteurs
304
 
305
+ - **Projet** : OpenClassrooms P5
306
+ - **Repo** : [github.com/chaton59/OC_P5](https://github.com/chaton59/OC_P5)
README_HF.md CHANGED
@@ -9,20 +9,23 @@ license: mit
9
  app_port: 7860
10
  ---
11
 
12
- # Employee Turnover Prediction API 🚀
13
 
14
- API de prédiction du turnover des employés avec XGBoost + SMOTE.
 
 
15
 
16
  ## 🎯 Fonctionnalités
17
 
18
  - ✅ Prédiction de turnover (0 = reste, 1 = part)
19
- - 📦 **Nouveau** : Endpoint batch pour traiter vos fichiers CSV directement
 
20
  - 📊 Probabilités et niveau de risque (Low/Medium/High)
21
- - 🔐 Authentification API Key
22
  - 📝 Logs structurés JSON
23
  - 🛡️ Rate limiting (20 req/min)
24
  - 📚 Documentation OpenAPI/Swagger
25
 
 
26
  ## 🔗 Endpoints
27
 
28
  | Endpoint | Description |
@@ -30,26 +33,55 @@ API de prédiction du turnover des employés avec XGBoost + SMOTE.
30
  | `/docs` | Documentation interactive Swagger |
31
  | `/health` | Status de l'API |
32
  | `/ui` | Interface Gradio interactive |
33
- | `/predict` | Prédiction unitaire (JSON) |
34
- | `/predict/batch` | Prédiction batch (3 fichiers CSV) |
 
35
 
36
  ## 🚀 Utilisation
37
 
38
- ### Prédiction unitaire
39
  ```bash
40
  curl -X POST https://asi-engineer-oc-p5-dev.hf.space/predict \
41
  -H "Content-Type: application/json" \
 
42
  -d '{
43
  "nombre_participation_pee": 0,
44
  "nb_formations_suivies": 2,
 
 
 
 
 
 
 
 
45
  "satisfaction_employee_environnement": 3,
46
- ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  }'
48
  ```
49
 
50
- ### Prédiction batch (fichiers CSV)
51
  ```bash
52
  curl -X POST https://asi-engineer-oc-p5-dev.hf.space/predict/batch \
 
53
  -F "sondage_file=@extrait_sondage.csv" \
54
  -F "eval_file=@extrait_eval.csv" \
55
  -F "sirh_file=@extrait_sirh.csv"
@@ -68,6 +100,7 @@ curl -X POST https://asi-engineer-oc-p5-dev.hf.space/predict/batch \
68
  }
69
  ```
70
 
 
71
  ## 📚 Documentation complète
72
 
73
- Voir [GitHub Repository](https://github.com/chaton59/OC_P5) pour la documentation complète.
 
9
  app_port: 7860
10
  ---
11
 
 
12
 
13
+ # Employee Turnover Prediction API 🚀 (v3.2.1)
14
+
15
+ API de prédiction du turnover des employés (XGBoost + SMOTE) avec endpoints batch, validation stricte et documentation à jour.
16
 
17
  ## 🎯 Fonctionnalités
18
 
19
  - ✅ Prédiction de turnover (0 = reste, 1 = part)
20
+ - 📦 Endpoint batch CSV (3 fichiers bruts)
21
+ - 🎛️ Sliders Gradio et schémas Pydantic alignés sur les min/max réels
22
  - 📊 Probabilités et niveau de risque (Low/Medium/High)
23
+ - 🔐 Authentification API Key (obligatoire)
24
  - 📝 Logs structurés JSON
25
  - 🛡️ Rate limiting (20 req/min)
26
  - 📚 Documentation OpenAPI/Swagger
27
 
28
+
29
  ## 🔗 Endpoints
30
 
31
  | Endpoint | Description |
 
33
  | `/docs` | Documentation interactive Swagger |
34
  | `/health` | Status de l'API |
35
  | `/ui` | Interface Gradio interactive |
36
+ | `/predict` | Prédiction unitaire (JSON, contraintes réelles) |
37
+ | `/predict/batch` | Prédiction batch (3 fichiers CSV bruts) |
38
+
39
 
40
  ## 🚀 Utilisation
41
 
42
+ ### Prédiction unitaire (toutes contraintes appliquées)
43
  ```bash
44
  curl -X POST https://asi-engineer-oc-p5-dev.hf.space/predict \
45
  -H "Content-Type: application/json" \
46
+ -H "X-API-Key: your-key" \
47
  -d '{
48
  "nombre_participation_pee": 0,
49
  "nb_formations_suivies": 2,
50
+ "nombre_employee_sous_responsabilite": 1,
51
+ "distance_domicile_travail": 15,
52
+ "niveau_education": 3,
53
+ "domaine_etude": "Infra & Cloud",
54
+ "ayant_enfants": "Y",
55
+ "frequence_deplacement": "Occasionnel",
56
+ "annees_depuis_la_derniere_promotion": 2,
57
+ "annes_sous_responsable_actuel": 5,
58
  "satisfaction_employee_environnement": 3,
59
+ "note_evaluation_precedente": 4,
60
+ "niveau_hierarchique_poste": 2,
61
+ "satisfaction_employee_nature_travail": 3,
62
+ "satisfaction_employee_equipe": 3,
63
+ "satisfaction_employee_equilibre_pro_perso": 2,
64
+ "note_evaluation_actuelle": 4,
65
+ "heure_supplementaires": "Non",
66
+ "augementation_salaire_precedente": 5.5,
67
+ "age": 35,
68
+ "genre": "M",
69
+ "revenu_mensuel": 4500.0,
70
+ "statut_marital": "Marié(e)",
71
+ "departement": "Commercial",
72
+ "poste": "Manager",
73
+ "nombre_experiences_precedentes": 3,
74
+ "nombre_heures_travailless": 80,
75
+ "annee_experience_totale": 10,
76
+ "annees_dans_l_entreprise": 5,
77
+ "annees_dans_le_poste_actuel": 2
78
  }'
79
  ```
80
 
81
+ ### Prédiction batch (3 fichiers CSV bruts)
82
  ```bash
83
  curl -X POST https://asi-engineer-oc-p5-dev.hf.space/predict/batch \
84
+ -H "X-API-Key: your-key" \
85
  -F "sondage_file=@extrait_sondage.csv" \
86
  -F "eval_file=@extrait_eval.csv" \
87
  -F "sirh_file=@extrait_sirh.csv"
 
100
  }
101
  ```
102
 
103
+
104
  ## 📚 Documentation complète
105
 
106
+ Voir [docs/API.md](docs/API.md) ou le [GitHub Repository](https://github.com/chaton59/OC_P5) pour la documentation complète et les contraintes détaillées (min/max, enums, etc).