Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Construction image Docker

on:
push:
branches:
- main
- dev


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: 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: remiguy/application:latest
42 changes: 42 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Python package

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v6
with:
# latest python minor
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install uv
uv sync

- name: Test code quality
run: |
uv sync
uv run --with pylint pylint src --fail-under=5

- name: Test that code runs smoothly
env:
JETON_API: ${{ secrets.JETON_API }}
run: uv run train.py

- name: Upload recording.log artifact
uses: actions/upload-artifact@v4
with:
name: log-file
path: recording.log
if-no-files-found: warn
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
config.yaml
__pycache__/
.env
*.log
data/
model.skops
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM ubuntu:22.04

# Install Python
RUN apt-get -y update && \
apt-get install -y python3-pip curl

# Install uv
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin/:$PATH"

# Install project dependencies
COPY pyproject.toml .
RUN uv sync

COPY app ./app
COPY train.py .
COPY src ./src
CMD ["bash", "-c", "./app/run.sh"]
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Probabilité de survie sur le Titanic

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

```yaml
JETON_API="####" #renseigner la valeur pertinente
```
49 changes: 49 additions & 0 deletions app/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""A simple API to expose our trained RandomForest model for Tutanic survival."""

from fastapi import FastAPI
import skops.io as sio
import pandas as pd

unknown_types = sio.get_untrusted_types(file="model.skops")
model = sio.load("model.skops", trusted=unknown_types)

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 = int(model.predict(df)[0])

prediction = "Survived 🎉" if prediction == 1 else "Dead ⚰️"

return prediction
2 changes: 2 additions & 0 deletions app/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
uv run train.py
uv run uvicorn app.api:app --host "0.0.0.0"
892 changes: 0 additions & 892 deletions data.csv

This file was deleted.

28 changes: 28 additions & 0 deletions deployment/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#| filename: "deployment/deployment.yaml"
apiVersion: apps/v1
kind: Deployment
metadata:
name: titanic-deployment
labels:
app: titanic
spec:
replicas: 1
selector:
matchLabels:
app: titanic
template:
metadata:
labels:
app: titanic
spec:
containers:
- name: titanic
image: remiguy/application:latest
ports:
- containerPort: 8000
env:
- name: JETON_API
valueFrom:
secretKeyRef:
name: api-jeton
key: JETON_API
21 changes: 21 additions & 0 deletions deployment/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#| filename: "deployment/ingress.yaml"
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: titanic-ingress
spec:
ingressClassName: nginx
tls:
- hosts:
- remtita.lab.sspcloud.fr
rules:
- host: remtita.lab.sspcloud.fr
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: titanic-service
port:
number: 80
11 changes: 11 additions & 0 deletions deployment/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: titanic-service
spec:
selector:
app: titanic
ports:
- protocol: TCP
port: 80
targetPort: 8000
11 changes: 11 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

# Ensure everything is installed
sudo apt-get -y update
sudo apt-get install -y python3-pip python3-venv curl

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Restore environment
uv sync
Loading