ASI-Engineer commited on
Commit
bb12238
·
verified ·
1 Parent(s): 04e665f

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +38 -48
  2. app.py +7 -9
  3. main.py +1 -0
README.md CHANGED
@@ -1,67 +1,57 @@
1
  ---
2
  title: OC P5 - API ML Déployée
3
- emoji: 🚀
4
  colorFrom: blue
5
- colorTo: purple
6
- sdk: static
 
7
  app_file: app.py
8
  pinned: false
 
9
  ---
10
 
11
- # ML Deployment Project
12
- Déploiement d'un modèle ML pour Futurisys : API FastAPI, PostgreSQL, tests Pytest, CI/CD.
13
 
14
- ## Aperçu
15
- POC pour exposer un modèle ML via API performante, avec traçabilité DB et bonnes pratiques DevOps.
16
 
17
- ## Installation
18
- 1. Clone le repo : `git clone https://github.com/ton-username/ml-deployment-project.git`
19
- 2. Installe Poetry (si pas fait) : `curl -sSL https://install.python-poetry.org | python3 -`
20
- 3. Dépendances : `poetry install` (crée/lock .venv avec deps)
21
- 4. Active env : `poetry shell`
22
 
23
- ## Utilisation
24
- - Dev : `poetry run uvicorn src.main:app --reload` (Étape 3 pour API).
25
- - BDD : `poetry run python scripts/create_db.py` (Étape 4).
26
- - Tests : `poetry run pytest` (Étape 5).
 
27
 
28
- ## Structure du Projet
29
- - `src/` : Code core (API, modèle ML).
30
- - `tests/` : Tests unitaires/fonctionnels (Pytest).
31
- - `docs/` : Schémas UML, docs API.
32
- - `scripts/` : Utils init (BDD, data load).
33
- - `data/` : Datasets (ignorés pour privacy).
34
 
35
- ## CI/CD Optimization
36
- - Pipelines configurés pour exécution <10 min (ex. : lint ~1 min, tests ~3 min, deploy ~2 min). Si >10 min, optimiser via cache Poetry ou jobs parallèles. Temps observés basés sur runs GitHub Actions.
 
37
 
38
- ## CI/CD Détails
39
- - Pipeline : GitHub Actions pour lint (Flake8/Black), tests (Pytest), deploy HF.
40
- - Environnements : Dev (branch dev/local tests), Prod (branch main/HF oc_p5).
41
- - Secrets : HF_TOKEN sécurisé via GitHub Secrets.
42
- - Standards : Voir [docs/standards.md](./docs/standards.md).
43
 
44
- ## Environnements CI/CD
45
- - Dev : Branch "dev" -> HF space oc_p5-dev pour tests itératifs et validation.
46
- - Prod : Branch "main" -> HF space oc_p5 pour déploiement stable.
47
- - Secrets : HF_TOKEN partagé (sécurisé via GitHub Secrets) pour dev/prod.
 
 
 
 
48
 
49
- ## Branches & Conventions
50
- - `main` : Stable (merges via PR).
51
- - `main` : pour développement et tests
52
- - `feature/etapeX` : Fonctionnalités (kebab-case, ex. `feature/etape3-api`).
53
- - Commits : Conventional (ex. `feat: Add endpoint`).
54
 
55
- ## Déploiement & Sécurité
56
- - Auth/Sec : À venir (JWT pour API, secrets en .env ignoré).
57
- - Versions : Tags semver (ex. v1.0.0 pour Étape 1).
 
58
 
59
- ## HF Spaces
60
- - Prod : https://huggingface.co/spaces/ASI-Engineer/oc_p5 (branch dev, pour tests itératifs).
61
- - Sync auto via GitHub Actions (push déclenche rebuild ~2min, avec HF_TOKEN sécurisé).
62
 
63
- ## Documentation
64
- - Standards Code/ML
 
65
 
66
- ## Licence
67
- MIT (ou adapte pour Futurisys).
 
 
1
  ---
2
  title: OC P5 - API ML Déployée
3
+ emoji: 🎯
4
  colorFrom: blue
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: 5.9.1
8
  app_file: app.py
9
  pinned: false
10
+ license: mit
11
  ---
12
 
13
+ # 🎯 Employee Turnover Prediction - DEV Environment
 
14
 
15
+ Interface Gradio pour tester le modèle de prédiction de départ des employés (turnover).
 
16
 
17
+ ## 🚀 Modèle ML
 
 
 
 
18
 
19
+ - **Algorithme**: XGBoost optimisé avec RandomizedSearchCV
20
+ - **Équilibrage**: SMOTE pour gérer le déséquilibre de classes (ratio 5:1)
21
+ - **Tracking**: MLflow pour versioning et reproductibilité
22
+ - **Métriques**: F1-Score optimisé (0.51), Accuracy 79%
23
+ - **Stockage**: [Hugging Face Hub](https://huggingface.co/ASI-Engineer/employee-turnover-model)
24
 
25
+ ## 📊 Fonctionnalités
 
 
 
 
 
26
 
27
+ - **Status Checker**: Vérifier l'état du modèle et les métriques
28
+ - **API Simple**: Interface Gradio pour tests rapides
29
+ - **Chargement automatique**: Modèle téléchargé depuis HF Hub au démarrage
30
 
31
+ ## 🔧 Architecture
 
 
 
 
32
 
33
+ ```python
34
+ # Chargement du modèle depuis HF Hub
35
+ model_path = hf_hub_download(
36
+ repo_id="ASI-Engineer/employee-turnover-model",
37
+ filename="model/model.pkl"
38
+ )
39
+ model = mlflow.sklearn.load_model(str(Path(model_path).parent))
40
+ ```
41
 
42
+ ## 📈 Métriques
 
 
 
 
43
 
44
+ - **F1-Score**: 0.5136
45
+ - **Accuracy**: 79%
46
+ - **Données**: 1470 échantillons, 50 features
47
+ - **Classes**: {0: 1233, 1: 237} - Ratio 5.20:1
48
 
49
+ ## 🔗 Liens
 
 
50
 
51
+ - **Modèle**: [employee-turnover-model](https://huggingface.co/ASI-Engineer/employee-turnover-model)
52
+ - **GitHub**: [OC_P5](https://github.com/chaton59/OC_P5)
53
+ - **CI/CD**: GitHub Actions avec déploiement automatique
54
 
55
+ Ce Space est synchronisé automatiquement via CI/CD depuis la branche `dev` du repository GitHub.
56
+
57
+ **Repository**: [chaton59/OC_P5](https://github.com/chaton59/OC_P5)
app.py CHANGED
@@ -5,11 +5,12 @@ Interface Gradio pour tester le modèle Employee Turnover en production.
5
  Déploiement sur Hugging Face Spaces pour tests rapides.
6
  Version de démonstration - Interface complète en développement.
7
  """
8
- import gradio as gr
 
 
9
  import mlflow
10
- import mlflow.sklearn
11
  from huggingface_hub import hf_hub_download
12
- from pathlib import Path
13
 
14
  # Configuration
15
  HF_MODEL_REPO = "ASI-Engineer/employee-turnover-model"
@@ -30,7 +31,7 @@ def load_model():
30
  model_path = hf_hub_download(
31
  repo_id=HF_MODEL_REPO, filename="model/model.pkl", repo_type="model"
32
  )
33
- model = mlflow.sklearn.load_model(str(Path(model_path).parent))
34
  print(f"✅ Modèle chargé depuis HF Hub: {HF_MODEL_REPO}")
35
  return model, "HF Hub"
36
  except Exception as e:
@@ -40,13 +41,13 @@ def load_model():
40
  mlflow.set_tracking_uri("sqlite:///mlflow.db")
41
  try:
42
  # Essayer Model Registry d'abord
43
- model = mlflow.sklearn.load_model("models:/XGBoost_Employee_Turnover/latest")
44
  print("✅ Modèle chargé depuis MLflow Model Registry")
45
  return model, "MLflow Registry"
46
  except Exception:
47
  try:
48
  # Fallback sur run ID
49
- model = mlflow.sklearn.load_model(f"runs:/{FALLBACK_RUN_ID}/model")
50
  print(f"✅ Modèle chargé depuis MLflow run: {FALLBACK_RUN_ID}")
51
  return model, "MLflow Local"
52
  except Exception as e2:
@@ -108,9 +109,6 @@ def get_model_info():
108
  except Exception as e:
109
  return {"status": "✅ Modèle chargé (info limitées)", "error": str(e)}
110
 
111
- except Exception as e:
112
- return {"status": "✅ Modèle chargé (info limitées)", "error": str(e)}
113
-
114
 
115
  # Interface Gradio
116
  with gr.Blocks(
 
5
  Déploiement sur Hugging Face Spaces pour tests rapides.
6
  Version de démonstration - Interface complète en développement.
7
  """
8
+ from pathlib import Path
9
+
10
+ import gradio as gr # type: ignore[import]
11
  import mlflow
12
+ import mlflow.pyfunc
13
  from huggingface_hub import hf_hub_download
 
14
 
15
  # Configuration
16
  HF_MODEL_REPO = "ASI-Engineer/employee-turnover-model"
 
31
  model_path = hf_hub_download(
32
  repo_id=HF_MODEL_REPO, filename="model/model.pkl", repo_type="model"
33
  )
34
+ model = mlflow.pyfunc.load_model(str(Path(model_path).parent)) # type: ignore[attr-defined]
35
  print(f"✅ Modèle chargé depuis HF Hub: {HF_MODEL_REPO}")
36
  return model, "HF Hub"
37
  except Exception as e:
 
41
  mlflow.set_tracking_uri("sqlite:///mlflow.db")
42
  try:
43
  # Essayer Model Registry d'abord
44
+ model = mlflow.pyfunc.load_model("models:/XGBoost_Employee_Turnover/latest") # type: ignore[attr-defined]
45
  print("✅ Modèle chargé depuis MLflow Model Registry")
46
  return model, "MLflow Registry"
47
  except Exception:
48
  try:
49
  # Fallback sur run ID
50
+ model = mlflow.pyfunc.load_model(f"runs:/{FALLBACK_RUN_ID}/model") # type: ignore[attr-defined]
51
  print(f"✅ Modèle chargé depuis MLflow run: {FALLBACK_RUN_ID}")
52
  return model, "MLflow Local"
53
  except Exception as e2:
 
109
  except Exception as e:
110
  return {"status": "✅ Modèle chargé (info limitées)", "error": str(e)}
111
 
 
 
 
112
 
113
  # Interface Gradio
114
  with gr.Blocks(
main.py CHANGED
@@ -21,6 +21,7 @@ from pathlib import Path
21
  import joblib
22
  import mlflow
23
  import mlflow.sklearn
 
24
  from ml_model.preprocess import preprocess_data
25
  from ml_model.train_model import train_model
26
 
 
21
  import joblib
22
  import mlflow
23
  import mlflow.sklearn
24
+
25
  from ml_model.preprocess import preprocess_data
26
  from ml_model.train_model import train_model
27