second
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import joblib
|
|
| 4 |
import boto3
|
| 5 |
import os
|
| 6 |
import io
|
|
|
|
| 7 |
import uvicorn
|
| 8 |
import numpy as np
|
| 9 |
from dotenv import load_dotenv
|
|
@@ -38,12 +39,30 @@ model = load_model_from_s3(S3_BUCKET, MODEL_KEY)
|
|
| 38 |
class InputData(BaseModel):
|
| 39 |
input: list
|
| 40 |
|
|
|
|
| 41 |
@app.post("/predict")
|
| 42 |
def predict(data: InputData):
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
preds = model.predict(X)
|
| 45 |
return {"prediction": preds.tolist()}
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
@app.get("/")
|
| 48 |
def home():
|
| 49 |
return {"message": "Bienvenue sur l'API GetAround Pricing! Utilisez /predict pour faire une prédiction."}
|
|
|
|
| 4 |
import boto3
|
| 5 |
import os
|
| 6 |
import io
|
| 7 |
+
import pandas as pd
|
| 8 |
import uvicorn
|
| 9 |
import numpy as np
|
| 10 |
from dotenv import load_dotenv
|
|
|
|
| 39 |
class InputData(BaseModel):
|
| 40 |
input: list
|
| 41 |
|
| 42 |
+
|
| 43 |
@app.post("/predict")
|
| 44 |
def predict(data: InputData):
|
| 45 |
+
# Colonnes attendues par le modèle
|
| 46 |
+
columns = [
|
| 47 |
+
"mileage", "engine_power", "fuel", "paint_color", "car_type",
|
| 48 |
+
"private_parking_available", "has_gps", "has_air_conditioning",
|
| 49 |
+
"automatic_car", "has_getaround_connect", "has_speed_regulator", "winter_tires"
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
# Transformer l'input en DataFrame
|
| 53 |
+
X = pd.DataFrame(data.input, columns=columns)
|
| 54 |
+
|
| 55 |
+
# Prédictions
|
| 56 |
preds = model.predict(X)
|
| 57 |
return {"prediction": preds.tolist()}
|
| 58 |
|
| 59 |
+
|
| 60 |
+
# @app.post("/predict")
|
| 61 |
+
# def predict(data: InputData):
|
| 62 |
+
# X = np.array(data.input)
|
| 63 |
+
# preds = model.predict(X)
|
| 64 |
+
# return {"prediction": preds.tolist()}
|
| 65 |
+
|
| 66 |
@app.get("/")
|
| 67 |
def home():
|
| 68 |
return {"message": "Bienvenue sur l'API GetAround Pricing! Utilisez /predict pour faire une prédiction."}
|