Spaces:
Runtime error
Runtime error
Merge branch 'develop' into feature/db_schema_setup
Browse files- .github/workflows/ci.yml +9 -10
- .gitignore +2 -2
- App/main.py +4 -0
- App/predict.py +10 -7
- Dockerfile +13 -0
- README.md +10 -0
- poetry.lock +0 -0
- pyproject.toml +8 -2
- requirements.txt +7 -1
.github/workflows/ci.yml
CHANGED
|
@@ -16,16 +16,15 @@ jobs:
|
|
| 16 |
steps:
|
| 17 |
- uses: actions/setup-python@v5
|
| 18 |
with:
|
| 19 |
-
python-version: "3.11"
|
| 20 |
|
| 21 |
- uses: actions/checkout@v4
|
| 22 |
|
| 23 |
-
- name: Install
|
| 24 |
-
run:
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
- name: Run tests
|
| 30 |
-
run: pytest
|
| 31 |
-
|
|
|
|
| 16 |
steps:
|
| 17 |
- uses: actions/setup-python@v5
|
| 18 |
with:
|
| 19 |
+
python-version: "3.11.9"
|
| 20 |
|
| 21 |
- uses: actions/checkout@v4
|
| 22 |
|
| 23 |
+
- name: Install Poetry
|
| 24 |
+
run: pip install poetry
|
| 25 |
+
|
| 26 |
+
- name: Install dependencies with Poetry
|
| 27 |
+
run: poetry install --no-interaction --no-root
|
| 28 |
+
|
| 29 |
+
- name: Run tests
|
| 30 |
+
run: poetry run pytest
|
|
|
.gitignore
CHANGED
|
@@ -4,7 +4,7 @@ venv/
|
|
| 4 |
.venv/
|
| 5 |
.pytest_cache/
|
| 6 |
.coverage
|
| 7 |
-
App/
|
| 8 |
-
App/model/modele_final_xgb.joblib
|
| 9 |
*.joblib
|
| 10 |
*.json
|
|
|
|
|
|
| 4 |
.venv/
|
| 5 |
.pytest_cache/
|
| 6 |
.coverage
|
| 7 |
+
App/modl/
|
|
|
|
| 8 |
*.joblib
|
| 9 |
*.json
|
| 10 |
+
App/model/modele_final_xgb.joblib
|
App/main.py
CHANGED
|
@@ -8,6 +8,10 @@ app = FastAPI(
|
|
| 8 |
version="0.1.0"
|
| 9 |
)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
@app.post("/predict")
|
| 12 |
def predict(data: EmployeeFeatures):
|
| 13 |
"""
|
|
|
|
| 8 |
version="0.1.0"
|
| 9 |
)
|
| 10 |
|
| 11 |
+
@app.get("/")
|
| 12 |
+
def root():
|
| 13 |
+
return {"status": "API OK"}
|
| 14 |
+
|
| 15 |
@app.post("/predict")
|
| 16 |
def predict(data: EmployeeFeatures):
|
| 17 |
"""
|
App/predict.py
CHANGED
|
@@ -3,10 +3,9 @@ import pandas as pd
|
|
| 3 |
from App.schemas import EmployeeFeatures
|
| 4 |
import json
|
| 5 |
from pathlib import Path
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
chemin_model = Path("App/model/modele_final_xgb.joblib")
|
| 9 |
-
chemin_mapping = Path("App/model/mapping_classes.json")
|
| 10 |
|
| 11 |
# Variables chargées
|
| 12 |
model = None
|
|
@@ -14,17 +13,21 @@ classes_mapping = None
|
|
| 14 |
Features = list(EmployeeFeatures.model_fields.keys())
|
| 15 |
|
| 16 |
|
|
|
|
| 17 |
# Chargement des fichiers: fonction pour charger le modèle, le mapping afin de permettre à l'API de démarrer m^me si les éléments ne sont pas présents
|
| 18 |
def files_load():
|
| 19 |
global model, classes_mapping
|
|
|
|
| 20 |
if model is None:
|
| 21 |
-
|
| 22 |
-
|
|
|
|
| 23 |
model =joblib.load(chemin_model)
|
| 24 |
|
| 25 |
if classes_mapping is None:
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
with open(chemin_mapping) as f:
|
| 29 |
classes_mapping = json.load(f)
|
| 30 |
|
|
|
|
| 3 |
from App.schemas import EmployeeFeatures
|
| 4 |
import json
|
| 5 |
from pathlib import Path
|
| 6 |
+
from huggingface_hub import hf_hub_download
|
| 7 |
|
| 8 |
+
MODEL_REPO = "Diaure/xgb_model"
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Variables chargées
|
| 11 |
model = None
|
|
|
|
| 13 |
Features = list(EmployeeFeatures.model_fields.keys())
|
| 14 |
|
| 15 |
|
| 16 |
+
|
| 17 |
# Chargement des fichiers: fonction pour charger le modèle, le mapping afin de permettre à l'API de démarrer m^me si les éléments ne sont pas présents
|
| 18 |
def files_load():
|
| 19 |
global model, classes_mapping
|
| 20 |
+
|
| 21 |
if model is None:
|
| 22 |
+
chemin_model = Path(hf_hub_download(repo_id=MODEL_REPO, filename="modele_final_xgb.joblib"))
|
| 23 |
+
# if not chemin_model.exists():
|
| 24 |
+
# raise RuntimeError("Eléments du modèle introuvable.")
|
| 25 |
model =joblib.load(chemin_model)
|
| 26 |
|
| 27 |
if classes_mapping is None:
|
| 28 |
+
chemin_mapping = Path(hf_hub_download(repo_id=MODEL_REPO, filename="mapping_classes.json"))
|
| 29 |
+
# if not chemin_mapping.exists():
|
| 30 |
+
# raise RuntimeError("Mapping des classes introuvable.")
|
| 31 |
with open(chemin_mapping) as f:
|
| 32 |
classes_mapping = json.load(f)
|
| 33 |
|
Dockerfile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# force rebuild
|
| 2 |
+
FROM python:3.11
|
| 3 |
+
|
| 4 |
+
WORKDIR /code
|
| 5 |
+
|
| 6 |
+
COPY requirements.txt .
|
| 7 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 8 |
+
|
| 9 |
+
COPY . .
|
| 10 |
+
|
| 11 |
+
EXPOSE 7860
|
| 12 |
+
|
| 13 |
+
CMD ["uvicorn", "App.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# Futurisys – Déploiement d’un modèle de Machine Learning via API
|
| 2 |
|
| 3 |
## Contexte
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Futurisys ML API
|
| 3 |
+
emoji: 🚀
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
|
| 11 |
# Futurisys – Déploiement d’un modèle de Machine Learning via API
|
| 12 |
|
| 13 |
## Contexte
|
poetry.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
pyproject.toml
CHANGED
|
@@ -21,11 +21,17 @@ dependencies = [
|
|
| 21 |
"catboost ==1.2.7",
|
| 22 |
"numba ==0.59.1",
|
| 23 |
"llvmlite ==0.42.0",
|
| 24 |
-
"ipykernel>=6.25,<7.0"
|
|
|
|
|
|
|
|
|
|
| 25 |
]
|
| 26 |
|
| 27 |
-
|
| 28 |
[build-system]
|
| 29 |
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
| 30 |
build-backend = "poetry.core.masonry.api"
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
"catboost ==1.2.7",
|
| 22 |
"numba ==0.59.1",
|
| 23 |
"llvmlite ==0.42.0",
|
| 24 |
+
"ipykernel>=6.25,<7.0",
|
| 25 |
+
"huggingface-hub ==1.3.1",
|
| 26 |
+
"fastapi ==0.115.0",
|
| 27 |
+
"uvicorn ==0.30.1"
|
| 28 |
]
|
| 29 |
|
|
|
|
| 30 |
[build-system]
|
| 31 |
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
| 32 |
build-backend = "poetry.core.masonry.api"
|
| 33 |
|
| 34 |
+
[tool.poetry.group.dev.dependencies]
|
| 35 |
+
pytest = "9.0.2"
|
| 36 |
+
|
| 37 |
+
|
requirements.txt
CHANGED
|
@@ -6,4 +6,10 @@ Pygments==2.19.2
|
|
| 6 |
pytest==9.0.2
|
| 7 |
fastapi==0.115.0
|
| 8 |
uvicorn==0.30.1
|
| 9 |
-
httpx==0.27.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
pytest==9.0.2
|
| 7 |
fastapi==0.115.0
|
| 8 |
uvicorn==0.30.1
|
| 9 |
+
httpx==0.27.0
|
| 10 |
+
huggingface-hub==1.3.1
|
| 11 |
+
joblib==1.4.2
|
| 12 |
+
pandas==2.2.2
|
| 13 |
+
scikit-learn==1.4.2
|
| 14 |
+
xgboost ==2.0.3
|
| 15 |
+
huggingface-hub ==1.3.1
|