-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf85d56
commit 0f2a4d2
Showing
5 changed files
with
88 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |