forked from raminmohammadi/MLOps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·35 lines (23 loc) · 877 Bytes
/
main.py
File metadata and controls
executable file
·35 lines (23 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from fastapi import FastAPI, status, HTTPException
from pydantic import BaseModel
from predict import predict_data
app = FastAPI()
class IrisData(BaseModel):
petal_length: float
sepal_length: float
petal_width: float
sepal_width: float
class IrisResponse(BaseModel):
response:int
@app.get("/", status_code=status.HTTP_200_OK)
async def health_ping():
return {"status": "healthy"}
@app.post("/predict", response_model=IrisResponse)
async def predict_iris(iris_features: IrisData):
try:
features = [[iris_features.sepal_length, iris_features.sepal_width,
iris_features.petal_length, iris_features.petal_width]]
prediction = predict_data(features)
return IrisResponse(response=int(prediction[0]))
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))