Spaces:
Runtime error
Runtime error
Commit ·
3295edd
1
Parent(s): 654a471
Ajout du modèle, du préprocesseur
Browse files- Dockerfile +10 -0
- __pycache__/app.cpython-312.pyc +0 -0
- app.py +70 -0
- model.joblib +3 -0
- preprocessor.joblib +3 -0
- requirements.txt +7 -0
Dockerfile
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10.10
|
| 2 |
+
|
| 3 |
+
WORKDIR /home/app
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt /dependencies/requirements.txt
|
| 6 |
+
RUN pip install -r /dependencies/requirements.txt
|
| 7 |
+
|
| 8 |
+
COPY . /home/app
|
| 9 |
+
|
| 10 |
+
CMD gunicorn app:app --bind 0.0.0.0:$PORT --worker-class uvicorn.workers.UvicornWorker
|
__pycache__/app.cpython-312.pyc
ADDED
|
Binary file (2.69 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import uvicorn
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from pydantic import BaseModel
|
| 4 |
+
from fastapi import FastAPI
|
| 5 |
+
import numpy as np
|
| 6 |
+
import joblib
|
| 7 |
+
from typing import List
|
| 8 |
+
|
| 9 |
+
# ==== FastAPI Description ====
|
| 10 |
+
|
| 11 |
+
description = """
|
| 12 |
+
# 🚗 GetAround Rental Price Predictor API
|
| 13 |
+
|
| 14 |
+
This API predicts the **rental price per day (in €)** for a car based on various features.
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
app = FastAPI(
|
| 18 |
+
title="GetAround Price Prediction API",
|
| 19 |
+
description=description,
|
| 20 |
+
version="1.0",
|
| 21 |
+
contact={"name": "Ton Nom"},
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# ==== Input Data Models ====
|
| 25 |
+
|
| 26 |
+
class CarCriteria(BaseModel):
|
| 27 |
+
model_key: str
|
| 28 |
+
mileage: int
|
| 29 |
+
engine_power: int
|
| 30 |
+
fuel: str
|
| 31 |
+
paint_color: str
|
| 32 |
+
car_type: str
|
| 33 |
+
private_parking_available: bool
|
| 34 |
+
has_gps: bool
|
| 35 |
+
has_air_conditioning: bool
|
| 36 |
+
automatic_car: bool
|
| 37 |
+
has_getaround_connect: bool
|
| 38 |
+
has_speed_regulator: bool
|
| 39 |
+
winter_tires: bool
|
| 40 |
+
|
| 41 |
+
class CarOptions(BaseModel):
|
| 42 |
+
car_options: List[CarCriteria]
|
| 43 |
+
|
| 44 |
+
# ==== Load pipeline (model + preprocessor ensemble) ====
|
| 45 |
+
|
| 46 |
+
def load_model():
|
| 47 |
+
model = joblib.load("model.joblib") # Pipeline: preprocessor + LinearRegression
|
| 48 |
+
return model
|
| 49 |
+
|
| 50 |
+
# ==== Predict endpoint ====
|
| 51 |
+
|
| 52 |
+
@app.post("/predict", tags=["Machine Learning"])
|
| 53 |
+
async def predict(car_options: CarOptions):
|
| 54 |
+
model = load_model()
|
| 55 |
+
|
| 56 |
+
# Convertir les données en DataFrame
|
| 57 |
+
df_input = pd.DataFrame([option.dict() for option in car_options.car_options])
|
| 58 |
+
|
| 59 |
+
# Prédiction directe (le modèle contient déjà le préprocesseur)
|
| 60 |
+
predictions = model.predict(df_input)
|
| 61 |
+
|
| 62 |
+
# Retourner les résultats formatés
|
| 63 |
+
formatted = [f"Option {i+1}: {round(pred)} €" for i, pred in enumerate(predictions)]
|
| 64 |
+
return {"predictions": formatted}
|
| 65 |
+
|
| 66 |
+
# ==== Exécution locale ====
|
| 67 |
+
|
| 68 |
+
if __name__ == "__main__":
|
| 69 |
+
uvicorn.run(app, host="0.0.0.0", port=4000)
|
| 70 |
+
|
model.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bb2d31c2bdf37b3d683e65da884bac4714bfbc736145be1590b106c2cfa01994
|
| 3 |
+
size 5993
|
preprocessor.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:91f63c94fe85c7a7144d6f608787f2b1a26bc2ea53f82725d6726f1bd400c175
|
| 3 |
+
size 5156
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn[standard]
|
| 3 |
+
pydantic
|
| 4 |
+
pandas
|
| 5 |
+
numpy
|
| 6 |
+
scikit-learn==1.0.2
|
| 7 |
+
joblib==1.2.0
|