ASI-Engineer commited on
Commit
b11e918
·
verified ·
1 Parent(s): 454c86f

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +5 -2
  2. app.py +6 -45
  3. requirements.txt +9 -114
README.md CHANGED
@@ -64,10 +64,13 @@ poetry run python main.py
64
  poetry run python app.py
65
  ```
66
 
67
- ### Export pour HF Spaces
68
 
69
- HuggingFace Spaces nécessite un `requirements.txt`. Pour le générer depuis Poetry :
70
 
 
 
 
71
  ```bash
72
  ./scripts/export_requirements.sh
73
  ```
 
64
  poetry run python app.py
65
  ```
66
 
67
+ ### Requirements.txt pour HF Spaces
68
 
69
+ Le fichier `requirements.txt` est **minimal et optimisé** pour HF Spaces (seulement gradio, huggingface-hub, joblib).
70
 
71
+ Il est **généré automatiquement** par le CI/CD lors des déploiements.
72
+
73
+ Pour le générer manuellement :
74
  ```bash
75
  ./scripts/export_requirements.sh
76
  ```
app.py CHANGED
@@ -6,24 +6,19 @@ 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.pyfunc
11
  from huggingface_hub import hf_hub_download
12
 
13
  # Configuration
14
  HF_MODEL_REPO = "ASI-Engineer/employee-turnover-model"
15
- FALLBACK_RUN_ID = "40e43c8e425345bab3d19f27eb8fe5d8"
16
 
17
 
18
  def load_model():
19
  """
20
- Charge le modèle depuis Hugging Face Hub (prod) ou MLflow local (dev).
21
 
22
- Ordre de priorité:
23
- 1. HF Hub avec pickle direct (modèle déployé en production)
24
- 2. MLflow local (développement local)
25
  """
26
- # Essayer HF Hub en premier (production) - charger directement le pickle
27
  try:
28
  import joblib
29
 
@@ -35,24 +30,8 @@ def load_model():
35
  print(f"✅ Modèle chargé depuis HF Hub: {HF_MODEL_REPO}")
36
  return model, "HF Hub"
37
  except Exception as e:
38
- print(f"⚠️ HF Hub non disponible: {e}")
39
-
40
- # Fallback: MLflow local (développement uniquement)
41
- try:
42
- mlflow.set_tracking_uri("sqlite:///mlflow.db")
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:
54
- print(f"❌ Erreur chargement MLflow: {e2}")
55
- return None, "Error"
56
 
57
 
58
  # Charger le modèle au démarrage
@@ -82,27 +61,9 @@ def get_model_info():
82
  "model_type": type(model).__name__,
83
  "features": "~50 features (après preprocessing)",
84
  "algorithme": "XGBoost + SMOTE",
85
- "hf_hub_repo": HF_MODEL_REPO if model_source == "HF Hub" else "N/A",
86
  }
87
 
88
- # Si MLflow local, ajouter les métriques
89
- if model_source == "MLflow Local":
90
- mlflow.set_tracking_uri("sqlite:///mlflow.db")
91
- client = mlflow.MlflowClient()
92
- runs = client.search_runs(
93
- experiment_ids=["1"], order_by=["start_time DESC"], max_results=1
94
- )
95
- if runs:
96
- run = runs[0]
97
- metrics = run.data.metrics
98
- info.update(
99
- {
100
- "run_id": run.info.run_id[:8],
101
- "f1_score": f"{metrics.get('f1_score', 0):.4f}",
102
- "accuracy": f"{metrics.get('accuracy', 0):.4f}",
103
- }
104
- )
105
-
106
  info["info"] = "Interface de prédiction en développement - API FastAPI à venir"
107
  return info
108
 
 
6
  Version de démonstration - Interface complète en développement.
7
  """
8
  import gradio as gr
 
 
9
  from huggingface_hub import hf_hub_download
10
 
11
  # Configuration
12
  HF_MODEL_REPO = "ASI-Engineer/employee-turnover-model"
 
13
 
14
 
15
  def load_model():
16
  """
17
+ Charge le modèle depuis Hugging Face Hub.
18
 
19
+ En production (HF Spaces), charge uniquement depuis HF Hub.
20
+ Le fallback MLflow local n'est disponible qu'en développement local.
 
21
  """
 
22
  try:
23
  import joblib
24
 
 
30
  print(f"✅ Modèle chargé depuis HF Hub: {HF_MODEL_REPO}")
31
  return model, "HF Hub"
32
  except Exception as e:
33
+ print(f" Erreur chargement depuis HF Hub: {e}")
34
+ return None, "Error"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
 
37
  # Charger le modèle au démarrage
 
61
  "model_type": type(model).__name__,
62
  "features": "~50 features (après preprocessing)",
63
  "algorithme": "XGBoost + SMOTE",
64
+ "hf_hub_repo": HF_MODEL_REPO,
65
  }
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  info["info"] = "Interface de prédiction en développement - API FastAPI à venir"
68
  return info
69
 
requirements.txt CHANGED
@@ -1,114 +1,9 @@
1
- # This file is auto-generated from pyproject.toml using Poetry
2
- # To update: run ./scripts/export_requirements.sh
3
-
4
- aiofiles==23.2.1 ; python_version >= "3.12" and python_version < "4.0"
5
- alembic==1.17.2 ; python_version >= "3.12" and python_version < "4.0"
6
- annotated-doc==0.0.4 ; python_version >= "3.12" and python_version < "4.0"
7
- annotated-types==0.7.0 ; python_version >= "3.12" and python_version < "4.0"
8
- anyio==4.12.0 ; python_version >= "3.12" and python_version < "4.0"
9
- audioop-lts==0.2.2 ; python_version >= "3.13" and python_version < "4.0"
10
- blinker==1.9.0 ; python_version >= "3.12" and python_version < "4.0"
11
- cachetools==6.2.4 ; python_version >= "3.12" and python_version < "4.0"
12
- certifi==2025.11.12 ; python_version >= "3.12" and python_version < "4.0"
13
- cffi==2.0.0 ; python_version >= "3.12" and python_version < "4.0" and platform_python_implementation != "PyPy"
14
- charset-normalizer==3.4.4 ; python_version >= "3.12" and python_version < "4.0"
15
- click==8.3.1 ; python_version >= "3.12" and python_version < "4.0"
16
- cloudpickle==3.1.2 ; python_version >= "3.12" and python_version < "4.0"
17
- colorama==0.4.6 ; python_version >= "3.12" and python_version < "4.0" and platform_system == "Windows"
18
- contourpy==1.3.3 ; python_version >= "3.12" and python_version < "4.0"
19
- cryptography==46.0.3 ; python_version >= "3.12" and python_version < "4.0"
20
- cycler==0.12.1 ; python_version >= "3.12" and python_version < "4.0"
21
- databricks-sdk==0.76.0 ; python_version >= "3.12" and python_version < "4.0"
22
- docker==7.1.0 ; python_version >= "3.12" and python_version < "4.0"
23
- fastapi==0.123.4 ; python_version >= "3.12" and python_version < "4.0"
24
- ffmpy==1.0.0 ; python_version >= "3.12" and python_version < "4.0"
25
- filelock==3.20.1 ; python_version >= "3.12" and python_version < "4.0"
26
- flask-cors==6.0.2 ; python_version >= "3.12" and python_version < "4.0"
27
- flask==3.1.2 ; python_version >= "3.12" and python_version < "4.0"
28
- fonttools==4.61.1 ; python_version >= "3.12" and python_version < "4.0"
29
- fsspec==2025.12.0 ; python_version >= "3.12" and python_version < "4.0"
30
- gitdb==4.0.12 ; python_version >= "3.12" and python_version < "4.0"
31
- gitpython==3.1.45 ; python_version >= "3.12" and python_version < "4.0"
32
- google-auth==2.45.0 ; python_version >= "3.12" and python_version < "4.0"
33
- gradio-client==1.7.0 ; python_version >= "3.12" and python_version < "4.0"
34
- gradio==5.14.0 ; python_version >= "3.12" and python_version < "4.0"
35
- graphene==3.4.3 ; python_version >= "3.12" and python_version < "4.0"
36
- graphql-core==3.2.7 ; python_version >= "3.12" and python_version < "4.0"
37
- graphql-relay==3.2.0 ; python_version >= "3.12" and python_version < "4.0"
38
- greenlet==3.2.4 ; python_version >= "3.12" and python_version < "4.0" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32")
39
- gunicorn==23.0.0 ; python_version >= "3.12" and python_version < "4.0" and platform_system != "Windows"
40
- h11==0.16.0 ; python_version >= "3.12" and python_version < "4.0"
41
- httpcore==1.0.9 ; python_version >= "3.12" and python_version < "4.0"
42
- httpx==0.28.1 ; python_version >= "3.12" and python_version < "4.0"
43
- huey==2.5.5 ; python_version >= "3.12" and python_version < "4.0"
44
- huggingface-hub==0.27.1 ; python_version >= "3.12" and python_version < "4.0"
45
- idna==3.11 ; python_version >= "3.12" and python_version < "4.0"
46
- imbalanced-learn==0.13.0 ; python_version >= "3.12" and python_version < "4.0"
47
- importlib-metadata==8.7.1 ; python_version >= "3.12" and python_version < "4.0"
48
- itsdangerous==2.2.0 ; python_version >= "3.12" and python_version < "4.0"
49
- jinja2==3.1.6 ; python_version >= "3.12" and python_version < "4.0"
50
- joblib==1.5.3 ; python_version >= "3.12" and python_version < "4.0"
51
- kiwisolver==1.4.9 ; python_version >= "3.12" and python_version < "4.0"
52
- mako==1.3.10 ; python_version >= "3.12" and python_version < "4.0"
53
- markdown-it-py==4.0.0 ; python_version >= "3.12" and python_version < "4.0" and sys_platform != "emscripten"
54
- markupsafe==2.1.5 ; python_version >= "3.12" and python_version < "4.0"
55
- matplotlib==3.10.8 ; python_version >= "3.12" and python_version < "4.0"
56
- mdurl==0.1.2 ; python_version >= "3.12" and python_version < "4.0" and sys_platform != "emscripten"
57
- mlflow-skinny==3.8.0 ; python_version >= "3.12" and python_version < "4.0"
58
- mlflow-tracing==3.8.0 ; python_version >= "3.12" and python_version < "4.0"
59
- mlflow==3.8.0 ; python_version >= "3.12" and python_version < "4.0"
60
- numpy==2.4.0 ; python_version >= "3.12" and python_version < "4.0"
61
- nvidia-nccl-cu12==2.28.9 ; python_version >= "3.12" and python_version < "4.0" and platform_system == "Linux" and platform_machine != "aarch64"
62
- opentelemetry-api==1.39.1 ; python_version >= "3.12" and python_version < "4.0"
63
- opentelemetry-proto==1.39.1 ; python_version >= "3.12" and python_version < "4.0"
64
- opentelemetry-sdk==1.39.1 ; python_version >= "3.12" and python_version < "4.0"
65
- opentelemetry-semantic-conventions==0.60b1 ; python_version >= "3.12" and python_version < "4.0"
66
- orjson==3.11.5 ; python_version >= "3.12" and python_version < "4.0"
67
- packaging==25.0 ; python_version >= "3.12" and python_version < "4.0"
68
- pandas==2.3.3 ; python_version >= "3.12" and python_version < "4.0"
69
- pillow==11.3.0 ; python_version >= "3.12" and python_version < "4.0"
70
- protobuf==6.33.2 ; python_version >= "3.12" and python_version < "4.0"
71
- pyarrow==22.0.0 ; python_version >= "3.12" and python_version < "4.0"
72
- pyasn1-modules==0.4.2 ; python_version >= "3.12" and python_version < "4.0"
73
- pyasn1==0.6.1 ; python_version >= "3.12" and python_version < "4.0"
74
- pycparser==2.23 ; python_version >= "3.12" and python_version < "4.0" and platform_python_implementation != "PyPy" and implementation_name != "PyPy"
75
- pydantic-core==2.41.5 ; python_version >= "3.12" and python_version < "4.0"
76
- pydantic==2.12.5 ; python_version >= "3.12" and python_version < "4.0"
77
- pydub==0.25.1 ; python_version >= "3.12" and python_version < "4.0"
78
- pygments==2.19.2 ; python_version >= "3.12" and python_version < "4.0" and sys_platform != "emscripten"
79
- pyparsing==3.3.1 ; python_version >= "3.12" and python_version < "4.0"
80
- python-dateutil==2.9.0.post0 ; python_version >= "3.12" and python_version < "4.0"
81
- python-dotenv==1.2.1 ; python_version >= "3.12" and python_version < "4.0"
82
- python-multipart==0.0.21 ; python_version >= "3.12" and python_version < "4.0"
83
- pytz==2025.2 ; python_version >= "3.12" and python_version < "4.0"
84
- pywin32==311 ; python_version >= "3.12" and python_version < "4.0" and sys_platform == "win32"
85
- pyyaml==6.0.3 ; python_version >= "3.12" and python_version < "4.0"
86
- requests==2.32.5 ; python_version >= "3.12" and python_version < "4.0"
87
- rich==14.2.0 ; python_version >= "3.12" and python_version < "4.0" and sys_platform != "emscripten"
88
- rsa==4.9.1 ; python_version >= "3.12" and python_version < "4.0"
89
- ruff==0.14.10 ; python_version >= "3.12" and python_version < "4.0" and sys_platform != "emscripten"
90
- safehttpx==0.1.7 ; python_version >= "3.12" and python_version < "4.0"
91
- scikit-learn==1.6.1 ; python_version >= "3.12" and python_version < "4.0"
92
- scipy==1.16.3 ; python_version >= "3.12" and python_version < "4.0"
93
- semantic-version==2.10.0 ; python_version >= "3.12" and python_version < "4.0"
94
- shellingham==1.5.4 ; python_version >= "3.12" and python_version < "4.0" and sys_platform != "emscripten"
95
- six==1.17.0 ; python_version >= "3.12" and python_version < "4.0"
96
- sklearn-compat==0.1.5 ; python_version >= "3.12" and python_version < "4.0"
97
- smmap==5.0.2 ; python_version >= "3.12" and python_version < "4.0"
98
- sqlalchemy==2.0.44 ; python_version >= "3.12" and python_version < "4.0"
99
- sqlparse==0.5.5 ; python_version >= "3.12" and python_version < "4.0"
100
- starlette==0.50.0 ; python_version >= "3.12" and python_version < "4.0"
101
- threadpoolctl==3.6.0 ; python_version >= "3.12" and python_version < "4.0"
102
- tomlkit==0.13.3 ; python_version >= "3.12" and python_version < "4.0"
103
- tqdm==4.67.1 ; python_version >= "3.12" and python_version < "4.0"
104
- typer==0.21.0 ; python_version >= "3.12" and python_version < "4.0" and sys_platform != "emscripten"
105
- typing-extensions==4.15.0 ; python_version >= "3.12" and python_version < "4.0"
106
- typing-inspection==0.4.2 ; python_version >= "3.12" and python_version < "4.0"
107
- tzdata==2025.2 ; python_version >= "3.12" and python_version < "4.0"
108
- urllib3==2.6.2 ; python_version >= "3.12" and python_version < "4.0"
109
- uvicorn==0.38.0 ; python_version >= "3.12" and python_version < "4.0"
110
- waitress==3.0.2 ; python_version >= "3.12" and python_version < "4.0" and platform_system == "Windows"
111
- websockets==14.2 ; python_version >= "3.12" and python_version < "4.0"
112
- werkzeug==3.1.4 ; python_version >= "3.12" and python_version < "4.0"
113
- xgboost==2.1.4 ; python_version >= "3.12" and python_version < "4.0"
114
- zipp==3.23.0 ; python_version >= "3.12" and python_version < "4.0"
 
1
+ # Minimal requirements for HF Spaces deployment
2
+ # Only the dependencies needed for app.py and model loading
3
+ gradio>=5.9.0
4
+ huggingface-hub>=0.27.0
5
+ joblib>=1.4.0
6
+ scikit-learn>=1.6.0
7
+ imbalanced-learn>=0.13.0
8
+ xgboost>=2.1.0
9
+ numpy>=2.0.0