Spaces:
Sleeping
Sleeping
update main
Browse files
main.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
import uvicorn
|
2 |
import pandas as pd
|
3 |
-
from
|
4 |
-
from
|
5 |
-
from fastapi import FastAPI
|
6 |
import joblib
|
7 |
from enum import Enum
|
8 |
from fastapi.responses import HTMLResponse
|
@@ -56,20 +55,33 @@ class CarBrand(str, Enum):
|
|
56 |
subaru = "Subaru"
|
57 |
toyota = "Toyota"
|
58 |
|
59 |
-
class
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
@app.get("/", response_class=HTMLResponse, tags=["Introduction Endpoints"])
|
75 |
async def index():
|
@@ -81,15 +93,37 @@ async def index():
|
|
81 |
)
|
82 |
|
83 |
@app.post("/predict", tags=["Machine Learning"])
|
84 |
-
async def predict(
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
-
car_data_dict = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
car_data = pd.DataFrame(car_data_dict)
|
94 |
|
95 |
model = joblib.load('best_model_XGBoost.pkl')
|
|
|
1 |
import uvicorn
|
2 |
import pandas as pd
|
3 |
+
from typing import Union
|
4 |
+
from fastapi import FastAPI, Query
|
|
|
5 |
import joblib
|
6 |
from enum import Enum
|
7 |
from fastapi.responses import HTMLResponse
|
|
|
55 |
subaru = "Subaru"
|
56 |
toyota = "Toyota"
|
57 |
|
58 |
+
class FuelType(str, Enum):
|
59 |
+
diesel = "diesel"
|
60 |
+
petrol = "petrol"
|
61 |
+
hybrid_petrol = "hybrid_petrol"
|
62 |
+
electro = "electro"
|
63 |
+
|
64 |
+
class PaintColor(str, Enum):
|
65 |
+
black = "black"
|
66 |
+
grey = "grey"
|
67 |
+
white = "white"
|
68 |
+
red = "red"
|
69 |
+
silver = "silver"
|
70 |
+
blue = "blue"
|
71 |
+
orange = "orange"
|
72 |
+
beige = "beige"
|
73 |
+
brown = "brown"
|
74 |
+
green = "green"
|
75 |
+
|
76 |
+
class CarType(str, Enum):
|
77 |
+
convertible = "convertible"
|
78 |
+
coupe = "coupe"
|
79 |
+
estate = "estate"
|
80 |
+
hatchback = "hatchback"
|
81 |
+
sedan = "sedan"
|
82 |
+
subcompact = "subcompact"
|
83 |
+
suv = "suv"
|
84 |
+
van = "van"
|
85 |
|
86 |
@app.get("/", response_class=HTMLResponse, tags=["Introduction Endpoints"])
|
87 |
async def index():
|
|
|
93 |
)
|
94 |
|
95 |
@app.post("/predict", tags=["Machine Learning"])
|
96 |
+
async def predict(
|
97 |
+
brand: CarBrand,
|
98 |
+
mileage: int = Query(...),
|
99 |
+
engine_power: int = Query(...),
|
100 |
+
fuel: FuelType = Query(...),
|
101 |
+
paint_color: PaintColor = Query(...),
|
102 |
+
car_type: CarType = Query(...),
|
103 |
+
private_parking_available: bool = Query(...),
|
104 |
+
has_gps: bool = Query(...),
|
105 |
+
has_air_conditioning: bool = Query(...),
|
106 |
+
automatic_car: bool = Query(...),
|
107 |
+
has_getaround_connect: bool = Query(...),
|
108 |
+
has_speed_regulator: bool = Query(...),
|
109 |
+
winter_tires: bool = Query(...)
|
110 |
+
):
|
111 |
|
112 |
+
car_data_dict = {
|
113 |
+
'model_key': [brand],
|
114 |
+
'mileage': [mileage],
|
115 |
+
'engine_power': [engine_power],
|
116 |
+
'fuel': [fuel],
|
117 |
+
'paint_color': [paint_color],
|
118 |
+
'car_type': [car_type],
|
119 |
+
'private_parking_available': [private_parking_available],
|
120 |
+
'has_gps': [has_gps],
|
121 |
+
'has_air_conditioning': [has_air_conditioning],
|
122 |
+
'automatic_car': [automatic_car],
|
123 |
+
'has_getaround_connect': [has_getaround_connect],
|
124 |
+
'has_speed_regulator': [has_speed_regulator],
|
125 |
+
'winter_tires': [winter_tires]
|
126 |
+
}
|
127 |
car_data = pd.DataFrame(car_data_dict)
|
128 |
|
129 |
model = joblib.load('best_model_XGBoost.pkl')
|