Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app.py +12 -8
- preprocessor.pkl +3 -0
app.py
CHANGED
|
@@ -6,14 +6,12 @@ from typing import Literal, List, Union
|
|
| 6 |
from fastapi import FastAPI, File, UploadFile
|
| 7 |
import joblib
|
| 8 |
from fastapi.responses import RedirectResponse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
try:
|
| 11 |
-
logged_model = 'runs:/c2037b0c2c9e4c629a02b7b8a7eb2642/model'
|
| 12 |
-
loaded_model = mlflow.pyfunc.load_model(logged_model)
|
| 13 |
-
print("β
Model loaded successfully!")
|
| 14 |
-
except Exception as e:
|
| 15 |
-
print(f"β Error loading model: {e}")
|
| 16 |
-
loaded_model = None
|
| 17 |
|
| 18 |
description = """
|
| 19 |
Welcome to the rental price predictor API for Getaround ποΈ !\n
|
|
@@ -51,6 +49,10 @@ class PredictionFeatures(BaseModel):
|
|
| 51 |
has_speed_regulator: bool
|
| 52 |
winter_tires: bool
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
# Redirect automatically to /docs (without showing this endpoint in /docs)
|
| 55 |
@app.get("/", include_in_schema=False)
|
| 56 |
async def docs_redirect():
|
|
@@ -75,8 +77,10 @@ async def predict(predictionFeatures: PredictionFeatures):
|
|
| 75 |
"has_speed_regulator": [predictionFeatures.has_speed_regulator],
|
| 76 |
"winter_tires": [predictionFeatures.winter_tires]
|
| 77 |
})
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
prediction = loaded_model.predict(
|
| 80 |
|
| 81 |
# Format response
|
| 82 |
response = {"prediction": prediction.tolist()[0]}
|
|
|
|
| 6 |
from fastapi import FastAPI, File, UploadFile
|
| 7 |
import joblib
|
| 8 |
from fastapi.responses import RedirectResponse
|
| 9 |
+
import pickle
|
| 10 |
+
|
| 11 |
+
logged_model = 'runs:/c2037b0c2c9e4c629a02b7b8a7eb2642/model'
|
| 12 |
+
loaded_model = mlflow.pyfunc.load_model(logged_model)
|
| 13 |
+
print("β
Model loaded successfully!")
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
description = """
|
| 17 |
Welcome to the rental price predictor API for Getaround ποΈ !\n
|
|
|
|
| 49 |
has_speed_regulator: bool
|
| 50 |
winter_tires: bool
|
| 51 |
|
| 52 |
+
# Load the preprocessor
|
| 53 |
+
with open('preprocessor.pkl', 'rb') as file:
|
| 54 |
+
preprocessor = pickle.load(file)
|
| 55 |
+
|
| 56 |
# Redirect automatically to /docs (without showing this endpoint in /docs)
|
| 57 |
@app.get("/", include_in_schema=False)
|
| 58 |
async def docs_redirect():
|
|
|
|
| 77 |
"has_speed_regulator": [predictionFeatures.has_speed_regulator],
|
| 78 |
"winter_tires": [predictionFeatures.winter_tires]
|
| 79 |
})
|
| 80 |
+
|
| 81 |
+
preprocessed_data = preprocessor.transform(input_data)
|
| 82 |
|
| 83 |
+
prediction = loaded_model.predict(preprocessed_data)
|
| 84 |
|
| 85 |
# Format response
|
| 86 |
response = {"prediction": prediction.tolist()[0]}
|
preprocessor.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:aa5ced732a6ef7c6852c9afc7a589f9e0bc0e2f99e94fbe3973b83b9fe6dab41
|
| 3 |
+
size 3075
|