Skip to content

Commit

Permalink
Update appli19b
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Mar 15, 2024
1 parent b11c70e commit 5a9f15d
Show file tree
Hide file tree
Showing 21 changed files with 440 additions and 2,789 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Construction image Docker

on:
push:
branches:
- main
- dev
tags:
- 'v*.*.*'

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: linogaliana/application-correction

-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
31 changes: 31 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Python package

on:
push:
branches:
- main
- dev


jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
# latest python minor
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pylint
- name: Lint
run: |
pylint src --fail-under=6
- name: Test Python code
run: python train.py
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
config.yaml
__pycache__/
data/**/*.csv
titanic/
model.joblib
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM ubuntu:22.04
WORKDIR ${HOME}/titanic
# Install Python
RUN apt-get -y update && \
apt-get install -y python3-pip
# Install project dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY train.py .
COPY src ./src
COPY api ./api
CMD ["bash", "-c", "./api/run.sh"]
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Probabilité de survie sur le Titanic [![Construction image Docker](https://github.com/ensae-reproductibilite/application-correction/actions/workflows/prod.yaml/badge.svg)](https://github.com/ensae-reproductibilite/application-correction/actions/workflows/prod.yaml)

Pour pouvoir utiliser ce projet, il
est recommandé de créer un fichier `config.yaml`
ayant la structure suivante:

```yaml
jeton_api: ####
data_path: https://minio.lab.sspcloud.fr/lgaliana/ensae-reproductibilite/data/raw/data.csv
```
Pour installer les dépendances
```bash
pip install -r requirements.txt
```
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=
"<b>Application de prédiction de survie sur le Titanic</b> 🚢 <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
Loading

0 comments on commit 5a9f15d

Please sign in to comment.