File size: 810 Bytes
0f6bede f35d21e 36f8d4c f35d21e 0f6bede 36f8d4c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
from fastapi import FastAPI
from pydantic import BaseModel
from inference import preprocess_and_predict
# Définir l'API
app = FastAPI()
# Définir un modèle d'entrée
class InputData(BaseModel):
puiss_admin_98: int
conso_urb: float
conso_exurb: float
masse_ordma_max: float
marque: str
typ_boite: str
champ_v9 : str
carrosserie: str
gamme: str
@app.get("/")
def read_root():
return {"message": "Welcome to CO2 Prediction for cars ! To use the prediction endpoint, it's a POST request to https://avraux-co2pred.hf.space/predict. You can see what the body should look like in the README !"}
# Endpoint pour prédiction
@app.post("/predict")
def predict(data: InputData):
input_json = data.dict()
result = preprocess_and_predict(input_json)
return result |