Download app.py from avraux/co2pred: direct link, hf CLI and curl.
- Browser
- Download file 810 Bytes
-
https://huggingface.co/spaces/avraux/co2pred/resolve/main/app.py
- Command line
-
hf download hf://spaces/avraux/co2pred/app.py
-
curl -L -o app.py https://huggingface.co/spaces/avraux/co2pred/resolve/main/app.py
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 | |
| 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 | |
| def predict(data: InputData): | |
| input_json = data.dict() | |
| result = preprocess_and_predict(input_json) | |
| return result |