co2pred / app.py
avraux
endpoint founded
36f8d4c
raw
history blame
810 Bytes
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