|
from fastapi import FastAPI |
|
from pydantic import BaseModel |
|
from inference import preprocess_and_predict |
|
|
|
|
|
app = FastAPI() |
|
|
|
|
|
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 !"} |
|
|
|
|
|
|
|
@app.post("/predict") |
|
def predict(data: InputData): |
|
input_json = data.dict() |
|
result = preprocess_and_predict(input_json) |
|
return result |