flodussart commited on
Commit
11f2ec7
·
1 Parent(s): d4ede10
Dockerfile CHANGED
@@ -1,23 +1,3 @@
1
- # FROM python:3.12.4
2
- #
3
- # # Set working directory
4
- # WORKDIR /app
5
- #
6
- # # Copy dependencies
7
- # COPY requirements.txt .
8
- #
9
- # # Install dependencies
10
- # RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
11
- #
12
- # # Copy the rest of the app
13
- # COPY . .
14
- #
15
- # # Expose API port
16
- # EXPOSE 7860
17
- #
18
- # # Run the app with uvicorn
19
- # CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
20
-
21
  FROM python:3.12-slim
22
 
23
  # (Optional but useful for xgboost/lightgbm/numba, etc.)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  FROM python:3.12-slim
2
 
3
  # (Optional but useful for xgboost/lightgbm/numba, etc.)
app.py CHANGED
@@ -12,16 +12,12 @@ from pydantic import BaseModel, Field, field_validator
12
  from unidecode import unidecode
13
 
14
 
15
- # =======================
16
  # Configuration
17
- # =======================
18
  PORT = int(os.getenv("PORT", 7860))
19
  LOCAL_MODEL_PATH = os.getenv("MODEL_PATH", "model_bundle/model")
20
 
21
 
22
- # =======================
23
  # Helper functions
24
- # =======================
25
  def load_features_from_artifacts(model_dir: str) -> list[str]:
26
  """
27
  Attempt to load `features_used.json` generated during training.
@@ -58,26 +54,29 @@ def load_features_from_artifacts(model_dir: str) -> list[str]:
58
  ]
59
 
60
 
61
- # =======================
62
  # FastAPI initialization
63
- # =======================
64
  app = FastAPI(
65
  title="🚗 Getaround Pricing API",
66
  description=(
67
  "Prédiction du prix journalier de location.\n\n"
68
  "• Dashboard : https://flodussart-getaroundcertifter.hf.space\n"
69
- "• Endpoint ML : POST /predict — body: {\"rows\": [...] } (recommandé) "
70
- "ou {\"input\": [[...], ...]} (ordre strict des features).\n"
71
  ),
72
  version="1.0",
73
  docs_url="/docs",
74
  redoc_url="/redoc",
75
  )
76
 
77
- # Enable CORS (useful when the Streamlit client calls this API from the browser)
 
 
 
 
 
78
  app.add_middleware(
79
  CORSMiddleware,
80
- allow_origins=["*"], # set a specific origin list in production if needed
81
  allow_credentials=True,
82
  allow_methods=["*"],
83
  allow_headers=["*"],
@@ -88,15 +87,13 @@ try:
88
  model = mlflow.pyfunc.load_model(LOCAL_MODEL_PATH)
89
  except Exception as e:
90
  raise RuntimeError(
91
- f"Unable to load local MLflow model '{LOCAL_MODEL_PATH}': {e}"
92
  )
93
 
94
  FEATURES: list[str] = load_features_from_artifacts(LOCAL_MODEL_PATH)
95
 
96
 
97
- # =======================
98
- # Pydantic schemas (v2)
99
- # =======================
100
  ALLOWED_FUEL = {"diesel", "petrol", "other"}
101
  ALLOWED_PAINT = {
102
  "black",
 
12
  from unidecode import unidecode
13
 
14
 
 
15
  # Configuration
 
16
  PORT = int(os.getenv("PORT", 7860))
17
  LOCAL_MODEL_PATH = os.getenv("MODEL_PATH", "model_bundle/model")
18
 
19
 
 
20
  # Helper functions
 
21
  def load_features_from_artifacts(model_dir: str) -> list[str]:
22
  """
23
  Attempt to load `features_used.json` generated during training.
 
54
  ]
55
 
56
 
 
57
  # FastAPI initialization
 
58
  app = FastAPI(
59
  title="🚗 Getaround Pricing API",
60
  description=(
61
  "Prédiction du prix journalier de location.\n\n"
62
  "• Dashboard : https://flodussart-getaroundcertifter.hf.space\n"
63
+ "• Endpoint ML : POST /predict — body: {\"input\": [[...], ...]} (ordre strict des features)"
64
+ "ou {\"rows\": [...] } .\n"
65
  ),
66
  version="1.0",
67
  docs_url="/docs",
68
  redoc_url="/redoc",
69
  )
70
 
71
+ # Authorized origins Streamlit app and local dev
72
+ origins = [
73
+ "https://flodussart-getaroundcertifter.hf.space", # Streamlit dashboard on Hugging Face
74
+ "http://localhost:8501", # local Streamlit testing
75
+ ]
76
+
77
  app.add_middleware(
78
  CORSMiddleware,
79
+ allow_origins=origins,
80
  allow_credentials=True,
81
  allow_methods=["*"],
82
  allow_headers=["*"],
 
87
  model = mlflow.pyfunc.load_model(LOCAL_MODEL_PATH)
88
  except Exception as e:
89
  raise RuntimeError(
90
+ f"Unable to load local MLflow model '{LOCAL_MODEL_PATH}': {e}"
91
  )
92
 
93
  FEATURES: list[str] = load_features_from_artifacts(LOCAL_MODEL_PATH)
94
 
95
 
96
+ # Pydantic schemas
 
 
97
  ALLOWED_FUEL = {"diesel", "petrol", "other"}
98
  ALLOWED_PAINT = {
99
  "black",
model_bundle/model/artifacts/features_used.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "numeric": [
3
+ "mileage",
4
+ "engine_power"
5
+ ],
6
+ "categorical": [
7
+ "model_key",
8
+ "fuel_grouped",
9
+ "paint_color",
10
+ "car_type"
11
+ ],
12
+ "boolean": [
13
+ "private_parking_available",
14
+ "has_gps",
15
+ "has_air_conditioning",
16
+ "automatic_car",
17
+ "has_getaround_connect",
18
+ "has_speed_regulator",
19
+ "winter_tires"
20
+ ]
21
+ }