Skip to content

Commit

Permalink
Appli
Browse files Browse the repository at this point in the history
  • Loading branch information
linogaliana committed Mar 15, 2024
1 parent 05fdafb commit c2d264d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
run: |
pylint src --fail-under=6
- name: Test Python code
run: python main.py
run: python train.py
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
config.yaml
__pycache__/
data/**/*.csv
titanic/
titanic/
model.joblib
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RUN apt-get -y update && \
# Install project dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY main.py .
COPY train.py .
COPY src ./src
CMD ["python3", "main.py"]
COPY api ./api
CMD ["bash", "-c", "./api/run.sh"]
51 changes: 51 additions & 0 deletions api/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""A simple API to expose our trained RandomForest model for Tutanic survival."""
from fastapi import FastAPI
from joblib import load

import pandas as pd

model = load('model.joblib')

app = FastAPI(
title="Prédiction de survie sur le Titanic",
description=
"Application de prédiction de survie sur le Titanic 🚢 <br>Une version par API pour faciliter la réutilisation du modèle 🚀" +\
"<br><br><img src=\"https://media.vogue.fr/photos/5faac06d39c5194ff9752ec9/1:1/w_2404,h_2404,c_limit/076_CHL_126884.jpg\" width=\"200\">"
)


@app.get("/", tags=["Welcome"])
def show_welcome_page():
"""
Show welcome page with model name and version.
"""

return {
"Message": "API de prédiction de survie sur le Titanic",
"Model_name": 'Titanic ML',
"Model_version": "0.1",
}


@app.get("/predict", tags=["Predict"])
async def predict(
sex: str = "female",
age: float = 29.0,
fare: float = 16.5,
embarked: str = "S"
) -> str:
"""
"""

df = pd.DataFrame(
{
"Sex": [sex],
"Age": [age],
"Fare": [fare],
"Embarked": [embarked],
}
)

prediction = "Survived 🎉" if int(model.predict(df)) == 1 else "Dead ⚰️"

return prediction
3 changes: 3 additions & 0 deletions api/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#/bin/bash
python3 train.py
uvicorn api.main:app --reload --host "0.0.0.0" --port 5000
2 changes: 2 additions & 0 deletions main.py → train.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import argparse
import pathlib
import pandas as pd
from joblib import dump

from src.data.import_data import import_yaml_config
from src.pipeline.build_pipeline import split_train_test, create_pipeline
Expand Down Expand Up @@ -53,6 +54,7 @@

pipe.fit(X_train, y_train)

dump(pipe, 'model.joblib')

# Evaluate the model
score, matrix = evaluate_model(pipe, X_test, y_test)
Expand Down

0 comments on commit c2d264d

Please sign in to comment.