Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,8 +3,8 @@
|
|
3 |
import pandas as pd
|
4 |
from pycaret.regression import load_model, predict_model
|
5 |
from fastapi import FastAPI
|
|
|
6 |
import uvicorn
|
7 |
-
from pydantic import create_model
|
8 |
|
9 |
# Create the app
|
10 |
app = FastAPI()
|
@@ -13,13 +13,27 @@ app = FastAPI()
|
|
13 |
model = load_model("lr_api")
|
14 |
|
15 |
# Create input/output pydantic models
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# Define predict function
|
21 |
-
@app.post("/predict", response_model=
|
22 |
-
def predict(data:
|
23 |
data = pd.DataFrame([data.dict()])
|
24 |
predictions = predict_model(model, data=data)
|
25 |
return {"prediction": predictions["prediction_label"].iloc[0]}
|
|
|
3 |
import pandas as pd
|
4 |
from pycaret.regression import load_model, predict_model
|
5 |
from fastapi import FastAPI
|
6 |
+
from pydantic import BaseModel
|
7 |
import uvicorn
|
|
|
8 |
|
9 |
# Create the app
|
10 |
app = FastAPI()
|
|
|
13 |
model = load_model("lr_api")
|
14 |
|
15 |
# Create input/output pydantic models
|
16 |
+
class InputModel(BaseModel):
|
17 |
+
rownames: int
|
18 |
+
year: int
|
19 |
+
violent: float
|
20 |
+
murder: float
|
21 |
+
prisoners: int
|
22 |
+
afam: float
|
23 |
+
cauc: float
|
24 |
+
male: float
|
25 |
+
population: float
|
26 |
+
income: float
|
27 |
+
density: float
|
28 |
+
state: str
|
29 |
+
law: str
|
30 |
+
|
31 |
+
class OutputModel(BaseModel):
|
32 |
+
prediction: float
|
33 |
|
34 |
# Define predict function
|
35 |
+
@app.post("/predict", response_model=OutputModel)
|
36 |
+
def predict(data: InputModel):
|
37 |
data = pd.DataFrame([data.dict()])
|
38 |
predictions = predict_model(model, data=data)
|
39 |
return {"prediction": predictions["prediction_label"].iloc[0]}
|